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

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

        // make sure transition ran
        assertForwardTransition(mBeginningFragment, fragment1);

        FragmentTestUtil.popBackStackImmediate(mActivityRule);

        // should be postponed going back
        assertPostponedTransition(fragment1, mBeginningFragment, null);

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

        // make sure it ran
        assertBackTransition(fragment1, mBeginningFragment);

        startBlue = mActivityRule.getActivity().findViewById(R.id.blueSquare);

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

        // make sure transition ran
        assertForwardTransition(mBeginningFragment, fragment2);

        FragmentTestUtil.popBackStackImmediate(mActivityRule);

        // should be postponed going back
        assertPostponedTransition(fragment2, mBeginningFragment, null);

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

        // make sure it ran
        assertBackTransition(fragment2, mBeginningFragment);
    }
// Ensure that replacing a fragment doesn't cause problems with the back stack nesting level
Ensure that replacing a fragment doesn't cause problems with the back stack nesting level
Ensure that replacing a fragment doesn ' t cause problems with the back stack nesting level
@Test
    public void backStackNestingLevel() throws Throwable {
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        View startBlue = mActivityRule.getActivity().findViewById(R.id.blueSquare);
        final TransitionFragment fragment1 = new TransitionFragment2();
        fm.beginTransaction()
                .addSharedElement(startBlue, "blueSquare")
                .replace(R.id.fragmentContainer, fragment1)
                .addToBackStack(null)
                .setReorderingAllowed(true)
                .commit();
        assertForwardTransition(mBeginningFragment, fragment1);
        FragmentTestUtil.popBackStackImmediate(mActivityRule);
        assertPostponedTransition(fragment1, mBeginningFragment, null);
        mBeginningFragment.startPostponedEnterTransition();
        assertBackTransition(fragment1, mBeginningFragment);
        startBlue = mActivityRule.getActivity().findViewById(R.id.blueSquare);
        final TransitionFragment fragment2 = new TransitionFragment2();
        fm.beginTransaction()
                .addSharedElement(startBlue, "blueSquare")
                .replace(R.id.fragmentContainer, fragment2)
                .addToBackStack(null)
                .setReorderingAllowed(true)
                .commit();
        assertForwardTransition(mBeginningFragment, fragment2);
        FragmentTestUtil.popBackStackImmediate(mActivityRule);
        assertPostponedTransition(fragment2, mBeginningFragment, null);
        mBeginningFragment.startPostponedEnterTransition();
        assertBackTransition(fragment2, mBeginningFragment);
    }
@ Test public void backStackNestingLevel ( ) throws Throwable { final FragmentManager fm = mActivityRule . getActivity ( ) . getSupportFragmentManager ( ) ; View startBlue = mActivityRule . getActivity ( ) . findViewById ( R . id . blueSquare ) ; final TransitionFragment fragment1 = new TransitionFragment2 ( ) ; fm . beginTransaction ( ) . addSharedElement ( startBlue , "blueSquare" ) . replace ( R . id . fragmentContainer , fragment1 ) . addToBackStack ( null ) . setReorderingAllowed ( true ) . commit ( ) ; assertForwardTransition ( mBeginningFragment , fragment1 ) ; FragmentTestUtil . popBackStackImmediate ( mActivityRule ) ; assertPostponedTransition ( fragment1 , mBeginningFragment , null ) ; mBeginningFragment . startPostponedEnterTransition ( ) ; assertBackTransition ( fragment1 , mBeginningFragment ) ; startBlue = mActivityRule . getActivity ( ) . findViewById ( R . id . blueSquare ) ; final TransitionFragment fragment2 = new TransitionFragment2 ( ) ; fm . beginTransaction ( ) . addSharedElement ( startBlue , "blueSquare" ) . replace ( R . id . fragmentContainer , fragment2 ) . addToBackStack ( null ) . setReorderingAllowed ( true ) . commit ( ) ; assertForwardTransition ( mBeginningFragment , fragment2 ) ; FragmentTestUtil . popBackStackImmediate ( mActivityRule ) ; assertPostponedTransition ( fragment2 , mBeginningFragment , null ) ; mBeginningFragment . startPostponedEnterTransition ( ) ; assertBackTransition ( fragment2 , mBeginningFragment ) ; }
Ensure that replacing a fragment doesn't cause problems with the back stack nesting level
Ensure that replacing a fragment doesn ' t cause problems with the back stack nesting level
// make sure transition ran // should be postponed going back // start the postponed transition // make sure it ran // make sure transition ran // should be postponed going back // start the postponed transition // make sure it ran