fragment/src/androidTest/java/androidx/fragment/app/FragmentTransitionTest.java
@Test
    public void attachDetachTransition() throws Throwable {
        TransitionFragment fragment1 = setupInitialFragment();
        TransitionFragment fragment2 = new TransitionFragment();
        fragment2.setLayoutId(R.layout.scene2);

        final View startBlue = findBlue();
        final View startGreen = findGreen();

        mFragmentManager.beginTransaction()
                .setReorderingAllowed(mReorderingAllowed)
                .add(R.id.fragmentContainer, fragment2)
                .detach(fragment1)
                .addToBackStack(null)
                .commit();

        FragmentTestUtil.waitForExecution(mActivityRule);

        final View endGreen = findViewById(fragment2, R.id.greenSquare);
        final View endBlue = findViewById(fragment2, R.id.blueSquare);

        verifyAndClearTransition(fragment1.exitTransition, null, startGreen, startBlue);
        verifyNoOtherTransitions(fragment1);

        verifyAndClearTransition(fragment2.enterTransition, null, endGreen, endBlue);
        verifyNoOtherTransitions(fragment2);

        FragmentTestUtil.popBackStackImmediate(mActivityRule);

        FragmentTestUtil.waitForExecution(mActivityRule);

        final View reenterBlue = findBlue();
        final View reenterGreen = findGreen();

        verifyAndClearTransition(fragment1.reenterTransition, null, reenterGreen, reenterBlue);
        verifyNoOtherTransitions(fragment1);

        verifyAndClearTransition(fragment2.returnTransition, null, endGreen, endBlue);
        verifyNoOtherTransitions(fragment2);
    }
// Ensure that transitions are done when a fragment is attached and detached
Ensure that transitions are done when a fragment is attached and detached
Ensure that transitions are done when a fragment is attached and detached
@Test
    public void attachDetachTransition() throws Throwable {
        TransitionFragment fragment1 = setupInitialFragment();
        TransitionFragment fragment2 = new TransitionFragment();
        fragment2.setLayoutId(R.layout.scene2);
        final View startBlue = findBlue();
        final View startGreen = findGreen();
        mFragmentManager.beginTransaction()
                .setReorderingAllowed(mReorderingAllowed)
                .add(R.id.fragmentContainer, fragment2)
                .detach(fragment1)
                .addToBackStack(null)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);
        final View endGreen = findViewById(fragment2, R.id.greenSquare);
        final View endBlue = findViewById(fragment2, R.id.blueSquare);
        verifyAndClearTransition(fragment1.exitTransition, null, startGreen, startBlue);
        verifyNoOtherTransitions(fragment1);
        verifyAndClearTransition(fragment2.enterTransition, null, endGreen, endBlue);
        verifyNoOtherTransitions(fragment2);
        FragmentTestUtil.popBackStackImmediate(mActivityRule);
        FragmentTestUtil.waitForExecution(mActivityRule);
        final View reenterBlue = findBlue();
        final View reenterGreen = findGreen();
        verifyAndClearTransition(fragment1.reenterTransition, null, reenterGreen, reenterBlue);
        verifyNoOtherTransitions(fragment1);
        verifyAndClearTransition(fragment2.returnTransition, null, endGreen, endBlue);
        verifyNoOtherTransitions(fragment2);
    }
@ Test public void attachDetachTransition ( ) throws Throwable { TransitionFragment fragment1 = setupInitialFragment ( ) ; TransitionFragment fragment2 = new TransitionFragment ( ) ; fragment2 . setLayoutId ( R . layout . scene2 ) ; final View startBlue = findBlue ( ) ; final View startGreen = findGreen ( ) ; mFragmentManager . beginTransaction ( ) . setReorderingAllowed ( mReorderingAllowed ) . add ( R . id . fragmentContainer , fragment2 ) . detach ( fragment1 ) . addToBackStack ( null ) . commit ( ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; final View endGreen = findViewById ( fragment2 , R . id . greenSquare ) ; final View endBlue = findViewById ( fragment2 , R . id . blueSquare ) ; verifyAndClearTransition ( fragment1 . exitTransition , null , startGreen , startBlue ) ; verifyNoOtherTransitions ( fragment1 ) ; verifyAndClearTransition ( fragment2 . enterTransition , null , endGreen , endBlue ) ; verifyNoOtherTransitions ( fragment2 ) ; FragmentTestUtil . popBackStackImmediate ( mActivityRule ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; final View reenterBlue = findBlue ( ) ; final View reenterGreen = findGreen ( ) ; verifyAndClearTransition ( fragment1 . reenterTransition , null , reenterGreen , reenterBlue ) ; verifyNoOtherTransitions ( fragment1 ) ; verifyAndClearTransition ( fragment2 . returnTransition , null , endGreen , endBlue ) ; verifyNoOtherTransitions ( fragment2 ) ; }
Ensure that transitions are done when a fragment is attached and detached
Ensure that transitions are done when a fragment is attached and detached