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

        final EndAnimationListenerFragment fragment1 = new EndAnimationListenerFragment();
        fm.beginTransaction()
                .add(R.id.fragmentContainer, fragment1)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);

        final EndAnimationListenerFragment fragment2 = new EndAnimationListenerFragment();

        fm.beginTransaction()
                .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out,
                        android.R.anim.fade_in, android.R.anim.fade_out)
                .replace(R.id.fragmentContainer, fragment2)
                .addToBackStack(null)
                .commit();

        FragmentTestUtil.waitForExecution(mActivityRule);

        assertTrue(fragment1.exitLatch.await(1, TimeUnit.SECONDS));
        assertTrue(fragment2.enterLatch.await(1, TimeUnit.SECONDS));

        mActivityRule.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                assertNotNull(fragment1.view);
                assertNotNull(fragment2.view);
                assertNull(fragment1.view.getParent());
            }
        });

        // Now pop the transaction
        FragmentTestUtil.popBackStackImmediate(mActivityRule);

        assertTrue(fragment2.exitLatch.await(1, TimeUnit.SECONDS));
        assertTrue(fragment1.enterLatch.await(1, TimeUnit.SECONDS));

        mActivityRule.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                assertNull(fragment2.view.getParent());
            }
        });
    }
// When a view is animated out, is parent should be null after the animation completes
When a view is animated out, is parent should be null after the animation completes
When a view is animated out is parent should be null after the animation completes
@Test
    public void parentNullAfterAnimation() throws Throwable {
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        final EndAnimationListenerFragment fragment1 = new EndAnimationListenerFragment();
        fm.beginTransaction()
                .add(R.id.fragmentContainer, fragment1)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);
        final EndAnimationListenerFragment fragment2 = new EndAnimationListenerFragment();
        fm.beginTransaction()
                .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out,
                        android.R.anim.fade_in, android.R.anim.fade_out)
                .replace(R.id.fragmentContainer, fragment2)
                .addToBackStack(null)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);
        assertTrue(fragment1.exitLatch.await(1, TimeUnit.SECONDS));
        assertTrue(fragment2.enterLatch.await(1, TimeUnit.SECONDS));
        mActivityRule.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                assertNotNull(fragment1.view);
                assertNotNull(fragment2.view);
                assertNull(fragment1.view.getParent());
            }
        });
        FragmentTestUtil.popBackStackImmediate(mActivityRule);
        assertTrue(fragment2.exitLatch.await(1, TimeUnit.SECONDS));
        assertTrue(fragment1.enterLatch.await(1, TimeUnit.SECONDS));
        mActivityRule.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                assertNull(fragment2.view.getParent());
            }
        });
    }
@ Test public void parentNullAfterAnimation ( ) throws Throwable { final FragmentManager fm = mActivityRule . getActivity ( ) . getSupportFragmentManager ( ) ; final EndAnimationListenerFragment fragment1 = new EndAnimationListenerFragment ( ) ; fm . beginTransaction ( ) . add ( R . id . fragmentContainer , fragment1 ) . commit ( ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; final EndAnimationListenerFragment fragment2 = new EndAnimationListenerFragment ( ) ; fm . beginTransaction ( ) . setCustomAnimations ( android . R . anim . fade_in , android . R . anim . fade_out , android . R . anim . fade_in , android . R . anim . fade_out ) . replace ( R . id . fragmentContainer , fragment2 ) . addToBackStack ( null ) . commit ( ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; assertTrue ( fragment1 . exitLatch . await ( 1 , TimeUnit . SECONDS ) ) ; assertTrue ( fragment2 . enterLatch . await ( 1 , TimeUnit . SECONDS ) ) ; mActivityRule . runOnUiThread ( new Runnable ( ) { @ Override public void run ( ) { assertNotNull ( fragment1 . view ) ; assertNotNull ( fragment2 . view ) ; assertNull ( fragment1 . view . getParent ( ) ) ; } } ) ; FragmentTestUtil . popBackStackImmediate ( mActivityRule ) ; assertTrue ( fragment2 . exitLatch . await ( 1 , TimeUnit . SECONDS ) ) ; assertTrue ( fragment1 . enterLatch . await ( 1 , TimeUnit . SECONDS ) ) ; mActivityRule . runOnUiThread ( new Runnable ( ) { @ Override public void run ( ) { assertNull ( fragment2 . view . getParent ( ) ) ; } } ) ; }
When a view is animated out, is parent should be null after the animation completes
When a view is animated out is parent should be null after the animation completes
// Now pop the transaction