Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7221716 authored by jorgegil@google.com's avatar jorgegil@google.com
Browse files

Fix failing testOnPictureInPictureRequested

Fixes an issue where relying on a spy of ClientLifecyleManager caused
the test to fail with a TooManyActualInvocations error because
scheduleTransaction() was getting called more than once by mockito.
This change replaces the lifecyle manager spy with a mock.

Bug: 153709777
Test: atest WmTests:ActivityTaskManagerServiceTests
Change-Id: I5dfa780e28dabc4d634ef45667eb3688d07361b2
parent b86e5a77
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -89,13 +89,13 @@ public class ActivityTaskManagerServiceTests extends ActivityTestsBase {
    public void testOnPictureInPictureRequested() throws RemoteException {
        final ActivityStack stack = new StackBuilder(mRootWindowContainer).build();
        final ActivityRecord activity = stack.getBottomMostTask().getTopNonFinishingActivity();
        ClientLifecycleManager lifecycleManager = mService.getLifecycleManager();
        doNothing().when(lifecycleManager).scheduleTransaction(any());
        final ClientLifecycleManager mockLifecycleManager = mock(ClientLifecycleManager.class);
        doReturn(mockLifecycleManager).when(mService).getLifecycleManager();
        doReturn(true).when(activity).checkEnterPictureInPictureState(anyString(), anyBoolean());

        mService.requestPictureInPictureMode(activity.token);

        verify(lifecycleManager).scheduleTransaction(mClientTransactionCaptor.capture());
        verify(mockLifecycleManager).scheduleTransaction(mClientTransactionCaptor.capture());
        final ClientTransaction transaction = mClientTransactionCaptor.getValue();
        // Check that only an enter pip request item callback was scheduled.
        assertEquals(1, transaction.getCallbacks().size());