diff options
| author | 2023-07-11 15:52:26 +0000 | |
|---|---|---|
| committer | 2023-07-11 15:52:26 +0000 | |
| commit | eab59deb1d8b6df53c4272536b9f8eafaa19ae85 (patch) | |
| tree | b2220fda3ca1203d4af525d449366e238300e990 /java/tests | |
| parent | 42802669f7278a7120d3acb7c746917b4a54fefb (diff) | |
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
Diffstat (limited to 'java/tests')
| -rw-r--r-- | java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java | 52 |
1 files changed, 17 insertions, 35 deletions
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<ResolvedComponentInfo> 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<ResolvedComponentInfo> 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<ResolvedComponentInfo> 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<Pair<ShortcutLoader, Consumer<ShortcutLoader.Result>>> |