-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(storage): add StringLoader to support loading gs:// URL strings directly via Glide #2335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+197
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
storage/src/test/java/com/firebase/ui/storage/images/StringLoaderTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package com.firebase.ui.storage.images; | ||
|
|
||
| import com.bumptech.glide.load.Options; | ||
| import com.bumptech.glide.load.model.ModelLoader.LoadData; | ||
| import com.google.firebase.storage.FirebaseStorage; | ||
| import com.google.firebase.storage.StorageReference; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
| import org.mockito.junit.MockitoJUnitRunner; | ||
|
|
||
| import java.io.InputStream; | ||
|
|
||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @RunWith(MockitoJUnitRunner.class) | ||
| public class StringLoaderTest { | ||
|
|
||
| private static final String VALID_GS_URL = "gs://my-bucket.appspot.com/images/photo.png"; | ||
| private static final String INVALID_GS_URL = "gs://bad-url"; | ||
|
|
||
| @Mock FirebaseStorage mStorage; | ||
| @Mock StorageReference mRef; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| when(mStorage.getReferenceFromUrl(VALID_GS_URL)).thenReturn(mRef); | ||
| } | ||
|
|
||
| // handles() | ||
|
|
||
| @Test | ||
| public void handles_gsUrl_returnsTrue() { | ||
| assertTrue(new FirebaseImageLoader.StringLoader(mStorage).handles(VALID_GS_URL)); | ||
| } | ||
|
|
||
| @Test | ||
| public void handles_httpsUrl_returnsFalse() { | ||
| assertFalse(new FirebaseImageLoader.StringLoader(mStorage).handles("https://example.com/image.png")); | ||
| } | ||
|
|
||
| @Test | ||
| public void handles_emptyString_returnsFalse() { | ||
| assertFalse(new FirebaseImageLoader.StringLoader(mStorage).handles("")); | ||
| } | ||
|
|
||
| // buildLoadData() | ||
|
|
||
| @Test | ||
| public void buildLoadData_validUrl_returnsLoadData() { | ||
| LoadData<InputStream> result = loaderWithMockStorage().buildLoadData(VALID_GS_URL, 0, 0, new Options()); | ||
| assertNotNull(result); | ||
| } | ||
|
|
||
| @Test | ||
| public void buildLoadData_illegalArgumentException_returnsNull() { | ||
| when(mStorage.getReferenceFromUrl(INVALID_GS_URL)).thenThrow(new IllegalArgumentException()); | ||
| LoadData<InputStream> result = loaderWithMockStorage().buildLoadData(INVALID_GS_URL, 0, 0, new Options()); | ||
| assertNull(result); | ||
| } | ||
|
|
||
| @Test | ||
| public void buildLoadData_illegalStateException_returnsNull() { | ||
| when(mStorage.getReferenceFromUrl(VALID_GS_URL)).thenThrow(new IllegalStateException()); | ||
| LoadData<InputStream> result = loaderWithMockStorage().buildLoadData(VALID_GS_URL, 0, 0, new Options()); | ||
| assertNull(result); | ||
| } | ||
|
|
||
| // Factory | ||
|
|
||
| @Test | ||
| public void factory_noArg_buildsStringLoader() { | ||
| // Verify the no-arg Factory produces a non-null loader without throwing | ||
| FirebaseImageLoader.StringLoader loader = | ||
| (FirebaseImageLoader.StringLoader) new FirebaseImageLoader.StringLoader.Factory().build(null); | ||
| assertNotNull(loader); | ||
| } | ||
|
|
||
| @Test | ||
| public void factory_withStorage_buildsStringLoaderUsingProvidedInstance() { | ||
| FirebaseImageLoader.StringLoader loader = | ||
| (FirebaseImageLoader.StringLoader) new FirebaseImageLoader.StringLoader.Factory(mStorage).build(null); | ||
| // The provided storage instance should be used — valid URL resolves without exception | ||
| LoadData<InputStream> result = loader.buildLoadData(VALID_GS_URL, 0, 0, new Options()); | ||
| assertNotNull(result); | ||
| } | ||
|
|
||
| private FirebaseImageLoader.StringLoader loaderWithMockStorage() { | ||
| return new FirebaseImageLoader.StringLoader(mStorage); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.