FragmentRequest { public FragmentRequest sharedElement(@NonNull final View element, @NonNull final String elementName) { if (sharedElements == null) { this.sharedElements = new ArrayList<>(1); } this.sharedElements.add(new Pair<>(element, elementName)); return this; } FragmentRequest(final FragmentController controller, int fragmentId);   FragmentRequest(final FragmentController controller, final Fragment fragment); @SuppressWarnings("StringBufferReplaceableByString") @Override String toString(); @NonNull Fragment fragment(); FragmentRequest fragmentId(final int fragmentId); int fragmentId(); FragmentRequest outgoingFragmentId(final int fragmentId); int outgoingFragmentId(); FragmentRequest arguments(@Nullable final Bundle arguments); @Nullable Bundle arguments(); FragmentRequest transaction(@Transaction final int transaction); @Transaction int transaction(); FragmentRequest tag(@Nullable final String fragmentTag); @Nullable String tag(); FragmentRequest viewContainerId(@IdRes final int containerId); @IdRes int viewContainerId(); FragmentRequest transition(@Nullable final FragmentTransition transition); @Nullable FragmentTransition transition(); FragmentRequest transitionStyle(@StyleRes final int transitionStyle); @StyleRes int transitionStyle(); FragmentRequest enterTransition(@Nullable final Object transition); @Nullable Object enterTransition(); FragmentRequest exitTransition(@Nullable final Object transition); @Nullable Object exitTransition(); FragmentRequest reenterTransition(@Nullable final Object transition); @Nullable Object reenterTransition(); FragmentRequest returnTransition(@Nullable final Object transition); @Nullable Object returnTransition(); FragmentRequest allowEnterTransitionOverlap(final boolean allowOverlap); Boolean allowEnterTransitionOverlap(); FragmentRequest allowReturnTransitionOverlap(final boolean allowOverlap); Boolean allowReturnTransitionOverlap(); @SafeVarargs final FragmentRequest sharedElements(@NonNull final Pair<View, String>... elements); FragmentRequest sharedElement(@NonNull final View element, @NonNull final String elementName); @Nullable List<Pair<View, String>> sharedElements(); @Nullable Pair<View, String> singleSharedElement(); FragmentRequest sharedElementEnterTransition(@Nullable final Object transition); @Nullable Object sharedElementEnterTransition(); FragmentRequest sharedElementReturnTransition(@Nullable final Object transition); @Nullable Object sharedElementReturnTransition(); FragmentRequest replaceSame(final boolean replace); boolean replaceSame(); FragmentRequest addToBackStack(final boolean add); boolean addToBackStack(); FragmentRequest allowStateLoss(final boolean allow); boolean allowStateLoss(); FragmentRequest immediate(final boolean immediate); boolean immediate(); @Nullable Fragment execute(); boolean executed(); static final int NO_ID; static final int NO_STYLE; static final int REPLACE; static final int ADD; static final int REMOVE; static final int SHOW; static final int HIDE; static final int ATTACH; static final int DETACH; }
@SuppressWarnings("ConstantConditions") @Test public void testSharedElement() { final FragmentRequest request = new FragmentRequest(mock(FragmentController.class), FragmentRequest.NO_ID); final View firstElement = new View(context); final View secondElement = new View(context); final View thirdElement = new View(context); request.sharedElement(firstElement, "first_element"); request.sharedElement(secondElement, "second_element"); request.sharedElement(thirdElement, "third_element"); final List<Pair<View, String>> sharedElements = request.sharedElements(); assertThat(sharedElements, is(notNullValue())); assertThat(sharedElements.size(), is(3)); assertThat(sharedElements.get(0).first, is(firstElement)); assertThat(sharedElements.get(0).second, is("first_element")); assertThat(sharedElements.get(1).first, is(secondElement)); assertThat(sharedElements.get(1).second, is("second_element")); assertThat(sharedElements.get(2).first, is(thirdElement)); assertThat(sharedElements.get(2).second, is("third_element")); }