fragment/src/androidTest/java/androidx/fragment/app/FragmentTransitionTest.java
@Test
    public void sharedElementMismatch() throws Throwable {
        final TransitionFragment fragment1 = setupInitialFragment();

        // Now do a transition to scene2
        TransitionFragment fragment2 = new TransitionFragment();
        fragment2.setLayoutId(R.layout.scene2);

        final View startBlue = findBlue();
        final View startGreen = findGreen();
        final Rect startBlueBounds = getBoundsOnScreen(startBlue);

        mFragmentManager.beginTransaction()
                .addSharedElement(startBlue, "fooSquare")
                .replace(R.id.fragmentContainer, fragment2)
                .setReorderingAllowed(mReorderingAllowed)
                .addToBackStack(null)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);

        fragment1.waitForTransition();
        fragment2.waitForTransition();

        final View endBlue = findBlue();
        final View endGreen = findGreen();

        if (mReorderingAllowed) {
            verifyAndClearTransition(fragment1.exitTransition, null, startGreen, startBlue);
        } else {
            verifyAndClearTransition(fragment1.exitTransition, startBlueBounds, startGreen);
            verifyAndClearTransition(fragment2.sharedElementEnter, startBlueBounds, startBlue);
        }
        verifyNoOtherTransitions(fragment1);

        verifyAndClearTransition(fragment2.enterTransition, null, endGreen, endBlue);
        verifyNoOtherTransitions(fragment2);
    }
// Ensure that shared element without matching transition name doesn't error out
Ensure that shared element without matching transition name doesn't error out
Ensure that shared element without matching transition name doesn ' t error out
@Test
    public void sharedElementMismatch() throws Throwable {
        final TransitionFragment fragment1 = setupInitialFragment();
        TransitionFragment fragment2 = new TransitionFragment();
        fragment2.setLayoutId(R.layout.scene2);
        final View startBlue = findBlue();
        final View startGreen = findGreen();
        final Rect startBlueBounds = getBoundsOnScreen(startBlue);
        mFragmentManager.beginTransaction()
                .addSharedElement(startBlue, "fooSquare")
                .replace(R.id.fragmentContainer, fragment2)
                .setReorderingAllowed(mReorderingAllowed)
                .addToBackStack(null)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);
        fragment1.waitForTransition();
        fragment2.waitForTransition();
        final View endBlue = findBlue();
        final View endGreen = findGreen();
        if (mReorderingAllowed) {
            verifyAndClearTransition(fragment1.exitTransition, null, startGreen, startBlue);
        } else {
            verifyAndClearTransition(fragment1.exitTransition, startBlueBounds, startGreen);
            verifyAndClearTransition(fragment2.sharedElementEnter, startBlueBounds, startBlue);
        }
        verifyNoOtherTransitions(fragment1);
        verifyAndClearTransition(fragment2.enterTransition, null, endGreen, endBlue);
        verifyNoOtherTransitions(fragment2);
    }
@ Test public void sharedElementMismatch ( ) throws Throwable { final TransitionFragment fragment1 = setupInitialFragment ( ) ; TransitionFragment fragment2 = new TransitionFragment ( ) ; fragment2 . setLayoutId ( R . layout . scene2 ) ; final View startBlue = findBlue ( ) ; final View startGreen = findGreen ( ) ; final Rect startBlueBounds = getBoundsOnScreen ( startBlue ) ; mFragmentManager . beginTransaction ( ) . addSharedElement ( startBlue , "fooSquare" ) . replace ( R . id . fragmentContainer , fragment2 ) . setReorderingAllowed ( mReorderingAllowed ) . addToBackStack ( null ) . commit ( ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; fragment1 . waitForTransition ( ) ; fragment2 . waitForTransition ( ) ; final View endBlue = findBlue ( ) ; final View endGreen = findGreen ( ) ; if ( mReorderingAllowed ) { verifyAndClearTransition ( fragment1 . exitTransition , null , startGreen , startBlue ) ; } else { verifyAndClearTransition ( fragment1 . exitTransition , startBlueBounds , startGreen ) ; verifyAndClearTransition ( fragment2 . sharedElementEnter , startBlueBounds , startBlue ) ; } verifyNoOtherTransitions ( fragment1 ) ; verifyAndClearTransition ( fragment2 . enterTransition , null , endGreen , endBlue ) ; verifyNoOtherTransitions ( fragment2 ) ; }
Ensure that shared element without matching transition name doesn't error out
Ensure that shared element without matching transition name doesn ' t error out
// Now do a transition to scene2