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

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

        SharedElementCallback enterCallback = mock(SharedElementCallback.class);
        fragment2.setEnterSharedElementCallback(enterCallback);

        final View startBlue = findBlue();

        verifyTransition(fragment1, fragment2, "blueSquare");

        ArgumentCaptor<List> names = ArgumentCaptor.forClass(List.class);
        ArgumentCaptor<List> views = ArgumentCaptor.forClass(List.class);
        ArgumentCaptor<List> snapshots = ArgumentCaptor.forClass(List.class);
        verify(enterCallback).onSharedElementStart(names.capture(), views.capture(),
                snapshots.capture());
        assertEquals(1, names.getValue().size());
        assertEquals(1, views.getValue().size());
        assertNull(snapshots.getValue());
        assertEquals("blueSquare", names.getValue().get(0));
        assertEquals(startBlue, views.getValue().get(0));

        final View endBlue = findBlue();

        verify(enterCallback).onSharedElementEnd(names.capture(), views.capture(),
                snapshots.capture());
        assertEquals(1, names.getValue().size());
        assertEquals(1, views.getValue().size());
        assertNull(snapshots.getValue());
        assertEquals("blueSquare", names.getValue().get(0));
        assertEquals(endBlue, views.getValue().get(0));

        // Now pop the back stack
        reset(enterCallback);
        verifyPopTransition(1, fragment2, fragment1);

        verify(enterCallback).onSharedElementStart(names.capture(), views.capture(),
                snapshots.capture());
        assertEquals(1, names.getValue().size());
        assertEquals(1, views.getValue().size());
        assertNull(snapshots.getValue());
        assertEquals("blueSquare", names.getValue().get(0));
        assertEquals(endBlue, views.getValue().get(0));

        final View reenterBlue = findBlue();

        verify(enterCallback).onSharedElementEnd(names.capture(), views.capture(),
                snapshots.capture());
        assertEquals(1, names.getValue().size());
        assertEquals(1, views.getValue().size());
        assertNull(snapshots.getValue());
        assertEquals("blueSquare", names.getValue().get(0));
        assertEquals(reenterBlue, views.getValue().get(0));
    }
// Make sure that onSharedElementStart and onSharedElementEnd are called
Make sure that onSharedElementStart and onSharedElementEnd are called
Make sure that onSharedElementStart and onSharedElementEnd are called
@Test
    public void callStartEndWithSharedElements() throws Throwable {
        TransitionFragment fragment1 = setupInitialFragment();
        TransitionFragment fragment2 = new TransitionFragment();
        fragment2.setLayoutId(R.layout.scene2);
        SharedElementCallback enterCallback = mock(SharedElementCallback.class);
        fragment2.setEnterSharedElementCallback(enterCallback);
        final View startBlue = findBlue();
        verifyTransition(fragment1, fragment2, "blueSquare");
        ArgumentCaptor<List> names = ArgumentCaptor.forClass(List.class);
        ArgumentCaptor<List> views = ArgumentCaptor.forClass(List.class);
        ArgumentCaptor<List> snapshots = ArgumentCaptor.forClass(List.class);
        verify(enterCallback).onSharedElementStart(names.capture(), views.capture(),
                snapshots.capture());
        assertEquals(1, names.getValue().size());
        assertEquals(1, views.getValue().size());
        assertNull(snapshots.getValue());
        assertEquals("blueSquare", names.getValue().get(0));
        assertEquals(startBlue, views.getValue().get(0));
        final View endBlue = findBlue();
        verify(enterCallback).onSharedElementEnd(names.capture(), views.capture(),
                snapshots.capture());
        assertEquals(1, names.getValue().size());
        assertEquals(1, views.getValue().size());
        assertNull(snapshots.getValue());
        assertEquals("blueSquare", names.getValue().get(0));
        assertEquals(endBlue, views.getValue().get(0));
        reset(enterCallback);
        verifyPopTransition(1, fragment2, fragment1);
        verify(enterCallback).onSharedElementStart(names.capture(), views.capture(),
                snapshots.capture());
        assertEquals(1, names.getValue().size());
        assertEquals(1, views.getValue().size());
        assertNull(snapshots.getValue());
        assertEquals("blueSquare", names.getValue().get(0));
        assertEquals(endBlue, views.getValue().get(0));
        final View reenterBlue = findBlue();
        verify(enterCallback).onSharedElementEnd(names.capture(), views.capture(),
                snapshots.capture());
        assertEquals(1, names.getValue().size());
        assertEquals(1, views.getValue().size());
        assertNull(snapshots.getValue());
        assertEquals("blueSquare", names.getValue().get(0));
        assertEquals(reenterBlue, views.getValue().get(0));
    }
