From 167c65e1a3dc527036a1cbf517989b747cc76614 Mon Sep 17 00:00:00 2001 From: Andrey Epin Date: Fri, 2 Dec 2022 15:17:20 -0800 Subject: Fix flakey unit test The test sometime failed locally apparently due to concurrency with shortcut loading logic. Test: the test itself Change-Id: I2bd3bc5df194814dfca021b2010d863a375deb7c --- .../intentresolver/UnbundledChooserActivityTest.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'java') diff --git a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java index da72a749..81a5897d 100644 --- a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java +++ b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java @@ -46,6 +46,7 @@ import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; @@ -774,7 +775,7 @@ public class UnbundledChooserActivityTest { } @Test - public void copyTextToClipboardLogging() throws Exception { + public void copyTextToClipboardLogging() { Intent sendIntent = createSendTextIntent(); List resolvedComponentInfos = createResolvedComponentsForTest(2); @@ -796,12 +797,16 @@ public class UnbundledChooserActivityTest { verify(mockLogger, atLeastOnce()).write(logMakerCaptor.capture()); // The last captured event is the selection of the target. - assertThat(logMakerCaptor.getValue().getCategory(), - is(MetricsEvent.ACTION_ACTIVITY_CHOOSER_PICKED_SYSTEM_TARGET)); + boolean containsTargetEvent = logMakerCaptor.getAllValues() + .stream() + .anyMatch(item -> + item.getCategory() + == MetricsEvent.ACTION_ACTIVITY_CHOOSER_PICKED_SYSTEM_TARGET); + assertTrue( + "ACTION_ACTIVITY_CHOOSER_PICKED_SYSTEM_TARGET is expected", containsTargetEvent); assertThat(logMakerCaptor.getValue().getSubtype(), is(1)); } - @Test @Ignore public void testNearbyShareLogging() throws Exception { -- cgit v1.2.3-59-g8ed1b