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

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

        FragmentTestUtil.waitForExecution(mActivityRule);

        // should be postponed now
        assertPostponedTransition(mBeginningFragment, fragment, null);

        mActivityRule.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                // start the postponed transition
                fragment.startPostponedEnterTransition();

                try {
                    // This should trigger an IllegalStateException
                    fm.executePendingTransactions();
                    fail("commitNow() while executing a transaction should cause an "
                            + "IllegalStateException");
                } catch (IllegalStateException e) {
                    // expected
                }
            }
        });
    }
// Ensure that the postponed fragment transactions don't allow reentrancy in fragment manager
Ensure that the postponed fragment transactions don't allow reentrancy in fragment manager
Ensure that the postponed fragment transactions don ' t allow reentrancy in fragment manager
@Test
    public void postponeDoesNotAllowReentrancy() throws Throwable {
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        final View startBlue = mActivityRule.getActivity().findViewById(R.id.blueSquare);
        final CommitNowFragment fragment = new CommitNowFragment();
        fm.beginTransaction()
                .addSharedElement(startBlue, "blueSquare")
                .replace(R.id.fragmentContainer, fragment)
                .setReorderingAllowed(true)
                .addToBackStack(null)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);
        assertPostponedTransition(mBeginningFragment, fragment, null);
        mActivityRule.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                fragment.startPostponedEnterTransition();
                try {
                    fm.executePendingTransactions();
                    fail("commitNow() while executing a transaction should cause an "
                            + "IllegalStateException");
                } catch (IllegalStateException e) {
                }
            }
        });
    }
@ Test public void postponeDoesNotAllowReentrancy ( ) throws Throwable { final FragmentManager fm = mActivityRule . getActivity ( ) . getSupportFragmentManager ( ) ; final View startBlue = mActivityRule . getActivity ( ) . findViewById ( R . id . blueSquare ) ; final CommitNowFragment fragment = new CommitNowFragment ( ) ; fm . beginTransaction ( ) . addSharedElement ( startBlue , "blueSquare" ) . replace ( R . id . fragmentContainer , fragment ) . setReorderingAllowed ( true ) . addToBackStack ( null ) . commit ( ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; assertPostponedTransition ( mBeginningFragment , fragment , null ) ; mActivityRule . runOnUiThread ( new Runnable ( ) { @ Override public void run ( ) { fragment . startPostponedEnterTransition ( ) ; try { fm . executePendingTransactions ( ) ; fail ( "commitNow() while executing a transaction should cause an " + "IllegalStateException" ) ; } catch ( IllegalStateException e ) { } } } ) ; }
Ensure that the postponed fragment transactions don't allow reentrancy in fragment manager
Ensure that the postponed fragment transactions don ' t allow reentrancy in fragment manager
// should be postponed now // start the postponed transition // This should trigger an IllegalStateException // expected