fragment/src/androidTest/java/androidx/fragment/app/FragmentViewTests.java
@Test
    public void addRemoveAdd() throws Throwable {
        FragmentTestUtil.setContentView(mActivityRule, R.layout.simple_container);
        ViewGroup container = (ViewGroup)
                mActivityRule.getActivity().findViewById(R.id.fragmentContainer);
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        final StrictViewFragment fragment = new StrictViewFragment();
        fm.beginTransaction()
                .add(R.id.fragmentContainer, fragment)
                .remove(fragment)
                .add(R.id.fragmentContainer, fragment)
                .addToBackStack(null)
                .commit();
        FragmentTestUtil.executePendingTransactions(mActivityRule);
        FragmentTestUtil.assertChildren(container, fragment);

        fm.popBackStack();
        FragmentTestUtil.executePendingTransactions(mActivityRule);
        FragmentTestUtil.assertChildren(container);
    }
// add the same fragment in one transaction.
add the same fragment in one transaction.
add the same fragment in one transaction .
@Test
    public void addRemoveAdd() throws Throwable {
        FragmentTestUtil.setContentView(mActivityRule, R.layout.simple_container);
        ViewGroup container = (ViewGroup)
                mActivityRule.getActivity().findViewById(R.id.fragmentContainer);
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        final StrictViewFragment fragment = new StrictViewFragment();
        fm.beginTransaction()
                .add(R.id.fragmentContainer, fragment)
                .remove(fragment)
                .add(R.id.fragmentContainer, fragment)
                .addToBackStack(null)
                .commit();
        FragmentTestUtil.executePendingTransactions(mActivityRule);
        FragmentTestUtil.assertChildren(container, fragment);
        fm.popBackStack();
        FragmentTestUtil.executePendingTransactions(mActivityRule);
        FragmentTestUtil.assertChildren(container);
    }
@ Test public void addRemoveAdd ( ) throws Throwable { FragmentTestUtil . setContentView ( mActivityRule , R . layout . simple_container ) ; ViewGroup container = ( ViewGroup ) mActivityRule . getActivity ( ) . findViewById ( R . id . fragmentContainer ) ; final FragmentManager fm = mActivityRule . getActivity ( ) . getSupportFragmentManager ( ) ; final StrictViewFragment fragment = new StrictViewFragment ( ) ; fm . beginTransaction ( ) . add ( R . id . fragmentContainer , fragment ) . remove ( fragment ) . add ( R . id . fragmentContainer , fragment ) . addToBackStack ( null ) . commit ( ) ; FragmentTestUtil . executePendingTransactions ( mActivityRule ) ; FragmentTestUtil . assertChildren ( container , fragment ) ; fm . popBackStack ( ) ; FragmentTestUtil . executePendingTransactions ( mActivityRule ) ; FragmentTestUtil . assertChildren ( container ) ; }
add the same fragment in one transaction.
add the same fragment in one transaction .