Router { public void launchFilePicker(Activity activity) { Intent samsungIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA"); samsungIntent.addCategory(Intent.CATEGORY_DEFAULT); if (activity.getPackageManager().resolveActivity(samsungIntent, 0) != null) { activity.startActivityForResult(samsungIntent, Router.REQUEST_CODE_IMPORT_FILE_PICKER); } else { Intent fileIntent = new Intent(Intent.ACTION_GET_CONTENT); fileIntent.setType("*/*"); activity.startActivityForResult(fileIntent, Router.REQUEST_CODE_IMPORT_FILE_PICKER); } }  void launchFeedbackActivity(Activity activity); void launchImportActivityForResult(Activity activity, Uri data); void launchCreateDeckFlow(Activity activity, NewDeckContext newDeckContext); void launchFilePicker(Activity activity); static final int REQUEST_CODE_IMPORT_FILE_PICKER; static final int REQUEST_CODE_IMPORT_FILE; static final int REQUEST_CODE_CREATE_DECK; }
@Test public void shouldLaunchFilePickerForSamsungPhone() { Activity activity = mock(Activity.class, RETURNS_DEEP_STUBS); Intent samsungIntent = getSamsungIntent(); when(activity.getPackageManager().resolveActivity(samsungIntent, 0)).thenReturn(mock(ResolveInfo.class)); router.launchFilePicker(activity); ArgumentCaptor<Intent> argument = ArgumentCaptor.forClass(Intent.class); verify(activity).startActivityForResult(argument.capture(), eq(Router.REQUEST_CODE_IMPORT_FILE_PICKER)); assertEquals("com.sec.android.app.myfiles.PICK_DATA", argument.getValue().getAction()); }
@Test public void shouldLaunchFilePickerForNonSamsungPhones() { Activity activity = mock(Activity.class, RETURNS_DEEP_STUBS); Intent samsungIntent = getSamsungIntent(); when(activity.getPackageManager().resolveActivity(samsungIntent, 0)).thenReturn(null); router.launchFilePicker(activity); ArgumentCaptor<Intent> argument = ArgumentCaptor.forClass(Intent.class); verify(activity).startActivityForResult(argument.capture(), eq(Router.REQUEST_CODE_IMPORT_FILE_PICKER)); assertEquals(Intent.ACTION_GET_CONTENT, argument.getValue().getAction()); }