Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add SecurityException unit test
  • Loading branch information
JeroenWeener committed May 19, 2023
commit f4e47933e0c510aeb1a2456a94d5c7e7c861a673
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
package io.flutter.plugins.imagepicker;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;

import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
Expand Down Expand Up @@ -66,7 +72,22 @@ public void FileUtil_GetPathFromUri() throws IOException {

assertTrue(bytes.length > 0);
String imageStream = new String(bytes, UTF_8);
assertTrue(imageStream.equals("imageStream"));
assertEquals("imageStream", imageStream);
}

@Test
public void FileUtil_GetPathFromUri_securityException() throws IOException {
Uri uri = Uri.parse("content://dummy/dummy.png");

ContentResolver mockContentResolver = mock(ContentResolver.class);
when(mockContentResolver.openInputStream(any(Uri.class))).thenThrow(SecurityException.class);

Context mockContext = mock(Context.class);
when(mockContext.getContentResolver()).thenReturn(mockContentResolver);

String path = fileUtils.getPathFromUri(mockContext, uri);

assertNull(path);
}

@Test
Expand Down