fragment/src/androidTest/java/androidx/fragment/app/PostponedTransitionTest.java
@Test
    public void forcedTransition2() throws Throwable {
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        final View startBlue = mActivityRule.getActivity().findViewById(R.id.blueSquare);

        final PostponedFragment2 fragment2 = new PostponedFragment2();

        fm.beginTransaction()
                .addSharedElement(startBlue, "blueSquare")
                .replace(R.id.fragmentContainer, fragment2)
                .addToBackStack(null)
                .setReorderingAllowed(true)
                .commit();

        FragmentTestUtil.waitForExecution(mActivityRule);

        assertPostponedTransition(mBeginningFragment, fragment2, null);

        final PostponedFragment1 fragment3 = new PostponedFragment1();
        fm.beginTransaction()
                .addSharedElement(startBlue, "blueSquare")
                .replace(R.id.fragmentContainer, fragment3)
                .addToBackStack(null)
                .setReorderingAllowed(true)
                .commit();

        // This should cancel the mBeginningFragment -> fragment2 transition
        // and start fragment2 -> fragment3 transition postponed
        FragmentTestUtil.waitForExecution(mActivityRule);

        // fragment3 should be postponed, but fragment2 should be executed with no transition.
        assertPostponedTransition(fragment2, fragment3, mBeginningFragment);

        // start the postponed transition
        fragment3.startPostponedEnterTransition();

        // make sure it ran
        assertForwardTransition(fragment2, fragment3);

        // Pop back to fragment2, but it should be postponed
        FragmentTestUtil.popBackStackImmediate(mActivityRule);

        assertPostponedTransition(fragment3, fragment2, null);

        // Pop to mBeginningFragment -- should cancel the fragment2 transition and
        // start the mBeginningFragment transaction postponed

        FragmentTestUtil.popBackStackImmediate(mActivityRule);

        assertPostponedTransition(fragment2, mBeginningFragment, fragment3);

        // start the postponed transition
        mBeginningFragment.startPostponedEnterTransition();

        // make sure it ran
        assertBackTransition(fragment2, mBeginningFragment);
    }
// This tests when the transactions are processed separately.
This tests when the transactions are processed separately.
This tests when the transactions are processed separately .
@Test
    public void forcedTransition2() throws Throwable {
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        final View startBlue = mActivityRule.getActivity().findViewById(R.id.blueSquare);
        final PostponedFragment2 fragment2 = new PostponedFragment2();
        fm.beginTransaction()
                .addSharedElement(startBlue, "blueSquare")
                .replace(R.id.fragmentContainer, fragment2)
                .addToBackStack(null)
                .setReorderingAllowed(true)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);
        assertPostponedTransition(mBeginningFragment, fragment2, null);
        final PostponedFragment1 fragment3 = new PostponedFragment1();
        fm.beginTransaction()
                .addSharedElement(startBlue, "blueSquare")
                .replace(R.id.fragmentContainer, fragment3)
                .addToBackStack(null)
                .setReorderingAllowed(true)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);
        assertPostponedTransition(fragment2, fragment3, mBeginningFragment);
        fragment3.startPostponedEnterTransition();
        assertForwardTransition(fragment2, fragment3);
        FragmentTestUtil.popBackStackImmediate(mActivityRule);
        assertPostponedTransition(fragment3, fragment2, null);
        FragmentTestUtil.popBackStackImmediate(mActivityRule);
        assertPostponedTransition(fragment2, mBeginningFragment, fragment3);
        mBeginningFragment.startPostponedEnterTransition();
        assertBackTransition(fragment2, mBeginningFragment);
    }
@ Test public void forcedTransition2 ( ) throws Throwable { final FragmentManager fm = mActivityRule . getActivity ( ) . getSupportFragmentManager ( ) ; final View startBlue = mActivityRule . getActivity ( ) . findViewById ( R . id . blueSquare ) ; final PostponedFragment2 fragment2 = new PostponedFragment2 ( ) ; fm . beginTransaction ( ) . addSharedElement ( startBlue , "blueSquare" ) . replace ( R . id . fragmentContainer , fragment2 ) . addToBackStack ( null ) . setReorderingAllowed ( true ) . commit ( ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; assertPostponedTransition ( mBeginningFragment , fragment2 , null ) ; final PostponedFragment1 fragment3 = new PostponedFragment1 ( ) ; fm . beginTransaction ( ) . addSharedElement ( startBlue , "blueSquare" ) . replace ( R . id . fragmentContainer , fragment3 ) . addToBackStack ( null ) . setReorderingAllowed ( true ) . commit ( ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; assertPostponedTransition ( fragment2 , fragment3 , mBeginningFragment ) ; fragment3 . startPostponedEnterTransition ( ) ; assertForwardTransition ( fragment2 , fragment3 ) ; FragmentTestUtil . popBackStackImmediate ( mActivityRule ) ; assertPostponedTransition ( fragment3 , fragment2 , null ) ; FragmentTestUtil . popBackStackImmediate ( mActivityRule ) ; assertPostponedTransition ( fragment2 , mBeginningFragment , fragment3 ) ; mBeginningFragment . startPostponedEnterTransition ( ) ; assertBackTransition ( fragment2 , mBeginningFragment ) ; }
This tests when the transactions are processed separately.
This tests when the transactions are processed separately .
// This should cancel the mBeginningFragment -> fragment2 transition // and start fragment2 -> fragment3 transition postponed // fragment3 should be postponed, but fragment2 should be executed with no transition. // start the postponed transition // make sure it ran // Pop back to fragment2, but it should be postponed // Pop to mBeginningFragment -- should cancel the fragment2 transition and // start the mBeginningFragment transaction postponed // start the postponed transition // make sure it ran