fragment/src/androidTest/java/androidx/fragment/app/FragmentAnimationTest.java
@Test
    public void replaceAnimators() throws Throwable {
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();

        // One fragment with a view
        final AnimatorFragment fragment1 = new AnimatorFragment();
        final AnimatorFragment fragment2 = new AnimatorFragment();
        fm.beginTransaction()
                .add(R.id.fragmentContainer, fragment1, "1")
                .add(R.id.fragmentContainer, fragment2, "2")
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);

        final AnimatorFragment fragment3 = new AnimatorFragment();
        fm.beginTransaction()
                .setCustomAnimations(ENTER, EXIT, POP_ENTER, POP_EXIT)
                .replace(R.id.fragmentContainer, fragment3)
                .addToBackStack(null)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);

        assertFragmentAnimation(fragment1, 1, false, EXIT);
        assertFragmentAnimation(fragment2, 1, false, EXIT);
        assertFragmentAnimation(fragment3, 1, true, ENTER);

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

        assertFragmentAnimation(fragment3, 2, false, POP_EXIT);
        final AnimatorFragment replacement1 = (AnimatorFragment) fm.findFragmentByTag("1");
        final AnimatorFragment replacement2 = (AnimatorFragment) fm.findFragmentByTag("1");
        int expectedAnimations = replacement1 == fragment1 ? 2 : 1;
        assertFragmentAnimation(replacement1, expectedAnimations, true, POP_ENTER);
        assertFragmentAnimation(replacement2, expectedAnimations, true, POP_ENTER);
    }
// popping should popExit the removed fragment and popEnter the added fragments
popping should popExit the removed fragment and popEnter the added fragments
popping should popExit the removed fragment and popEnter the added fragments
@Test
    public void replaceAnimators() throws Throwable {
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        final AnimatorFragment fragment1 = new AnimatorFragment();
        final AnimatorFragment fragment2 = new AnimatorFragment();
        fm.beginTransaction()
                .add(R.id.fragmentContainer, fragment1, "1")
                .add(R.id.fragmentContainer, fragment2, "2")
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);
        final AnimatorFragment fragment3 = new AnimatorFragment();
        fm.beginTransaction()
                .setCustomAnimations(ENTER, EXIT, POP_ENTER, POP_EXIT)
                .replace(R.id.fragmentContainer, fragment3)
                .addToBackStack(null)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);
        assertFragmentAnimation(fragment1, 1, false, EXIT);
        assertFragmentAnimation(fragment2, 1, false, EXIT);
        assertFragmentAnimation(fragment3, 1, true, ENTER);
        fm.popBackStack();
        FragmentTestUtil.waitForExecution(mActivityRule);
        assertFragmentAnimation(fragment3, 2, false, POP_EXIT);
        final AnimatorFragment replacement1 = (AnimatorFragment) fm.findFragmentByTag("1");
        final AnimatorFragment replacement2 = (AnimatorFragment) fm.findFragmentByTag("1");
        int expectedAnimations = replacement1 == fragment1 ? 2 : 1;
        assertFragmentAnimation(replacement1, expectedAnimations, true, POP_ENTER);
        assertFragmentAnimation(replacement2, expectedAnimations, true, POP_ENTER);
    }
@ Test public void replaceAnimators ( ) throws Throwable { final FragmentManager fm = mActivityRule . getActivity ( ) . getSupportFragmentManager ( ) ; final AnimatorFragment fragment1 = new AnimatorFragment ( ) ; final AnimatorFragment fragment2 = new AnimatorFragment ( ) ; fm . beginTransaction ( ) . add ( R . id . fragmentContainer , fragment1 , "1" ) . add ( R . id . fragmentContainer , fragment2 , "2" ) . commit ( ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; final AnimatorFragment fragment3 = new AnimatorFragment ( ) ; fm . beginTransaction ( ) . setCustomAnimations ( ENTER , EXIT , POP_ENTER , POP_EXIT ) . replace ( R . id . fragmentContainer , fragment3 ) . addToBackStack ( null ) . commit ( ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; assertFragmentAnimation ( fragment1 , 1 , false , EXIT ) ; assertFragmentAnimation ( fragment2 , 1 , false , EXIT ) ; assertFragmentAnimation ( fragment3 , 1 , true , ENTER ) ; fm . popBackStack ( ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; assertFragmentAnimation ( fragment3 , 2 , false , POP_EXIT ) ; final AnimatorFragment replacement1 = ( AnimatorFragment ) fm . findFragmentByTag ( "1" ) ; final AnimatorFragment replacement2 = ( AnimatorFragment ) fm . findFragmentByTag ( "1" ) ; int expectedAnimations = replacement1 == fragment1 ? 2 : 1 ; assertFragmentAnimation ( replacement1 , expectedAnimations , true , POP_ENTER ) ; assertFragmentAnimation ( replacement2 , expectedAnimations , true , POP_ENTER ) ; }
popping should popExit the removed fragment and popEnter the added fragments
popping should popExit the removed fragment and popEnter the added fragments
// One fragment with a view