fragment/src/androidTest/java/androidx/fragment/app/FragmentTransitionTest.java
@Test
    public void removeAdded() throws Throwable {
        final TransitionFragment fragment1 = setupInitialFragment();

        final View startBlue = findBlue();
        final View startGreen = findGreen();

        final TransitionFragment fragment2 = new TransitionFragment();
        fragment2.setLayoutId(R.layout.scene2);

        mInstrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                mFragmentManager.beginTransaction()
                        .setReorderingAllowed(mReorderingAllowed)
                        .replace(R.id.fragmentContainer, fragment2)
                        .replace(R.id.fragmentContainer, fragment1)
                        .replace(R.id.fragmentContainer, fragment2)
                        .addToBackStack(null)
                        .commit();
            }
        });
        FragmentTestUtil.waitForExecution(mActivityRule);
        assertEquals(2, mOnBackStackChangedTimes);

        // should be a normal transition from fragment1 to fragment2
        fragment2.waitForTransition();
        final View endBlue = findBlue();
        final View endGreen = findGreen();
        verifyAndClearTransition(fragment1.exitTransition, null, startBlue, startGreen);
        verifyAndClearTransition(fragment2.enterTransition, null, endBlue, endGreen);
        verifyNoOtherTransitions(fragment1);
        verifyNoOtherTransitions(fragment2);

        // Pop should also do the same thing
        FragmentTestUtil.popBackStackImmediate(mActivityRule);
        assertEquals(3, mOnBackStackChangedTimes);

        fragment1.waitForTransition();
        final View popBlue = findBlue();
        final View popGreen = findGreen();
        verifyAndClearTransition(fragment1.reenterTransition, null, popBlue, popGreen);
        verifyAndClearTransition(fragment2.returnTransition, null, endBlue, endGreen);
        verifyNoOtherTransitions(fragment1);
        verifyNoOtherTransitions(fragment2);
    }
// Adding/removing the same fragment multiple times shouldn't mess anything up
Adding/removing the same fragment multiple times shouldn't mess anything up
Adding / removing the same fragment multiple times shouldn ' t mess anything up
@Test
    public void removeAdded() throws Throwable {
        final TransitionFragment fragment1 = setupInitialFragment();
        final View startBlue = findBlue();
        final View startGreen = findGreen();
        final TransitionFragment fragment2 = new TransitionFragment();
        fragment2.setLayoutId(R.layout.scene2);
        mInstrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                mFragmentManager.beginTransaction()
                        .setReorderingAllowed(mReorderingAllowed)
                        .replace(R.id.fragmentContainer, fragment2)
                        .replace(R.id.fragmentContainer, fragment1)
                        .replace(R.id.fragmentContainer, fragment2)
                        .addToBackStack(null)
                        .commit();
            }
        });
        FragmentTestUtil.waitForExecution(mActivityRule);
        assertEquals(2, mOnBackStackChangedTimes);
        fragment2.waitForTransition();
        final View endBlue = findBlue();
        final View endGreen = findGreen();
        verifyAndClearTransition(fragment1.exitTransition, null, startBlue, startGreen);
        verifyAndClearTransition(fragment2.enterTransition, null, endBlue, endGreen);
        verifyNoOtherTransitions(fragment1);
        verifyNoOtherTransitions(fragment2);
        FragmentTestUtil.popBackStackImmediate(mActivityRule);
        assertEquals(3, mOnBackStackChangedTimes);
        fragment1.waitForTransition();
        final View popBlue = findBlue();
        final View popGreen = findGreen();
        verifyAndClearTransition(fragment1.reenterTransition, null, popBlue, popGreen);
        verifyAndClearTransition(fragment2.returnTransition, null, endBlue, endGreen);
        verifyNoOtherTransitions(fragment1);
        verifyNoOtherTransitions(fragment2);
    }
@ Test public void removeAdded ( ) throws Throwable { final TransitionFragment fragment1 = setupInitialFragment ( ) ; final View startBlue = findBlue ( ) ; final View startGreen = findGreen ( ) ; final TransitionFragment fragment2 = new TransitionFragment ( ) ; fragment2 . setLayoutId ( R . layout . scene2 ) ; mInstrumentation . runOnMainSync ( new Runnable ( ) { @ Override public void run ( ) { mFragmentManager . beginTransaction ( ) . setReorderingAllowed ( mReorderingAllowed ) . replace ( R . id . fragmentContainer , fragment2 ) . replace ( R . id . fragmentContainer , fragment1 ) . replace ( R . id . fragmentContainer , fragment2 ) . addToBackStack ( null ) . commit ( ) ; } } ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; assertEquals ( 2 , mOnBackStackChangedTimes ) ; fragment2 . waitForTransition ( ) ; final View endBlue = findBlue ( ) ; final View endGreen = findGreen ( ) ; verifyAndClearTransition ( fragment1 . exitTransition , null , startBlue , startGreen ) ; verifyAndClearTransition ( fragment2 . enterTransition , null , endBlue , endGreen ) ; verifyNoOtherTransitions ( fragment1 ) ; verifyNoOtherTransitions ( fragment2 ) ; FragmentTestUtil . popBackStackImmediate ( mActivityRule ) ; assertEquals ( 3 , mOnBackStackChangedTimes ) ; fragment1 . waitForTransition ( ) ; final View popBlue = findBlue ( ) ; final View popGreen = findGreen ( ) ; verifyAndClearTransition ( fragment1 . reenterTransition , null , popBlue , popGreen ) ; verifyAndClearTransition ( fragment2 . returnTransition , null , endBlue , endGreen ) ; verifyNoOtherTransitions ( fragment1 ) ; verifyNoOtherTransitions ( fragment2 ) ; }
Adding/removing the same fragment multiple times shouldn't mess anything up
Adding / removing the same fragment multiple times shouldn ' t mess anything up
// should be a normal transition from fragment1 to fragment2 // Pop should also do the same thing