OSDN Git Service

Fix broken unit tests due to mockito upgrade.
authorMakoto Onuki <omakoto@google.com>
Thu, 30 Mar 2017 21:17:35 +0000 (14:17 -0700)
committerMakoto Onuki <omakoto@google.com>
Thu, 30 Mar 2017 22:42:01 +0000 (15:42 -0700)
Bug 36781317

Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest1 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest2 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest3 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest4 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest5 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest6 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest7 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest8 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest9 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest10 -w com.android.frameworks.servicestests

Change-Id: Ie9abcd8bdf5353c96ebade0e8489f667ef9904ee

services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java
services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java
services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest8.java
services/tests/shortcutmanagerutils/src/com/android/server/pm/shortcutmanagertest/ShortcutManagerTestUtils.java

index b410400..7c37027 100644 (file)
@@ -15,6 +15,8 @@
  */
 package com.android.server.pm;
 
+import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.anyOrNull;
+import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.anyStringOrNull;
 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.cloneShortcutList;
 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.hashSet;
 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.list;
@@ -884,7 +886,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
                     entryName = ShortcutInfo.getResourceEntryName(entryName);
                 }
                 return Integer.parseInt(entryName.substring(1)) + ressIdOffset;
-            }).when(res).getIdentifier(anyString(), anyString(), anyString());
+            }).when(res).getIdentifier(anyStringOrNull(), anyStringOrNull(), anyStringOrNull());
             return res;
         }).when(mMockPackageManager).getResourcesForApplicationAsUser(anyString(), anyInt());
     }
@@ -1612,7 +1614,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
                 eq(packageName),
                 eq(userId),
                 intentsCaptor.capture(),
-                any(Bundle.class));
+                anyOrNull(Bundle.class));
         return intentsCaptor.getValue();
     }
 
@@ -1671,7 +1673,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
                 anyString(),
                 anyInt(),
                 any(Intent[].class),
-                any(Bundle.class));
+                anyOrNull(Bundle.class));
     }
 
     protected void assertStartShortcutThrowsException(@NonNull String packageName,
index 4b3c2f8..796cc16 100644 (file)
@@ -15,6 +15,8 @@
  */
 package com.android.server.pm;
 
+import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.anyOrNull;
+import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.anyStringOrNull;
 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllChooser;
 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllDisabled;
 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllDynamic;
@@ -2832,7 +2834,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
             // Not launchable.
             doReturn(ActivityManager.START_CLASS_NOT_FOUND)
                     .when(mMockActivityManagerInternal).startActivitiesAsPackage(
-                            anyString(), anyInt(), any(Intent[].class), any(Bundle.class));
+                            anyStringOrNull(), anyInt(),
+                            anyOrNull(Intent[].class), anyOrNull(Bundle.class));
             assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_0,
                     ActivityNotFoundException.class);
 
@@ -2840,7 +2843,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
             doReturn(ActivityManager.START_CLASS_NOT_FOUND)
                     .when(mMockActivityManagerInternal)
                     .startActivitiesAsPackage(
-                            anyString(), anyInt(), any(Intent[].class), any(Bundle.class));
+                            anyStringOrNull(), anyInt(),
+                            anyOrNull(Intent[].class), anyOrNull(Bundle.class));
             assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_0,
                     ActivityNotFoundException.class);
         });
index 0310e16..e9a329c 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.android.server.pm;
 
+import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.anyOrNull;
 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertExpectException;
 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertForLauncherCallbackNoThrow;
 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertWith;
@@ -775,7 +776,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
                     /* resultIntent=*/ null));
 
             // The intent should be sent right away.
-            verify(mServiceContext, times(1)).sendIntentSender(any(IntentSender.class));
+            verify(mServiceContext, times(1)).sendIntentSender(anyOrNull(IntentSender.class));
         });
     }
 
index f2bae4c..132ed98 100644 (file)
@@ -58,6 +58,8 @@ import org.hamcrest.Matcher;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mockito.ArgumentCaptor;
+import org.mockito.ArgumentMatcher;
+import org.mockito.ArgumentMatchers;
 import org.mockito.Mockito;
 import org.mockito.hamcrest.MockitoHamcrest;
 
@@ -733,6 +735,14 @@ public class ShortcutManagerTestUtils {
         fail("Timed out for: " + message);
     }
 
+    public static final <T> T anyOrNull(Class<T> clazz) {
+        return ArgumentMatchers.argThat(value -> true);
+    }
+
+    public static final String anyStringOrNull() {
+        return ArgumentMatchers.argThat(value -> true);
+    }
+
     public static ShortcutListAsserter assertWith(List<ShortcutInfo> list) {
         return new ShortcutListAsserter(list);
     }