Switch to modern ArgumentMatchers
Test: - adb shell am instrument -w -e class com.android.mediaframeworktest.unit.MediaInserterTest com.android.mediaframeworktest/android.support.test.runner.AndroidJUnitRunner
- atest com.android.settingslib.users.AppRestrictionsHelperTest
- atest com.android.server.NetworkScorerAppManagerTest com.android.server.accessibility.MotionEventInjectorTest com.android.server.webkit.WebViewUpdateServiceTest
Change-Id: I6d4c543541d3bebcd65e5aa9e3f4d9a0152d5583
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java
index e628b68..fadb76d 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java
@@ -16,10 +16,18 @@
package com.android.mediaframeworktest.integration;
+import static android.hardware.camera2.CameraDevice.TEMPLATE_PREVIEW;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyLong;
+import static org.mockito.Mockito.argThat;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+
import android.graphics.ImageFormat;
import android.graphics.SurfaceTexture;
import android.hardware.ICameraService;
-import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CaptureRequest;
@@ -41,13 +49,10 @@
import android.util.Log;
import android.view.Surface;
-import static android.hardware.camera2.CameraDevice.TEMPLATE_PREVIEW;
-
import com.android.mediaframeworktest.MediaFrameworkIntegrationTestRunner;
import org.mockito.ArgumentCaptor;
-import org.mockito.compat.ArgumentMatcher;
-import static org.mockito.Mockito.*;
+import org.mockito.ArgumentMatcher;
public class CameraDeviceBinderTest extends AndroidTestCase {
private static String TAG = "CameraDeviceBinderTest";
@@ -166,10 +171,10 @@
}
}
- class IsMetadataNotEmpty extends ArgumentMatcher<CameraMetadataNative> {
+ class IsMetadataNotEmpty implements ArgumentMatcher<CameraMetadataNative> {
@Override
- public boolean matchesObject(Object obj) {
- return !((CameraMetadataNative) obj).isEmpty();
+ public boolean matches(CameraMetadataNative obj) {
+ return !obj.isEmpty();
}
}
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java
index 712039d..74bf1a2 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java
@@ -16,13 +16,13 @@
package com.android.mediaframeworktest.unit;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
import android.content.ContentProviderClient;
import android.content.ContentValues;
@@ -36,10 +36,9 @@
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
-import org.hamcrest.Description;
+import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.mockito.compat.ArgumentMatcher;
public class MediaInserterTest extends InstrumentationTestCase {
@@ -59,7 +58,7 @@
private static final Uri sImagesUri = Images.Media.getContentUri(sVolumeName);
private static final Uri sFilesUri = Files.getContentUri(sVolumeName);
- private static class MediaUriMatcher extends ArgumentMatcher<Uri> {
+ private static class MediaUriMatcher implements ArgumentMatcher<Uri> {
private final Uri mUri;
private MediaUriMatcher(Uri uri) {
@@ -67,15 +66,8 @@
}
@Override
- public boolean matchesObject(Object argument) {
- if (!(argument instanceof Uri)) {
- return false;
- }
-
- Uri actualUri = (Uri) argument;
- if (actualUri == mUri)
- return true;
- return false;
+ public boolean matches(Uri actualUri) {
+ return actualUri == mUri;
}
@Override
diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/users/AppRestrictionsHelperTest.java b/packages/SettingsLib/tests/integ/src/com/android/settingslib/users/AppRestrictionsHelperTest.java
index 820231e..b011c67 100644
--- a/packages/SettingsLib/tests/integ/src/com/android/settingslib/users/AppRestrictionsHelperTest.java
+++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/users/AppRestrictionsHelperTest.java
@@ -45,9 +45,9 @@
import android.view.inputmethod.InputMethodInfo;
import com.android.settingslib.BaseTest;
+import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.mockito.compat.ArgumentMatcher;
import java.util.ArrayList;
import java.util.List;
@@ -241,7 +241,7 @@
return ri;
}
- private class IntentMatcher extends ArgumentMatcher<Intent> {
+ private class IntentMatcher implements ArgumentMatcher<Intent> {
private final Intent mIntent;
IntentMatcher(Intent intent) {
@@ -249,11 +249,8 @@
}
@Override
- public boolean matchesObject(Object argument) {
- if (argument instanceof Intent) {
- return ((Intent) argument).filterEquals(mIntent);
- }
- return false;
+ public boolean matches(Intent argument) {
+ return argument != null && argument.filterEquals(mIntent);
}
@Override
diff --git a/services/tests/servicestests/src/com/android/server/NetworkScorerAppManagerTest.java b/services/tests/servicestests/src/com/android/server/NetworkScorerAppManagerTest.java
index 82ff0d8..6874624 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkScorerAppManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkScorerAppManagerTest.java
@@ -52,10 +52,10 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.mockito.compat.ArgumentMatcher;
import java.util.ArrayList;
import java.util.List;
@@ -82,13 +82,9 @@
MockitoAnnotations.initMocks(this);
mAvailableServices = new ArrayList<>();
when(mMockContext.getPackageManager()).thenReturn(mMockPm);
- when(mMockPm.queryIntentServices(Mockito.argThat(new ArgumentMatcher<Intent>() {
- @Override
- public boolean matchesObject(Object object) {
- Intent intent = (Intent) object;
- return NetworkScoreManager.ACTION_RECOMMEND_NETWORKS.equals(intent.getAction());
- }
- }), eq(PackageManager.GET_META_DATA))).thenReturn(mAvailableServices);
+ when(mMockPm.queryIntentServices(Mockito.argThat(
+ intent -> NetworkScoreManager.ACTION_RECOMMEND_NETWORKS.equals(intent.getAction())),
+ eq(PackageManager.GET_META_DATA))).thenReturn(mAvailableServices);
when(mMockContext.getResources()).thenReturn(mResources);
when(mMockContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager);
@@ -664,15 +660,10 @@
final int flags = PackageManager.GET_META_DATA;
when(mMockPm.resolveService(
- Mockito.argThat(new ArgumentMatcher<Intent>() {
- @Override
- public boolean matchesObject(Object object) {
- Intent intent = (Intent) object;
- return NetworkScoreManager.ACTION_RECOMMEND_NETWORKS
- .equals(intent.getAction())
- && compName.getPackageName().equals(intent.getPackage());
- }
- }), Mockito.eq(flags))).thenReturn(serviceInfo);
+ Mockito.argThat(intent -> NetworkScoreManager.ACTION_RECOMMEND_NETWORKS
+ .equals(intent.getAction())
+ && compName.getPackageName().equals(intent.getPackage())),
+ Mockito.eq(flags))).thenReturn(serviceInfo);
mAvailableServices.add(serviceInfo);
}
@@ -685,13 +676,9 @@
final int flags = 0;
when(mMockPm.resolveActivity(
- Mockito.argThat(new ArgumentMatcher<Intent>() {
- @Override
- public boolean matchesObject(Object object) {
- Intent intent = (Intent) object;
- return NetworkScoreManager.ACTION_CUSTOM_ENABLE.equals(intent.getAction())
- && useOpenWifiComp.getPackageName().equals(intent.getPackage());
- }
- }), Mockito.eq(flags))).thenReturn(resolveActivityInfo);
+ Mockito.argThat(intent ->
+ NetworkScoreManager.ACTION_CUSTOM_ENABLE.equals(intent.getAction())
+ && useOpenWifiComp.getPackageName().equals(intent.getPackage())),
+ Mockito.eq(flags))).thenReturn(resolveActivityInfo);
}
}
diff --git a/services/tests/servicestests/src/com/android/server/accessibility/MotionEventInjectorTest.java b/services/tests/servicestests/src/com/android/server/accessibility/MotionEventInjectorTest.java
index ec99a9a..fce5e3f 100644
--- a/services/tests/servicestests/src/com/android/server/accessibility/MotionEventInjectorTest.java
+++ b/services/tests/servicestests/src/com/android/server/accessibility/MotionEventInjectorTest.java
@@ -65,7 +65,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
-import org.mockito.compat.ArgumentMatcher;
/**
* Tests for MotionEventInjector
diff --git a/services/tests/servicestests/src/com/android/server/webkit/WebViewUpdateServiceTest.java b/services/tests/servicestests/src/com/android/server/webkit/WebViewUpdateServiceTest.java
index 05c4853..30e8449 100644
--- a/services/tests/servicestests/src/com/android/server/webkit/WebViewUpdateServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/webkit/WebViewUpdateServiceTest.java
@@ -38,9 +38,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatcher;
import org.mockito.Mockito;
import org.mockito.Matchers;
-import org.mockito.compat.ArgumentMatcher;
import java.lang.Integer;
import java.util.concurrent.CountDownLatch;
@@ -140,7 +140,7 @@
}
// For matching the package name of a PackageInfo
- private class IsPackageInfoWithName extends ArgumentMatcher<PackageInfo> {
+ private class IsPackageInfoWithName implements ArgumentMatcher<PackageInfo> {
private final String mPackageName;
IsPackageInfoWithName(String name) {
@@ -148,8 +148,8 @@
}
@Override
- public boolean matchesObject(Object p) {
- return ((PackageInfo) p).packageName.equals(mPackageName);
+ public boolean matches(PackageInfo p) {
+ return p.packageName.equals(mPackageName);
}
@Override