Merge "Refactor code incompatible with Mockito 2.7.13" am: 2a3a4f81f9
am: 17e5a2d851
Change-Id: I91f5108861ed4eb47d9fae13860e79babf0f4bf9
This commit is contained in:
@@ -32,10 +32,10 @@ import android.provider.Settings;
|
|||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
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;
|
||||||
|
|
||||||
public class NetworkScorerAppManagerTest extends InstrumentationTestCase {
|
public class NetworkScorerAppManagerTest extends InstrumentationTestCase {
|
||||||
@Mock private Context mMockContext;
|
@Mock private Context mMockContext;
|
||||||
@@ -218,7 +218,7 @@ public class NetworkScorerAppManagerTest extends InstrumentationTestCase {
|
|||||||
when(mMockPm.resolveService(
|
when(mMockPm.resolveService(
|
||||||
Mockito.argThat(new ArgumentMatcher<Intent>() {
|
Mockito.argThat(new ArgumentMatcher<Intent>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Object object) {
|
public boolean matchesObject(Object object) {
|
||||||
Intent intent = (Intent) object;
|
Intent intent = (Intent) object;
|
||||||
return NetworkScoreManager.ACTION_RECOMMEND_NETWORKS
|
return NetworkScoreManager.ACTION_RECOMMEND_NETWORKS
|
||||||
.equals(intent.getAction())
|
.equals(intent.getAction())
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ import static android.hardware.camera2.CameraDevice.TEMPLATE_PREVIEW;
|
|||||||
|
|
||||||
import com.android.mediaframeworktest.MediaFrameworkIntegrationTestRunner;
|
import com.android.mediaframeworktest.MediaFrameworkIntegrationTestRunner;
|
||||||
|
|
||||||
import org.mockito.ArgumentMatcher;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.compat.ArgumentMatcher;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class CameraDeviceBinderTest extends AndroidTestCase {
|
public class CameraDeviceBinderTest extends AndroidTestCase {
|
||||||
@@ -158,7 +158,7 @@ public class CameraDeviceBinderTest extends AndroidTestCase {
|
|||||||
|
|
||||||
class IsMetadataNotEmpty extends ArgumentMatcher<CameraMetadataNative> {
|
class IsMetadataNotEmpty extends ArgumentMatcher<CameraMetadataNative> {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Object obj) {
|
public boolean matchesObject(Object obj) {
|
||||||
return !((CameraMetadataNative) obj).isEmpty();
|
return !((CameraMetadataNative) obj).isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -271,8 +271,8 @@ public class NetworkScoreServiceTest {
|
|||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
bundle.putParcelable(EXTRA_RECOMMENDATION_RESULT, providerResult);
|
bundle.putParcelable(EXTRA_RECOMMENDATION_RESULT, providerResult);
|
||||||
doAnswer(invocation -> {
|
doAnswer(invocation -> {
|
||||||
bundle.putInt(EXTRA_SEQUENCE, invocation.getArgumentAt(2, int.class));
|
bundle.putInt(EXTRA_SEQUENCE, invocation.getArgument(2));
|
||||||
invocation.getArgumentAt(1, IRemoteCallback.class).sendResult(bundle);
|
invocation.<IRemoteCallback>getArgument(1).sendResult(bundle);
|
||||||
return null;
|
return null;
|
||||||
}).when(mRecommendationProvider)
|
}).when(mRecommendationProvider)
|
||||||
.requestRecommendation(eq(mRecommendationRequest), isA(IRemoteCallback.class),
|
.requestRecommendation(eq(mRecommendationRequest), isA(IRemoteCallback.class),
|
||||||
@@ -336,7 +336,7 @@ public class NetworkScoreServiceTest {
|
|||||||
injectProvider();
|
injectProvider();
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
doAnswer(invocation -> {
|
doAnswer(invocation -> {
|
||||||
invocation.getArgumentAt(1, IRemoteCallback.class).sendResult(bundle);
|
invocation.<IRemoteCallback>getArgument(1).sendResult(bundle);
|
||||||
return null;
|
return null;
|
||||||
}).when(mRecommendationProvider)
|
}).when(mRecommendationProvider)
|
||||||
.requestRecommendation(eq(mRecommendationRequest), isA(IRemoteCallback.class),
|
.requestRecommendation(eq(mRecommendationRequest), isA(IRemoteCallback.class),
|
||||||
@@ -634,7 +634,7 @@ public class NetworkScoreServiceTest {
|
|||||||
IBinder mockBinder = mock(IBinder.class);
|
IBinder mockBinder = mock(IBinder.class);
|
||||||
when(mockBinder.queryLocalInterface(anyString()))
|
when(mockBinder.queryLocalInterface(anyString()))
|
||||||
.thenReturn(mRecommendationProvider);
|
.thenReturn(mRecommendationProvider);
|
||||||
invocation.getArgumentAt(1, ServiceConnection.class)
|
invocation.<ServiceConnection>getArgument(1)
|
||||||
.onServiceConnected(componentName, mockBinder);
|
.onServiceConnected(componentName, mockBinder);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.hamcrest.BaseMatcher;
|
|||||||
import org.hamcrest.Description;
|
import org.hamcrest.Description;
|
||||||
import org.hamcrest.Matcher;
|
import org.hamcrest.Matcher;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.hamcrest.MockitoHamcrest;
|
||||||
|
|
||||||
public class MockUtils {
|
public class MockUtils {
|
||||||
private MockUtils() {
|
private MockUtils() {
|
||||||
@@ -47,7 +48,7 @@ public class MockUtils {
|
|||||||
description.appendText("UserHandle: user-id= \"" + userId + "\"");
|
description.appendText("UserHandle: user-id= \"" + userId + "\"");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Mockito.argThat(m);
|
return MockitoHamcrest.argThat(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Intent checkIntentComponent(final ComponentName component) {
|
public static Intent checkIntentComponent(final ComponentName component) {
|
||||||
@@ -63,7 +64,7 @@ public class MockUtils {
|
|||||||
description.appendText("Intent: component=\"" + component + "\"");
|
description.appendText("Intent: component=\"" + component + "\"");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Mockito.argThat(m);
|
return MockitoHamcrest.argThat(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Intent checkIntentAction(final String action) {
|
public static Intent checkIntentAction(final String action) {
|
||||||
@@ -79,7 +80,7 @@ public class MockUtils {
|
|||||||
description.appendText("Intent: action=\"" + action + "\"");
|
description.appendText("Intent: action=\"" + action + "\"");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Mockito.argThat(m);
|
return MockitoHamcrest.argThat(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Intent checkIntent(final Intent intent) {
|
public static Intent checkIntent(final Intent intent) {
|
||||||
@@ -94,7 +95,7 @@ public class MockUtils {
|
|||||||
description.appendText(intent.toString());
|
description.appendText(intent.toString());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Mockito.argThat(m);
|
return MockitoHamcrest.argThat(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bundle checkUserRestrictions(String... keys) {
|
public static Bundle checkUserRestrictions(String... keys) {
|
||||||
@@ -111,7 +112,7 @@ public class MockUtils {
|
|||||||
description.appendText("User restrictions=" + getRestrictionsAsString(expected));
|
description.appendText("User restrictions=" + getRestrictionsAsString(expected));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Mockito.argThat(m);
|
return MockitoHamcrest.argThat(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getRestrictionsAsString(Bundle b) {
|
private static String getRestrictionsAsString(Bundle b) {
|
||||||
|
|||||||
@@ -32,14 +32,12 @@ import android.webkit.WebViewFactory;
|
|||||||
import android.webkit.WebViewProviderInfo;
|
import android.webkit.WebViewProviderInfo;
|
||||||
import android.webkit.WebViewProviderResponse;
|
import android.webkit.WebViewProviderResponse;
|
||||||
|
|
||||||
import org.hamcrest.Description;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.Matchers;
|
import org.mockito.Matchers;
|
||||||
import org.mockito.ArgumentMatcher;
|
import org.mockito.compat.ArgumentMatcher;
|
||||||
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
@@ -131,14 +129,13 @@ public class WebViewUpdateServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Object p) {
|
public boolean matchesObject(Object p) {
|
||||||
return ((PackageInfo) p).packageName.equals(mPackageName);
|
return ((PackageInfo) p).packageName.equals(mPackageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provide a more useful description in case of mismatch
|
|
||||||
@Override
|
@Override
|
||||||
public void describeTo (Description description) {
|
public String toString() {
|
||||||
description.appendText(String.format("PackageInfo with name '%s'", mPackageName));
|
return String.format("PackageInfo with name '%s'", mPackageName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.hamcrest.MockitoHamcrest;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -665,7 +666,7 @@ public class ShortcutManagerTestUtils {
|
|||||||
d.appendText(description);
|
d.appendText(description);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Mockito.argThat(m);
|
return MockitoHamcrest.argThat(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<ShortcutInfo> checkShortcutIds(String... ids) {
|
public static List<ShortcutInfo> checkShortcutIds(String... ids) {
|
||||||
|
|||||||
Reference in New Issue
Block a user