fragment/src/androidTest/java/androidx/fragment/app/FragmentTransitionTest.java
@Test
    public void crossContainer() throws Throwable {
        FragmentTestUtil.setContentView(mActivityRule, R.layout.double_container);
        TransitionFragment fragment1 = new TransitionFragment();
        fragment1.setLayoutId(R.layout.scene1);
        TransitionFragment fragment2 = new TransitionFragment();
        fragment2.setLayoutId(R.layout.scene1);
        mFragmentManager.beginTransaction()
                .setReorderingAllowed(mReorderingAllowed)
                .add(R.id.fragmentContainer1, fragment1)
                .add(R.id.fragmentContainer2, fragment2)
                .addToBackStack(null)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);
        assertEquals(1, mOnBackStackChangedTimes);

        fragment1.waitForTransition();
        final View greenSquare1 = findViewById(fragment1, R.id.greenSquare);
        final View blueSquare1 = findViewById(fragment1, R.id.blueSquare);
        verifyAndClearTransition(fragment1.enterTransition, null, greenSquare1, blueSquare1);
        verifyNoOtherTransitions(fragment1);
        fragment2.waitForTransition();
        final View greenSquare2 = findViewById(fragment2, R.id.greenSquare);
        final View blueSquare2 = findViewById(fragment2, R.id.blueSquare);
        verifyAndClearTransition(fragment2.enterTransition, null, greenSquare2, blueSquare2);
        verifyNoOtherTransitions(fragment2);

        // Make sure the correct transitions are run when the target names
        // are different in both shared elements. We may fool the system.
        verifyCrossTransition(false, fragment1, fragment2);

        // Make sure the correct transitions are run when the source names
        // are different in both shared elements. We may fool the system.
        verifyCrossTransition(true, fragment1, fragment2);
    }
// Make sure that shared elements on two different fragment containers don't interact
Make sure that shared elements on two different fragment containers don't interact
Make sure that shared elements on two different fragment containers don ' t interact
@Test
    public void crossContainer() throws Throwable {
        FragmentTestUtil.setContentView(mActivityRule, R.layout.double_container);
        TransitionFragment fragment1 = new TransitionFragment();
        fragment1.setLayoutId(R.layout.scene1);
        TransitionFragment fragment2 = new TransitionFragment();
        fragment2.setLayoutId(R.layout.scene1);
        mFragmentManager.beginTransaction()
                .setReorderingAllowed(mReorderingAllowed)
                .add(R.id.fragmentContainer1, fragment1)
                .add(R.id.fragmentContainer2, fragment2)
                .addToBackStack(null)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);
        assertEquals(1, mOnBackStackChangedTimes);
        fragment1.waitForTransition();
        final View greenSquare1 = findViewById(fragment1, R.id.greenSquare);
        final View blueSquare1 = findViewById(fragment1, R.id.blueSquare);
        verifyAndClearTransition(fragment1.enterTransition, null, greenSquare1, blueSquare1);
        verifyNoOtherTransitions(fragment1);
        fragment2.waitForTransition();
        final View greenSquare2 = findViewById(fragment2, R.id.greenSquare);
        final View blueSquare2 = findViewById(fragment2, R.id.blueSquare);
        verifyAndClearTransition(fragment2.enterTransition, null, greenSquare2, blueSquare2);
        verifyNoOtherTransitions(fragment2);
        verifyCrossTransition(false, fragment1, fragment2);
        verifyCrossTransition(true, fragment1, fragment2);
    }
@ Test public void crossContainer ( ) throws Throwable { FragmentTestUtil . setContentView ( mActivityRule , R . layout . double_container ) ; TransitionFragment fragment1 = new TransitionFragment ( ) ; fragment1 . setLayoutId ( R . layout . scene1 ) ; TransitionFragment fragment2 = new TransitionFragment ( ) ; fragment2 . setLayoutId ( R . layout . scene1 ) ; mFragmentManager . beginTransaction ( ) . setReorderingAllowed ( mReorderingAllowed ) . add ( R . id . fragmentContainer1 , fragment1 ) . add ( R . id . fragmentContainer2 , fragment2 ) . addToBackStack ( null ) . commit ( ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; assertEquals ( 1 , mOnBackStackChangedTimes ) ; fragment1 . waitForTransition ( ) ; final View greenSquare1 = findViewById ( fragment1 , R . id . greenSquare ) ; final View blueSquare1 = findViewById ( fragment1 , R . id . blueSquare ) ; verifyAndClearTransition ( fragment1 . enterTransition , null , greenSquare1 , blueSquare1 ) ; verifyNoOtherTransitions ( fragment1 ) ; fragment2 . waitForTransition ( ) ; final View greenSquare2 = findViewById ( fragment2 , R . id . greenSquare ) ; final View blueSquare2 = findViewById ( fragment2 , R . id . blueSquare ) ; verifyAndClearTransition ( fragment2 . enterTransition , null , greenSquare2 , blueSquare2 ) ; verifyNoOtherTransitions ( fragment2 ) ; verifyCrossTransition ( false , fragment1 , fragment2 ) ; verifyCrossTransition ( true , fragment1 , fragment2 ) ; }
Make sure that shared elements on two different fragment containers don't interact
Make sure that shared elements on two different fragment containers don ' t interact
// Make sure the correct transitions are run when the target names // are different in both shared elements. We may fool the system. // Make sure the correct transitions are run when the source names // are different in both shared elements. We may fool the system.