@ Test public void callStartEndWithSharedElements ( ) throws Throwable { TransitionFragment fragment1 = setupInitialFragment ( ) ; TransitionFragment fragment2 = new TransitionFragment ( ) ; fragment2 . setLayoutId ( R . layout . scene2 ) ; SharedElementCallback enterCallback = mock ( SharedElementCallback . class ) ; fragment2 . setEnterSharedElementCallback ( enterCallback ) ; final View startBlue = findBlue ( ) ; verifyTransition ( fragment1 , fragment2 , "blueSquare" ) ; ArgumentCaptor < List > names = ArgumentCaptor . forClass ( List . class ) ; ArgumentCaptor < List > views = ArgumentCaptor . forClass ( List . class ) ; ArgumentCaptor < List > snapshots = ArgumentCaptor . forClass ( List . class ) ; verify ( enterCallback ) . onSharedElementStart ( names . capture ( ) , views . capture ( ) , snapshots . capture ( ) ) ; assertEquals ( 1 , names . getValue ( ) . size ( ) ) ; assertEquals ( 1 , views . getValue ( ) . size ( ) ) ; assertNull ( snapshots . getValue ( ) ) ; assertEquals ( "blueSquare" , names . getValue ( ) . get ( 0 ) ) ; assertEquals ( startBlue , views . getValue ( ) . get ( 0 ) ) ; final View endBlue = findBlue ( ) ; verify ( enterCallback ) . onSharedElementEnd ( names . capture ( ) , views . capture ( ) , snapshots . capture ( ) ) ; assertEquals ( 1 , names . getValue ( ) . size ( ) ) ; assertEquals ( 1 , views . getValue ( ) . size ( ) ) ; assertNull ( snapshots . getValue ( ) ) ; assertEquals ( "blueSquare" , names . getValue ( ) . get ( 0 ) ) ; assertEquals ( endBlue , views . getValue ( ) . get ( 0 ) ) ; reset ( enterCallback ) ; verifyPopTransition ( 1 , fragment2 , fragment1 ) ; verify ( enterCallback ) . onSharedElementStart ( names . capture ( ) , views . capture ( ) , snapshots . capture ( ) ) ; assertEquals ( 1 , names . getValue ( ) . size ( ) ) ; assertEquals ( 1 , views . getValue ( ) . size ( ) ) ; assertNull ( snapshots . getValue ( ) ) ; assertEquals ( "blueSquare" , names . getValue ( ) . get ( 0 ) ) ; assertEquals ( endBlue , views . getValue ( ) . get ( 0 ) ) ; final View reenterBlue = findBlue ( ) ; verify ( enterCallback ) . onSharedElementEnd ( names . capture ( ) , views . capture ( ) , snapshots . capture ( ) ) ; assertEquals ( 1 , names . getValue ( ) . size ( ) ) ; assertEquals ( 1 , views . getValue ( ) . size ( ) ) ; assertNull ( snapshots . getValue ( ) ) ; assertEquals ( "blueSquare" , names . getValue ( ) . get ( 0 ) ) ; assertEquals ( reenterBlue , views . getValue ( ) . get ( 0 ) ) ; }
Make sure that onSharedElementStart and onSharedElementEnd are called
Make sure that onSharedElementStart and onSharedElementEnd are called
// Now do a transition to scene2 // Now pop the back stack