From 2ed5207528e7df6a0827d1cbe4cc534325b6fb49 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Tue, 29 Jun 2021 17:48:25 -0700 Subject: [PATCH] Fix flaky/broken test I think relying on actual CommandQueue is where the flakiness is coming from so instead I'm calling the callback directly. Bug: 191264972 Bug: 192356466 Test: atest LaunchConversationActivityTest -c --iterations 20 Change-Id: I23dff9da2b86772a959f144a035b3e884489ea43 --- .../LaunchConversationActivityTest.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/widget/LaunchConversationActivityTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/widget/LaunchConversationActivityTest.java index f6264ffc6a701..d8ba164851ede 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/widget/LaunchConversationActivityTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/widget/LaunchConversationActivityTest.java @@ -49,7 +49,6 @@ import com.android.systemui.wmshell.BubblesManager; import com.android.wm.shell.bubbles.Bubble; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; @@ -92,20 +91,23 @@ public class LaunchConversationActivityTest extends SysuiTestCase { private NotificationListenerService.Ranking mRanking; @Mock private UserManager mUserManager; - + @Mock private CommandQueue mCommandQueue; @Captor private ArgumentCaptor mNotificationVisibilityCaptor; + @Captor + private ArgumentCaptor mCallbacksCaptor; private Intent mIntent; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - mCommandQueue = new CommandQueue(mContext); mActivity = new LaunchConversationActivity(mNotificationEntryManager, Optional.of(mBubblesManager), mUserManager, mCommandQueue); + verify(mCommandQueue, times(1)).addCallback(mCallbacksCaptor.capture()); + mActivity.setIsForTesting(true, mIStatusBarService); mIntent = new Intent(); mIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_TILE_ID, "tile ID"); @@ -169,7 +171,7 @@ public class LaunchConversationActivityTest extends SysuiTestCase { mActivity.onCreate(new Bundle()); assertThat(mActivity.isFinishing()).isTrue(); - mCommandQueue.appTransitionFinished(DEFAULT_DISPLAY); + mCallbacksCaptor.getValue().appTransitionFinished(DEFAULT_DISPLAY); verify(mIStatusBarService, times(1)).onNotificationClear(any(), anyInt(), any(), anyInt(), anyInt(), mNotificationVisibilityCaptor.capture()); @@ -183,17 +185,20 @@ public class LaunchConversationActivityTest extends SysuiTestCase { @Test public void testBubbleEntryOpensBubbleAndDoesNotClearNotification() throws Exception { + when(mBubblesManager.getBubbleWithShortcutId(any())).thenReturn(null); mIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_NOTIFICATION_KEY, NOTIF_KEY_CAN_BUBBLE); mActivity.setIntent(mIntent); mActivity.onCreate(new Bundle()); assertThat(mActivity.isFinishing()).isTrue(); - mCommandQueue.appTransitionFinished(DEFAULT_DISPLAY); + mCallbacksCaptor.getValue().appTransitionFinished(DEFAULT_DISPLAY); // Don't clear the notification for bubbles. verify(mIStatusBarService, never()).onNotificationClear(any(), anyInt(), any(), anyInt(), anyInt(), any()); + // Select the bubble. + verify(mBubblesManager, times(1)).getBubbleWithShortcutId(any()); verify(mBubblesManager, times(1)).expandStackAndSelectBubble(eq(mNotifEntryCanBubble)); } @@ -214,7 +219,7 @@ public class LaunchConversationActivityTest extends SysuiTestCase { verify(mBubblesManager, never()).expandStackAndSelectBubble(any(NotificationEntry.class)); } - @Ignore + @Test public void testBubbleWithNoNotifOpensBubble() throws Exception { Bubble bubble = mock(Bubble.class); @@ -226,7 +231,7 @@ public class LaunchConversationActivityTest extends SysuiTestCase { mActivity.onCreate(new Bundle()); assertThat(mActivity.isFinishing()).isTrue(); - mCommandQueue.appTransitionFinished(DEFAULT_DISPLAY); + mCallbacksCaptor.getValue().appTransitionFinished(DEFAULT_DISPLAY); verify(mBubblesManager, times(1)).expandStackAndSelectBubble(eq(bubble)); }