Merge "Switch to modern ArgumentMatchers"

am: 343c512834

Change-Id: I25f39cefde34f5a27a9abf5d97fe94dcbcfee3cd
This commit is contained in:
Philip P. Moltmann
2017-12-15 10:47:38 +00:00
committed by android-build-merger
6 changed files with 40 additions and 60 deletions

View File

@@ -16,10 +16,18 @@
package com.android.mediaframeworktest.integration; 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.ImageFormat;
import android.graphics.SurfaceTexture; import android.graphics.SurfaceTexture;
import android.hardware.ICameraService; import android.hardware.ICameraService;
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CameraCaptureSession; import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraCharacteristics; import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CaptureRequest; import android.hardware.camera2.CaptureRequest;
@@ -41,13 +49,10 @@ import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log; import android.util.Log;
import android.view.Surface; import android.view.Surface;
import static android.hardware.camera2.CameraDevice.TEMPLATE_PREVIEW;
import com.android.mediaframeworktest.MediaFrameworkIntegrationTestRunner; import com.android.mediaframeworktest.MediaFrameworkIntegrationTestRunner;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.compat.ArgumentMatcher; import org.mockito.ArgumentMatcher;
import static org.mockito.Mockito.*;
public class CameraDeviceBinderTest extends AndroidTestCase { public class CameraDeviceBinderTest extends AndroidTestCase {
private static String TAG = "CameraDeviceBinderTest"; private static String TAG = "CameraDeviceBinderTest";
@@ -166,10 +171,10 @@ public class CameraDeviceBinderTest extends AndroidTestCase {
} }
} }
class IsMetadataNotEmpty extends ArgumentMatcher<CameraMetadataNative> { class IsMetadataNotEmpty implements ArgumentMatcher<CameraMetadataNative> {
@Override @Override
public boolean matchesObject(Object obj) { public boolean matches(CameraMetadataNative obj) {
return !((CameraMetadataNative) obj).isEmpty(); return !obj.isEmpty();
} }
} }

View File

