fragment/src/androidTest/java/androidx/fragment/app/FragmentViewTests.java
@Test
    public void replaceReplace() throws Throwable {
        FragmentTestUtil.setContentView(mActivityRule, R.layout.double_container);
        ViewGroup container1 = (ViewGroup)
                mActivityRule.getActivity().findViewById(R.id.fragmentContainer1);
        ViewGroup container2 = (ViewGroup)
                mActivityRule.getActivity().findViewById(R.id.fragmentContainer2);
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();

        final StrictViewFragment fragment1 = new StrictViewFragment();
        final StrictViewFragment fragment2 = new StrictViewFragment();
        final StrictViewFragment fragment3 = new StrictViewFragment();
        final StrictViewFragment fragment4 = new StrictViewFragment();
        final StrictViewFragment fragment5 = new StrictViewFragment();
        fm.beginTransaction()
                .add(R.id.fragmentContainer1, fragment1)
                .add(R.id.fragmentContainer2, fragment2)
                .replace(R.id.fragmentContainer1, fragment3)
                .replace(R.id.fragmentContainer2, fragment4)
                .replace(R.id.fragmentContainer1, fragment5)
                .addToBackStack(null)
                .commit();
        FragmentTestUtil.executePendingTransactions(mActivityRule);

        assertChildren(container1, fragment5);
        assertChildren(container2, fragment4);

        fm.popBackStack();
        FragmentTestUtil.executePendingTransactions(mActivityRule);

        assertChildren(container1);
        assertChildren(container2);
    }
// don't interfere with each other
don't interfere with each other
don ' t interfere with each other
@Test
    public void replaceReplace() throws Throwable {
        FragmentTestUtil.setContentView(mActivityRule, R.layout.double_container);
        ViewGroup container1 = (ViewGroup)
                mActivityRule.getActivity().findViewById(R.id.fragmentContainer1);
        ViewGroup container2 = (ViewGroup)
                mActivityRule.getActivity().findViewById(R.id.fragmentContainer2);
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        final StrictViewFragment fragment1 = new StrictViewFragment();
        final StrictViewFragment fragment2 = new StrictViewFragment();
        final StrictViewFragment fragment3 = new StrictViewFragment();
        final StrictViewFragment fragment4 = new StrictViewFragment();
        final StrictViewFragment fragment5 = new StrictViewFragment();
        fm.beginTransaction()
                .add(R.id.fragmentContainer1, fragment1)
                .add(R.id.fragmentContainer2, fragment2)
                .replace(R.id.fragmentContainer1, fragment3)
                .replace(R.id.fragmentContainer2, fragment4)
                .replace(R.id.fragmentContainer1, fragment5)
                .addToBackStack(null)
                .commit();
        FragmentTestUtil.executePendingTransactions(mActivityRule);
        assertChildren(container1, fragment5);
        assertChildren(container2, fragment4);
        fm.popBackStack();
        FragmentTestUtil.executePendingTransactions(mActivityRule);
        assertChildren(container1);
        assertChildren(container2);
    }
@ Test public void replaceReplace ( ) throws Throwable { FragmentTestUtil . setContentView ( mActivityRule , R . layout . double_container ) ; ViewGroup container1 = ( ViewGroup ) mActivityRule . getActivity ( ) . findViewById ( R . id . fragmentContainer1 ) ; ViewGroup container2 = ( ViewGroup ) mActivityRule . getActivity ( ) . findViewById ( R . id . fragmentContainer2 ) ; final FragmentManager fm = mActivityRule . getActivity ( ) . getSupportFragmentManager ( ) ; final StrictViewFragment fragment1 = new StrictViewFragment ( ) ; final StrictViewFragment fragment2 = new StrictViewFragment ( ) ; final StrictViewFragment fragment3 = new StrictViewFragment ( ) ; final StrictViewFragment fragment4 = new StrictViewFragment ( ) ; final StrictViewFragment fragment5 = new StrictViewFragment ( ) ; fm . beginTransaction ( ) . add ( R . id . fragmentContainer1 , fragment1 ) . add ( R . id . fragmentContainer2 , fragment2 ) . replace ( R . id . fragmentContainer1 , fragment3 ) . replace ( R . id . fragmentContainer2 , fragment4 ) . replace ( R . id . fragmentContainer1 , fragment5 ) . addToBackStack ( null ) . commit ( ) ; FragmentTestUtil . executePendingTransactions ( mActivityRule ) ; assertChildren ( container1 , fragment5 ) ; assertChildren ( container2 , fragment4 ) ; fm . popBackStack ( ) ; FragmentTestUtil . executePendingTransactions ( mActivityRule ) ; assertChildren ( container1 ) ; assertChildren ( container2 ) ; }
don't interfere with each other
don ' t interfere with each other