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

        final PostponedFragment2 fragment2 = new PostponedFragment2();
        final PostponedFragment1 fragment3 = new PostponedFragment1();

        final int[] commit = new int[1];
        // Need to run this on the UI thread so that the transaction doesn't start
        // between the two
        mInstrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                commit[0] = fm.beginTransaction()
                        .addSharedElement(startBlue, "blueSquare")
                        .replace(R.id.fragmentContainer, fragment2)
                        .addToBackStack(null)
                        .setReorderingAllowed(true)
                        .commit();

                fm.beginTransaction()
                        .addSharedElement(startBlue, "blueSquare")
                        .replace(R.id.fragmentContainer, fragment3)
                        .addToBackStack(null)
                        .setReorderingAllowed(true)
                        .commit();
            }
        });
        FragmentTestUtil.waitForExecution(mActivityRule);

        // transition to fragment2 should be started
        assertForwardTransition(mBeginningFragment, fragment2);

        // 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);

        FragmentTestUtil.popBackStackImmediate(mActivityRule, commit[0],
                FragmentManager.POP_BACK_STACK_INCLUSIVE);

        assertBackTransition(fragment3, fragment2);

        assertPostponedTransition(fragment2, mBeginningFragment, fragment3);

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

        // make sure it ran
        assertBackTransition(fragment2, mBeginningFragment);
    }
// This tests when the transactions are executed together
This tests when the transactions are executed together
This tests when the transactions are executed together
@Test
    public void forcedTransition1() throws Throwable {
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        final View startBlue = mActivityRule.getActivity().findViewById(R.id.blueSquare);
        final PostponedFragment2 fragment2 = new PostponedFragment2();
        final PostponedFragment1 fragment3 = new PostponedFragment1();
        final int[] commit = new int[1];
        mInstrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                commit[0] = fm.beginTransaction()
                        .addSharedElement(startBlue, "blueSquare")
                        .replace(R.id.fragmentContainer, fragment2)
                        .addToBackStack(null)
                        .setReorderingAllowed(true)
                        .commit();
                fm.beginTransaction()
                        .addSharedElement(startBlue, "blueSquare")
                        .replace(R.id.fragmentContainer, fragment3)
                        .addToBackStack(null)
                        .setReorderingAllowed(true)
                        .commit();
            }
        });
        FragmentTestUtil.waitForExecution(mActivityRule);
        assertForwardTransition(mBeginningFragment, fragment2);
        assertPostponedTransition(fragment2, fragment3, mBeginningFragment);
        fragment3.startPostponedEnterTransition();
        assertForwardTransition(fragment2, fragment3);
        FragmentTestUtil.popBackStackImmediate(mActivityRule, commit[0],
                FragmentManager.POP_BACK_STACK_INCLUSIVE);
        assertBackTransition(fragment3, fragment2);
        assertPostponedTransition(fragment2, mBeginningFragment, fragment3);
        mBeginningFragment.startPostponedEnterTransition();
        assertBackTransition(fragment2, mBeginningFragment);
    }
@ Test public void forcedTransition1 ( ) throws Throwable { final FragmentManager fm = mActivityRule . getActivity ( ) . getSupportFragmentManager ( ) ; final View startBlue = mActivityRule . getActivity ( ) . findViewById ( R . id . blueSquare ) ; final PostponedFragment2 fragment2 = new PostponedFragment2 ( ) ; final PostponedFragment1 fragment3 = new PostponedFragment1 ( ) ; final int [ ] commit = new int [ 1 ] ; mInstrumentation . runOnMainSync ( new Runnable ( ) { @ Override public void run ( ) { commit [ 0 ] = fm . beginTransaction ( ) . addSharedElement ( startBlue , "blueSquare" ) . replace ( R . id . fragmentContainer , fragment2 ) . addToBackStack ( null ) . setReorderingAllowed ( true ) . commit ( ) ; fm . beginTransaction ( ) . addSharedElement ( startBlue , "blueSquare" ) . replace ( R . id . fragmentContainer , fragment3 ) . addToBackStack ( null ) . setReorderingAllowed ( true ) . commit ( ) ; } } ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; assertForwardTransition ( mBeginningFragment , fragment2 ) ; assertPostponedTransition ( fragment2 , fragment3 , mBeginningFragment ) ; fragment3 . startPostponedEnterTransition ( ) ; assertForwardTransition ( fragment2 , fragment3 ) ; FragmentTestUtil . popBackStackImmediate ( mActivityRule , commit [ 0 ] , FragmentManager . POP_BACK_STACK_INCLUSIVE ) ; assertBackTransition ( fragment3 , fragment2 ) ; assertPostponedTransition ( fragment2 , mBeginningFragment , fragment3 ) ; mBeginningFragment . startPostponedEnterTransition ( ) ; assertBackTransition ( fragment2 , mBeginningFragment ) ; }
This tests when the transactions are executed together
This tests when the transactions are executed together
// Need to run this on the UI thread so that the transaction doesn't start // between the two // transition to fragment2 should be started // fragment3 should be postponed, but fragment2 should be executed with no transition. // start the postponed transition // make sure it ran // start the postponed transition // make sure it ran