IntentStarters { public static IntentStarter fragmentStarter(@NonNull final Fragment fragment) { return new FragmentStarter(fragment); } private  IntentStarters(); @NonNull static IntentStarter activityStarter(@NonNull final Activity activity); static IntentStarter fragmentStarter(@NonNull final Fragment fragment); static IntentStarter supportFragmentStarter(@NonNull final androidx.fragment.app.Fragment fragment);  }
@Test public void testFragmentStarter() throws IllegalStateException { final Fragment fragment = Robolectric.buildFragment(TestFragment.class, TestActivity.class).create(TestActivity.CONTENT_VIEW_ID, null).get(); final IntentStarter starter = IntentStarters.fragmentStarter(fragment); assertThat(starter, is(notNullValue())); assertThat(starter.getContext(), instanceOf(TestActivity.class)); }
@Test public void testFragmentStarterStartIntent() { final Fragment mockFragment = mock(Fragment.class); final Intent intent = new Intent(); final IntentStarter starter = IntentStarters.fragmentStarter(mockFragment); starter.startIntent(intent); verify(mockFragment).startActivity(intent); }
@Config(sdk = Build.VERSION_CODES.JELLY_BEAN) @Test public void testFragmentStarterStartIntentWithOptions() { final Fragment mockFragment = mock(Fragment.class); final Intent intent = new Intent(); final IntentStarter starter = IntentStarters.fragmentStarter(mockFragment); starter.startIntent(intent, Bundle.EMPTY); verify(mockFragment).startActivity(intent, Bundle.EMPTY); }
@Test public void testFragmentStarterStartIntentForResult() { final Fragment mockFragment = mock(Fragment.class); final Intent intent = new Intent(); final IntentStarter starter = IntentStarters.fragmentStarter(mockFragment); starter.startIntentForResult(intent, 1000); verify(mockFragment).startActivityForResult(intent, 1000); }
@Config(sdk = Build.VERSION_CODES.JELLY_BEAN) @Test public void testFragmentStarterStartIntentForResultWithOptions() { final Fragment mockFragment = mock(Fragment.class); final Intent intent = new Intent(); final IntentStarter starter = IntentStarters.fragmentStarter(mockFragment); starter.startIntentForResult(intent, 1000, Bundle.EMPTY); verify(mockFragment).startActivityForResult(intent, 1000, Bundle.EMPTY); }
@Test public void testFragmentStarterOverridePendingTransition() throws IllegalStateException { final Fragment fragment = Robolectric.buildFragment(TestFragment.class, TestActivity.class).create(TestActivity.CONTENT_VIEW_ID, null).get(); final IntentStarter starter = IntentStarters.fragmentStarter(fragment); starter.overridePendingTransition( android.R.anim.fade_in, android.R.anim.fade_out ); }