Refactor code incompatible with Mockito 2.7.13
(cherry picked from 76e319f015c2b43498ce3ce610a253d63e76cbf3) Some additional internal only refactorings were done as well. Bug: 32912773 Test: make checkbuild Change-Id: I96e3da967fad731fc8f39bde9db95f50ab7353fb
This commit is contained in:
@@ -45,8 +45,8 @@ import static android.hardware.camera2.CameraDevice.TEMPLATE_PREVIEW;
|
||||
|
||||
import com.android.mediaframeworktest.MediaFrameworkIntegrationTestRunner;
|
||||
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.compat.ArgumentMatcher;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class CameraDeviceBinderTest extends AndroidTestCase {
|
||||
@@ -168,7 +168,7 @@ public class CameraDeviceBinderTest extends AndroidTestCase {
|
||||
|
||||
class IsMetadataNotEmpty extends ArgumentMatcher<CameraMetadataNative> {
|
||||
@Override
|
||||
public boolean matches(Object obj) {
|
||||
public boolean matchesObject(Object obj) {
|
||||
return !((CameraMetadataNative) obj).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,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 {
|
||||
|
||||
@@ -67,7 +67,7 @@ public class MediaInserterTest extends InstrumentationTestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object argument) {
|
||||
public boolean matchesObject(Object argument) {
|
||||
if (!(argument instanceof Uri)) {
|
||||
return false;
|
||||
}
|
||||
@@ -79,13 +79,9 @@ public class MediaInserterTest extends InstrumentationTestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description
|
||||
.appendText("expected a TableUri '")
|
||||
.appendText(mUri.toString())
|
||||
.appendText("'");
|
||||
public String toString() {
|
||||
return "expected a TableUri '" + mUri.toString() + "'";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Uri eqUri(Uri in) {
|
||||
|
||||
@@ -44,10 +44,9 @@ import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import com.android.settingslib.BaseTest;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
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;
|
||||
@@ -249,7 +248,7 @@ public class AppRestrictionsHelperTest extends BaseTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object argument) {
|
||||
public boolean matchesObject(Object argument) {
|
||||
if (argument instanceof Intent) {
|
||||
return ((Intent) argument).filterEquals(mIntent);
|
||||
}
|
||||
@@ -257,8 +256,8 @@ public class AppRestrictionsHelperTest extends BaseTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("Expected: " + mIntent);
|
||||
public String toString() {
|
||||
return "Expected: " + mIntent;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -314,8 +314,8 @@ public class NetworkScoreServiceTest {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(EXTRA_RECOMMENDATION_RESULT, providerResult);
|
||||
doAnswer(invocation -> {
|
||||
bundle.putInt(EXTRA_SEQUENCE, invocation.getArgumentAt(2, int.class));
|
||||
invocation.getArgumentAt(1, IRemoteCallback.class).sendResult(bundle);
|
||||
bundle.putInt(EXTRA_SEQUENCE, invocation.getArgument(2));
|
||||
invocation.<IRemoteCallback>getArgument(1).sendResult(bundle);
|
||||
return null;
|
||||
}).when(mRecommendationProvider)
|
||||
.requestRecommendation(eq(mRecommendationRequest), isA(IRemoteCallback.class),
|
||||
@@ -379,7 +379,7 @@ public class NetworkScoreServiceTest {
|
||||
injectProvider();
|
||||
final Bundle bundle = new Bundle();
|
||||
doAnswer(invocation -> {
|
||||
invocation.getArgumentAt(1, IRemoteCallback.class).sendResult(bundle);
|
||||
invocation.<IRemoteCallback>getArgument(1).sendResult(bundle);
|
||||
return null;
|
||||
}).when(mRecommendationProvider)
|
||||
.requestRecommendation(eq(mRecommendationRequest), isA(IRemoteCallback.class),
|
||||
@@ -956,7 +956,7 @@ public class NetworkScoreServiceTest {
|
||||
IBinder mockBinder = mock(IBinder.class);
|
||||
when(mockBinder.queryLocalInterface(anyString()))
|
||||
.thenReturn(mRecommendationProvider);
|
||||
invocation.getArgumentAt(1, ServiceConnection.class)
|
||||
invocation.<ServiceConnection>getArgument(1)
|
||||
.onServiceConnected(NEW_SCORER.getRecommendationServiceComponent(),
|
||||
mockBinder);
|
||||
return true;
|
||||
|
||||
@@ -50,10 +50,10 @@ import com.android.internal.R;
|
||||
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;
|
||||
@@ -77,7 +77,7 @@ public class NetworkScorerAppManagerTest {
|
||||
when(mMockContext.getPackageManager()).thenReturn(mMockPm);
|
||||
when(mMockPm.queryIntentServices(Mockito.argThat(new ArgumentMatcher<Intent>() {
|
||||
@Override
|
||||
public boolean matches(Object object) {
|
||||
public boolean matchesObject(Object object) {
|
||||
Intent intent = (Intent) object;
|
||||
return NetworkScoreManager.ACTION_RECOMMEND_NETWORKS.equals(intent.getAction());
|
||||
}
|
||||
@@ -395,7 +395,7 @@ public class NetworkScorerAppManagerTest {
|
||||
when(mMockPm.resolveService(
|
||||
Mockito.argThat(new ArgumentMatcher<Intent>() {
|
||||
@Override
|
||||
public boolean matches(Object object) {
|
||||
public boolean matchesObject(Object object) {
|
||||
Intent intent = (Intent) object;
|
||||
return NetworkScoreManager.ACTION_RECOMMEND_NETWORKS
|
||||
.equals(intent.getAction())
|
||||
@@ -416,7 +416,7 @@ public class NetworkScorerAppManagerTest {
|
||||
when(mMockPm.resolveActivity(
|
||||
Mockito.argThat(new ArgumentMatcher<Intent>() {
|
||||
@Override
|
||||
public boolean matches(Object object) {
|
||||
public boolean matchesObject(Object object) {
|
||||
Intent intent = (Intent) object;
|
||||
return NetworkScoreManager.ACTION_CUSTOM_ENABLE.equals(intent.getAction())
|
||||
&& useOpenWifiComp.getPackageName().equals(intent.getPackage());
|
||||
|
||||
@@ -22,13 +22,13 @@ import static junit.framework.TestCase.assertTrue;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyObject;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -46,12 +46,13 @@ import android.support.test.runner.AndroidJUnit4;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.WindowManagerPolicy;
|
||||
import com.android.server.accessibility.KeyEventDispatcher.KeyEventFilter;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
|
||||
/**
|
||||
* Tests for KeyEventDispatcher
|
||||
@@ -558,7 +559,7 @@ public class KeyEventDispatcherTest {
|
||||
.matches(mInputEventsHander.timedMessages.get(1).obj));
|
||||
}
|
||||
|
||||
private class KeyEventMatcher extends ArgumentMatcher<KeyEvent> {
|
||||
private class KeyEventMatcher extends TypeSafeMatcher<KeyEvent> {
|
||||
private KeyEvent mEventToMatch;
|
||||
|
||||
KeyEventMatcher(KeyEvent eventToMatch) {
|
||||
@@ -566,14 +567,15 @@ public class KeyEventDispatcherTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object event) {
|
||||
if (!(event instanceof KeyEvent)) {
|
||||
return false;
|
||||
}
|
||||
KeyEvent keyEvent = (KeyEvent) event;
|
||||
public boolean matchesSafely(KeyEvent keyEvent) {
|
||||
return (mEventToMatch.getAction() == keyEvent.getAction())
|
||||
&& (mEventToMatch.getKeyCode() == keyEvent.getKeyCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("Key event matcher");
|
||||
}
|
||||
}
|
||||
|
||||
private class MessageCapturingHandler extends Handler {
|
||||
|
||||
@@ -22,7 +22,6 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyObject;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -30,6 +29,7 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.BroadcastReceiver;
|
||||
|
||||
@@ -28,7 +28,6 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
@@ -36,6 +35,7 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
import android.accessibilityservice.GestureDescription.GestureStep;
|
||||
import android.accessibilityservice.GestureDescription.TouchPoint;
|
||||
@@ -65,7 +65,7 @@ import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.compat.ArgumentMatcher;
|
||||
|
||||
/**
|
||||
* Tests for MotionEventInjector
|
||||
@@ -738,7 +738,7 @@ public class MotionEventInjectorTest {
|
||||
return next;
|
||||
}
|
||||
|
||||
static class MotionEventMatcher extends ArgumentMatcher<MotionEvent> {
|
||||
static class MotionEventMatcher extends TypeSafeMatcher<MotionEvent> {
|
||||
long mDownTime;
|
||||
long mEventTime;
|
||||
long mActionMasked;
|
||||
@@ -764,8 +764,7 @@ public class MotionEventInjectorTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object o) {
|
||||
MotionEvent event = (MotionEvent) o;
|
||||
public boolean matchesSafely(MotionEvent event) {
|
||||
if ((event.getDownTime() == mDownTime) && (event.getEventTime() == mEventTime)
|
||||
&& (event.getActionMasked() == mActionMasked) && ((int) event.getX() == mX)
|
||||
&& ((int) event.getY() == mY)) {
|
||||
@@ -782,6 +781,11 @@ public class MotionEventInjectorTest {
|
||||
Log.e(LOG_TAG, "event.getY() = " + event.getY() + ", expected " + mY);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("Motion event matcher");
|
||||
}
|
||||
}
|
||||
|
||||
private static class MotionEventActionMatcher extends TypeSafeMatcher<MotionEvent> {
|
||||
|
||||
@@ -85,7 +85,6 @@ import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyObject;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Matchers.isNull;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
@@ -99,6 +98,7 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Tests for DevicePolicyManager( and DevicePolicyManagerService).
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.hamcrest.MockitoHamcrest;
|
||||
|
||||
public class MockUtils {
|
||||
private MockUtils() {
|
||||
@@ -47,7 +48,7 @@ public class MockUtils {
|
||||
description.appendText("UserHandle: user-id= \"" + userId + "\"");
|
||||
}
|
||||
};
|
||||
return Mockito.argThat(m);
|
||||
return MockitoHamcrest.argThat(m);
|
||||
}
|
||||
|
||||
public static Intent checkIntentComponent(final ComponentName component) {
|
||||
@@ -63,7 +64,7 @@ public class MockUtils {
|
||||
description.appendText("Intent: component=\"" + component + "\"");
|
||||
}
|
||||
};
|
||||
return Mockito.argThat(m);
|
||||
return MockitoHamcrest.argThat(m);
|
||||
}
|
||||
|
||||
public static Intent checkIntentAction(final String action) {
|
||||
@@ -79,7 +80,7 @@ public class MockUtils {
|
||||
description.appendText("Intent: action=\"" + action + "\"");
|
||||
}
|
||||
};
|
||||
return Mockito.argThat(m);
|
||||
return MockitoHamcrest.argThat(m);
|
||||
}
|
||||
|
||||
public static Intent checkIntent(final Intent intent) {
|
||||
@@ -94,7 +95,7 @@ public class MockUtils {
|
||||
description.appendText(intent.toString());
|
||||
}
|
||||
};
|
||||
return Mockito.argThat(m);
|
||||
return MockitoHamcrest.argThat(m);
|
||||
}
|
||||
|
||||
public static Bundle checkUserRestrictions(String... keys) {
|
||||
@@ -111,7 +112,7 @@ public class MockUtils {
|
||||
description.appendText("User restrictions=" + getRestrictionsAsString(expected));
|
||||
}
|
||||
};
|
||||
return Mockito.argThat(m);
|
||||
return MockitoHamcrest.argThat(m);
|
||||
}
|
||||
|
||||
private static String getRestrictionsAsString(Bundle b) {
|
||||
|
||||
@@ -45,8 +45,8 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.internal.util.reflection.Whitebox;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
|
||||
import static android.provider.Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN;
|
||||
@@ -124,7 +124,15 @@ public class AccessibilityShortcutControllerTest {
|
||||
when(mToast.getWindowParams()).thenReturn(mLayoutParams);
|
||||
|
||||
Window window = mock(Window.class);
|
||||
Whitebox.setInternalState(window, "mWindowAttributes", new WindowManager.LayoutParams());
|
||||
// Initialize the mWindowAttributes field which was not properly initialized during mock
|
||||
// creation.
|
||||
try {
|
||||
Field field = Window.class.getDeclaredField("mWindowAttributes");
|
||||
field.setAccessible(true);
|
||||
field.set(window, new WindowManager.LayoutParams());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to set mWindowAttributes", e);
|
||||
}
|
||||
when(mAlertDialog.getWindow()).thenReturn(window);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,16 +66,15 @@ import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.server.SystemService;
|
||||
import com.android.server.retaildemo.RetailDemoModeService.Injector;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.compat.ArgumentMatcher;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -283,7 +282,7 @@ public class RetailDemoModeServiceTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object argument) {
|
||||
public boolean matchesObject(Object argument) {
|
||||
if (argument instanceof Intent) {
|
||||
return ((Intent) argument).filterEquals(mIntent);
|
||||
}
|
||||
@@ -291,8 +290,8 @@ public class RetailDemoModeServiceTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("Expected: " + mIntent);
|
||||
public String toString() {
|
||||
return "Expected: " + mIntent;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,14 +35,12 @@ import android.webkit.WebViewFactory;
|
||||
import android.webkit.WebViewProviderInfo;
|
||||
import android.webkit.WebViewProviderResponse;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.compat.ArgumentMatcher;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
@@ -149,14 +147,13 @@ public class WebViewUpdateServiceTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object p) {
|
||||
public boolean matchesObject(Object p) {
|
||||
return ((PackageInfo) p).packageName.equals(mPackageName);
|
||||
}
|
||||
|
||||
// Provide a more useful description in case of mismatch
|
||||
@Override
|
||||
public void describeTo (Description description) {
|
||||
description.appendText(String.format("PackageInfo with name '%s'", mPackageName));
|
||||
public String toString() {
|
||||
return String.format("PackageInfo with name '%s'", mPackageName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ class TestWindowManagerPolicy implements WindowManagerPolicy {
|
||||
final ActivityManagerInternal am =
|
||||
LocalServices.getService(ActivityManagerInternal.class);
|
||||
doAnswer((InvocationOnMock invocationOnMock) -> {
|
||||
final Runnable runnable = invocationOnMock.getArgumentAt(0, Runnable.class);
|
||||
final Runnable runnable = invocationOnMock.<Runnable>getArgument(0);
|
||||
if (runnable != null) {
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.hamcrest.MockitoHamcrest;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@@ -672,7 +673,7 @@ public class ShortcutManagerTestUtils {
|
||||
d.appendText(description);
|
||||
}
|
||||
};
|
||||
return Mockito.argThat(m);
|
||||
return MockitoHamcrest.argThat(m);
|
||||
}
|
||||
|
||||
public static List<ShortcutInfo> checkShortcutIds(String... ids) {
|
||||
|
||||
Reference in New Issue
Block a user