fragment/src/androidTest/java/androidx/fragment/app/FragmentLifecycleTest.java
@Test
    @UiThreadTest
    public void runTransactionsOnChange() throws Throwable {
        FragmentController fc = FragmentTestUtil.createController(mActivityRule);
        FragmentTestUtil.resume(mActivityRule, fc, null);
        FragmentManager fm = fc.getSupportFragmentManager();

        RemoveHelloInOnResume fragment1 = new RemoveHelloInOnResume();
        StrictFragment fragment2 = new StrictFragment();
        fm.beginTransaction()
                .add(fragment1, "1")
                .setReorderingAllowed(false)
                .commit();
        fm.beginTransaction()
                .add(fragment2, "Hello")
                .setReorderingAllowed(false)
                .commit();
        fm.executePendingTransactions();

        assertEquals(2, fm.getFragments().size());
        assertTrue(fm.getFragments().contains(fragment1));
        assertTrue(fm.getFragments().contains(fragment2));

        Pair<Parcelable, FragmentManagerNonConfig> savedState =
                FragmentTestUtil.destroy(mActivityRule, fc);
        fc = FragmentTestUtil.createController(mActivityRule);
        FragmentTestUtil.resume(mActivityRule, fc, savedState);
        fm = fc.getSupportFragmentManager();

        assertEquals(1, fm.getFragments().size());
        for (Fragment fragment : fm.getFragments()) {
            assertTrue(fragment instanceof RemoveHelloInOnResume);
        }
    }
/**
     * When the FragmentManager state changes, the pending transactions should execute.
     */
When the FragmentManager state changes, the pending transactions should execute.
When the FragmentManager state changes the pending transactions should execute .
@Test
    @UiThreadTest
    public void runTransactionsOnChange() throws Throwable {
        FragmentController fc = FragmentTestUtil.createController(mActivityRule);
        FragmentTestUtil.resume(mActivityRule, fc, null);
        FragmentManager fm = fc.getSupportFragmentManager();
        RemoveHelloInOnResume fragment1 = new RemoveHelloInOnResume();
        StrictFragment fragment2 = new StrictFragment();
        fm.beginTransaction()
                .add(fragment1, "1")
                .setReorderingAllowed(false)
                .commit();
        fm.beginTransaction()
                .add(fragment2, "Hello")
                .setReorderingAllowed(false)
                .commit();
        fm.executePendingTransactions();
        assertEquals(2, fm.getFragments().size());
        assertTrue(fm.getFragments().contains(fragment1));
        assertTrue(fm.getFragments().contains(fragment2));
        Pair<Parcelable, FragmentManagerNonConfig> savedState =
                FragmentTestUtil.destroy(mActivityRule, fc);
        fc = FragmentTestUtil.createController(mActivityRule);
        FragmentTestUtil.resume(mActivityRule, fc, savedState);
        fm = fc.getSupportFragmentManager();
        assertEquals(1, fm.getFragments().size());
        for (Fragment fragment : fm.getFragments()) {
            assertTrue(fragment instanceof RemoveHelloInOnResume);
        }
    }
@ Test @ UiThreadTest public void runTransactionsOnChange ( ) throws Throwable { FragmentController fc = FragmentTestUtil . createController ( mActivityRule ) ; FragmentTestUtil . resume ( mActivityRule , fc , null ) ; FragmentManager fm = fc . getSupportFragmentManager ( ) ; RemoveHelloInOnResume fragment1 = new RemoveHelloInOnResume ( ) ; StrictFragment fragment2 = new StrictFragment ( ) ; fm . beginTransaction ( ) . add ( fragment1 , "1" ) . setReorderingAllowed ( false ) . commit ( ) ; fm . beginTransaction ( ) . add ( fragment2 , "Hello" ) . setReorderingAllowed ( false ) . commit ( ) ; fm . executePendingTransactions ( ) ; assertEquals ( 2 , fm . getFragments ( ) . size ( ) ) ; assertTrue ( fm . getFragments ( ) . contains ( fragment1 ) ) ; assertTrue ( fm . getFragments ( ) . contains ( fragment2 ) ) ; Pair < Parcelable , FragmentManagerNonConfig > savedState = FragmentTestUtil . destroy ( mActivityRule , fc ) ; fc = FragmentTestUtil . createController ( mActivityRule ) ; FragmentTestUtil . resume ( mActivityRule , fc , savedState ) ; fm = fc . getSupportFragmentManager ( ) ; assertEquals ( 1 , fm . getFragments ( ) . size ( ) ) ; for ( Fragment fragment : fm . getFragments ( ) ) { assertTrue ( fragment instanceof RemoveHelloInOnResume ) ; } }
When the FragmentManager state changes, the pending transactions should execute.
When the FragmentManager state changes the pending transactions should execute .