Skip to content

Commit bef8899

Browse files
committed
Add test
1 parent aecc76f commit bef8899

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ void saveResult(
9898

9999
SharedPreferences.Editor editor = prefs.edit();
100100
if (path != null) {
101-
Set<String> imageSet = new HashSet<>();
102-
imageSet.addAll(path);
101+
Set<String> imageSet = new HashSet<>(path);
103102
editor.putStringSet(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY, imageSet);
104103
}
105104
if (errorCode != null) {

packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImagePickerCacheTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static io.flutter.plugins.imagepicker.ImagePickerCache.SHARED_PREFERENCES_NAME;
88
import static org.hamcrest.MatcherAssert.assertThat;
99
import static org.hamcrest.core.IsEqual.equalTo;
10+
import static org.junit.Assert.assertTrue;
1011
import static org.mockito.ArgumentMatchers.any;
1112
import static org.mockito.Mockito.mock;
1213
import static org.mockito.Mockito.when;
@@ -115,4 +116,11 @@ public void imageCache_shouldBeAbleToSetAndGetQuality() {
115116
(int) resultMapWithDefaultQuality.get(ImagePickerCache.MAP_KEY_IMAGE_QUALITY);
116117
assertThat(defaultImageQuality, equalTo(100));
117118
}
119+
120+
@Test
121+
public void imageCache_shouldNotThrowIfPathIsNullInSaveResult() {
122+
final ImagePickerCache cache = new ImagePickerCache(mockActivity);
123+
cache.saveResult(null, "errorCode", "errorMessage");
124+
assertTrue("No exception thrown when ImagePickerCache.saveResult() was passed a null path", true);
125+
}
118126
}

0 commit comments

Comments
 (0)