FragmentController { @VisibleForTesting static void attachTransitionsToFragment(final FragmentRequest request, final Fragment fragment) { if (request.hasTransition(FragmentRequest.TRANSITION_ENTER)) { fragment.setEnterTransition(request.enterTransition); } if (request.hasTransition(FragmentRequest.TRANSITION_EXIT)) { fragment.setExitTransition(request.exitTransition); } if (request.hasTransition(FragmentRequest.TRANSITION_REENTER)) { fragment.setReenterTransition(request.reenterTransition); } if (request.hasTransition(FragmentRequest.TRANSITION_RETURN)) { fragment.setReturnTransition(request.returnTransition); } if (request.hasTransition(FragmentRequest.TRANSITION_SHARED_ELEMENT_ENTER)) { fragment.setSharedElementEnterTransition(request.sharedElementEnterTransition); } if (request.hasTransition(FragmentRequest.TRANSITION_SHARED_ELEMENT_RETURN)) { fragment.setSharedElementReturnTransition(request.sharedElementReturnTransition); } if (request.allowEnterTransitionOverlap != null) { fragment.setAllowEnterTransitionOverlap(request.allowEnterTransitionOverlap); } if (request.allowReturnTransitionOverlap != null) { fragment.setAllowReturnTransitionOverlap(request.allowReturnTransitionOverlap); } } FragmentController(@NonNull final FragmentActivity parentActivity);  FragmentController(@NonNull final Fragment parentFragment);  FragmentController(@NonNull final FragmentManager fragmentManager);  FragmentController(@Nullable final Context context, @NonNull final FragmentManager fragmentManager); @NonNull FragmentManager getFragmentManager(); void setViewContainerId(@IdRes final int containerId); @IdRes int getViewContainerId(); void setFactory(@Nullable final FragmentFactory factory); boolean hasFactory(); @Nullable FragmentFactory getFactory(); void setRequestInterceptor(@Nullable final FragmentRequestInterceptor interceptor); void registerOnRequestListener(@NonNull final OnRequestListener listener); void unregisterOnRequestListener(@NonNull final OnRequestListener listener); void registerOnBackStackChangeListener(@NonNull final OnBackStackChangeListener listener); void unregisterOnBackStackChangeListener(@NonNull final OnBackStackChangeListener listener); @NonNull final FragmentRequest newRequest(); @NonNull final FragmentRequest newRequest(@NonNull final Fragment fragment); @NonNull final FragmentRequest newRequest(final int fragmentId); @SuppressWarnings("NewApi") @NonNull FragmentTransaction createTransaction(@NonNull final FragmentRequest request); @Nullable Fragment findCurrentFragment(); @Nullable Fragment findFragmentByFactoryId(final int factoryFragmentId); boolean hasBackStackEntries(); @Nullable FragmentManager.BackStackEntry getTopBackStackEntry(); void clearBackStack(); boolean clearBackStackImmediate(); final void destroy(); static final String FRAGMENT_TAG; static final int NO_CONTAINER_ID; }
@Config(sdk = Build.VERSION_CODES.LOLLIPOP) @Test public void testAttachTransitionsToFragment() { final Fragment mockFragment = mock(TestFragment.class); final Transition enterTransition = createTestTransition(); final Transition exitTransition = createTestTransition(); final Transition reenterTransition = createTestTransition(); final Transition returnTransition = createTestTransition(); final Transition sharedElementEnterTransition = createTestTransition(); final Transition sharedElementEnterReturnTransition = createTestTransition(); final FragmentRequest request = new FragmentRequest(mock(FragmentController.class), mockFragment) .enterTransition(enterTransition) .exitTransition(exitTransition) .reenterTransition(reenterTransition) .returnTransition(returnTransition) .sharedElementEnterTransition(sharedElementEnterTransition) .sharedElementReturnTransition(sharedElementEnterReturnTransition) .allowEnterTransitionOverlap(true) .allowReturnTransitionOverlap(false); FragmentController.attachTransitionsToFragment(request, mockFragment); verify(mockFragment).setEnterTransition(enterTransition); verify(mockFragment).setExitTransition(exitTransition); verify(mockFragment).setReenterTransition(reenterTransition); verify(mockFragment).setReturnTransition(returnTransition); verify(mockFragment).setSharedElementEnterTransition(sharedElementEnterTransition); verify(mockFragment).setSharedElementReturnTransition(sharedElementEnterReturnTransition); verify(mockFragment).setAllowEnterTransitionOverlap(true); verify(mockFragment).setAllowReturnTransitionOverlap(false); verifyNoMoreInteractions(mockFragment); }
@Config(sdk = Build.VERSION_CODES.LOLLIPOP) @Test public void testAttachTransitionsToFragmentForRequestWithoutTransitions() { final Fragment mockFragment = mock(TestFragment.class); final FragmentRequest request = new FragmentRequest(mock(FragmentController.class), mockFragment); FragmentController.attachTransitionsToFragment(request, mockFragment); verifyZeroInteractions(mockFragment); }