From eab59deb1d8b6df53c4272536b9f8eafaa19ae85 Mon Sep 17 00:00:00 2001 From: Matt Casey Date: Tue, 11 Jul 2023 15:52:26 +0000 Subject: Switch to doReturn notation for spy method mocking See bug for failure output and https://groups.google.com/g/mockito/c/9WUvkhZUy90 for relevant discussion. Test: atest IntentResolverUnitTests Bug: 290619420 Change-Id: I9c9b11e0e424f2eb658df8666071b9d9d97e5fed --- .../UnbundledChooserActivityTest.java | 52 +++++++--------------- 1 file changed, 17 insertions(+), 35 deletions(-) (limited to 'java/tests') diff --git a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java index 3ddd4394..8233f0db 100644 --- a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java +++ b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java @@ -52,6 +52,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -1466,14 +1467,10 @@ public class UnbundledChooserActivityTest { @Test public void testShortcutTargetWithApplyAppLimits() { // Set up resources - ChooserActivityOverrideData.getInstance().resources = Mockito.spy( + Resources resources = Mockito.spy( InstrumentationRegistry.getInstrumentation().getContext().getResources()); - when( - ChooserActivityOverrideData - .getInstance() - .resources - .getInteger(R.integer.config_maxShortcutTargetsPerApp)) - .thenReturn(1); + ChooserActivityOverrideData.getInstance().resources = resources; + doReturn(1).when(resources).getInteger(R.integer.config_maxShortcutTargetsPerApp); Intent sendIntent = createSendTextIntent(); // We need app targets for direct targets to get displayed List resolvedComponentInfos = createResolvedComponentsForTest(2); @@ -1541,14 +1538,10 @@ public class UnbundledChooserActivityTest { SystemUiDeviceConfigFlags.APPLY_SHARING_APP_LIMITS_IN_SYSUI, Boolean.toString(false)); // Set up resources - ChooserActivityOverrideData.getInstance().resources = Mockito.spy( + Resources resources = Mockito.spy( InstrumentationRegistry.getInstrumentation().getContext().getResources()); - when( - ChooserActivityOverrideData - .getInstance() - .resources - .getInteger(R.integer.config_maxShortcutTargetsPerApp)) - .thenReturn(1); + ChooserActivityOverrideData.getInstance().resources = resources; + doReturn(1).when(resources).getInteger(R.integer.config_maxShortcutTargetsPerApp); Intent sendIntent = createSendTextIntent(); // We need app targets for direct targets to get displayed List resolvedComponentInfos = createResolvedComponentsForTest(2); @@ -1620,14 +1613,10 @@ public class UnbundledChooserActivityTest { SystemUiDeviceConfigFlags.APPLY_SHARING_APP_LIMITS_IN_SYSUI, Boolean.toString(false)); // Set up resources - ChooserActivityOverrideData.getInstance().resources = Mockito.spy( + Resources resources = Mockito.spy( InstrumentationRegistry.getInstrumentation().getContext().getResources()); - when( - ChooserActivityOverrideData - .getInstance() - .resources - .getInteger(R.integer.config_maxShortcutTargetsPerApp)) - .thenReturn(1); + ChooserActivityOverrideData.getInstance().resources = resources; + doReturn(1).when(resources).getInteger(R.integer.config_maxShortcutTargetsPerApp); // We need app targets for direct targets to get displayed List resolvedComponentInfos = createResolvedComponentsForTest(2); @@ -1823,14 +1812,10 @@ public class UnbundledChooserActivityTest { .getResources().getConfiguration()); configuration.orientation = orientation; - ChooserActivityOverrideData.getInstance().resources = Mockito.spy( + Resources resources = Mockito.spy( InstrumentationRegistry.getInstrumentation().getContext().getResources()); - when( - ChooserActivityOverrideData - .getInstance() - .resources - .getConfiguration()) - .thenReturn(configuration); + ChooserActivityOverrideData.getInstance().resources = resources; + doReturn(configuration).when(resources).getConfiguration(); Intent sendIntent = createSendTextIntent(); // We need app targets for direct targets to get displayed @@ -2941,14 +2926,11 @@ public class UnbundledChooserActivityTest { } private void updateMaxTargetsPerRowResource(int targetsPerRow) { - ChooserActivityOverrideData.getInstance().resources = Mockito.spy( + Resources resources = Mockito.spy( InstrumentationRegistry.getInstrumentation().getContext().getResources()); - when( - ChooserActivityOverrideData - .getInstance() - .resources - .getInteger(R.integer.config_chooser_max_targets_per_row)) - .thenReturn(targetsPerRow); + ChooserActivityOverrideData.getInstance().resources = resources; + doReturn(targetsPerRow).when(resources).getInteger( + R.integer.config_chooser_max_targets_per_row); } private SparseArray>> -- cgit v1.2.3-59-g8ed1b