@@ -16,13 +16,13 @@
package com.android.mediaframeworktest.unit; 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.never;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; 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.ContentProviderClient;
import android.content.ContentValues; import android.content.ContentValues;
@@ -36,10 +36,9 @@ import android.provider.MediaStore.Video;
import android.test.InstrumentationTestCase; import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest;
import org.hamcrest.Description; import org.mockito.ArgumentMatcher;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.mockito.compat.ArgumentMatcher;
public class MediaInserterTest extends InstrumentationTestCase { public class MediaInserterTest extends InstrumentationTestCase {
@@ -59,7 +58,7 @@ public class MediaInserterTest extends InstrumentationTestCase {
private static final Uri sImagesUri = Images.Media.getContentUri(sVolumeName); private static final Uri sImagesUri = Images.Media.getContentUri(sVolumeName);
private static final Uri sFilesUri = Files.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 final Uri mUri;
private MediaUriMatcher(Uri uri) { private MediaUriMatcher(Uri uri) {
@@ -67,15 +66,8 @@ public class MediaInserterTest extends InstrumentationTestCase {
} }
@Override @Override
public boolean matchesObject(Object argument) { public boolean matches(Uri actualUri) {
if (!(argument instanceof Uri)) { return actualUri == mUri;
return false;
}
Uri actualUri = (Uri) argument;
if (actualUri == mUri)
return true;
return false;
} }
@Override @Override

View File

@@ -45,9 +45,9 @@ import android.test.suitebuilder.annotation.SmallTest;
import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodInfo;
import com.android.settingslib.BaseTest; import com.android.settingslib.BaseTest;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.mockito.compat.ArgumentMatcher;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -241,7 +241,7 @@ public class AppRestrictionsHelperTest extends BaseTest {
return ri; return ri;
} }
private class IntentMatcher extends ArgumentMatcher<Intent> { private class IntentMatcher implements ArgumentMatcher<Intent> {
private final Intent mIntent; private final Intent mIntent;
IntentMatcher(Intent intent) { IntentMatcher(Intent intent) {
@@ -249,11 +249,8 @@ public class AppRestrictionsHelperTest extends BaseTest {
} }
@Override @Override
public boolean matchesObject(Object argument) { public boolean matches(Intent argument) {
if (argument instanceof Intent) { return argument != null && argument.filterEquals(mIntent);
return ((Intent) argument).filterEquals(mIntent);
}
return false;
} }
@Override @Override

View File

@@ -52,10 +52,10 @@ import com.android.internal.R;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.mockito.compat.ArgumentMatcher;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -82,13 +82,9 @@ public class NetworkScorerAppManagerTest {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mAvailableServices = new ArrayList<>(); mAvailableServices = new ArrayList<>();
when(mMockContext.getPackageManager()).thenReturn(mMockPm); when(mMockContext.getPackageManager()).thenReturn(mMockPm);
when(mMockPm.queryIntentServices(Mockito.argThat(new ArgumentMatcher<Intent>() { when(mMockPm.queryIntentServices(Mockito.argThat(
@Override intent -> NetworkScoreManager.ACTION_RECOMMEND_NETWORKS.equals(intent.getAction())),
public boolean matchesObject(Object object) { eq(PackageManager.GET_META_DATA))).thenReturn(mAvailableServices);
Intent intent = (Intent) object;
return NetworkScoreManager.ACTION_RECOMMEND_NETWORKS.equals(intent.getAction());
}
}), eq(PackageManager.GET_META_DATA))).thenReturn(mAvailableServices);
when(mMockContext.getResources()).thenReturn(mResources); when(mMockContext.getResources()).thenReturn(mResources);
when(mMockContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager); when(mMockContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager);
@@ -664,15 +660,10 @@ public class NetworkScorerAppManagerTest {
final int flags = PackageManager.GET_META_DATA; final int flags = PackageManager.GET_META_DATA;
when(mMockPm.resolveService( when(mMockPm.resolveService(
Mockito.argThat(new ArgumentMatcher<Intent>() { Mockito.argThat(intent -> NetworkScoreManager.ACTION_RECOMMEND_NETWORKS
@Override .equals(intent.getAction())
public boolean matchesObject(Object object) { && compName.getPackageName().equals(intent.getPackage())),
Intent intent = (Intent) object; Mockito.eq(flags))).thenReturn(serviceInfo);
return NetworkScoreManager.ACTION_RECOMMEND_NETWORKS
.equals(intent.getAction())
&& compName.getPackageName().equals(intent.getPackage());
}
}), Mockito.eq(flags))).thenReturn(serviceInfo);
mAvailableServices.add(serviceInfo); mAvailableServices.add(serviceInfo);
} }
@@ -685,13 +676,9 @@ public class NetworkScorerAppManagerTest {
final int flags = 0; final int flags = 0;
when(mMockPm.resolveActivity( when(mMockPm.resolveActivity(
Mockito.argThat(new ArgumentMatcher<Intent>() { Mockito.argThat(intent ->
@Override NetworkScoreManager.ACTION_CUSTOM_ENABLE.equals(intent.getAction())
public boolean matchesObject(Object object) { && useOpenWifiComp.getPackageName().equals(intent.getPackage())),
Intent intent = (Intent) object; Mockito.eq(flags))).thenReturn(resolveActivityInfo);
return NetworkScoreManager.ACTION_CUSTOM_ENABLE.equals(intent.getAction())
&& useOpenWifiComp.getPackageName().equals(intent.getPackage());
}
}), Mockito.eq(flags))).thenReturn(resolveActivityInfo);
} }
} }

View File

@@ -65,7 +65,6 @@ import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.compat.ArgumentMatcher;
/** /**
* Tests for MotionEventInjector * Tests for MotionEventInjector

View File

@@ -38,9 +38,9 @@ import android.webkit.WebViewProviderResponse;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentMatcher;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.Matchers; import org.mockito.Matchers;
import org.mockito.compat.ArgumentMatcher;
import java.lang.Integer; import java.lang.Integer;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@@ -140,7 +140,7 @@ public class WebViewUpdateServiceTest {
} }
// For matching the package name of a PackageInfo // For matching the package name of a PackageInfo
private class IsPackageInfoWithName extends ArgumentMatcher<PackageInfo> { private class IsPackageInfoWithName implements ArgumentMatcher<PackageInfo> {
private final String mPackageName; private final String mPackageName;
IsPackageInfoWithName(String name) { IsPackageInfoWithName(String name) {
@@ -148,8 +148,8 @@ public class WebViewUpdateServiceTest {
} }
@Override @Override
public boolean matchesObject(Object p) { public boolean matches(PackageInfo p) {
return ((PackageInfo) p).packageName.equals(mPackageName); return p.packageName.equals(mPackageName);
} }
@Override @Override