Merge "Refactor code incompatible with Mockito 2.7.13"

This commit is contained in:
Paul Duffin
2017-03-10 20:33:20 +00:00
committed by Gerrit Code Review
6 changed files with 20 additions and 21 deletions

View File

@@ -32,10 +32,10 @@ import android.provider.Settings;
import android.test.InstrumentationTestCase;
import com.android.internal.R;
import java.util.List;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.compat.ArgumentMatcher;
public class NetworkScorerAppManagerTest extends InstrumentationTestCase {
@Mock private Context mMockContext;
@@ -218,7 +218,7 @@ public class NetworkScorerAppManagerTest extends InstrumentationTestCase {
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())

View File

@@ -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 {
@@ -158,7 +158,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();
}
}

View File

@@ -271,8 +271,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),
@@ -336,7 +336,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),
@@ -634,7 +634,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(componentName, mockBinder);
return true;
}

View File

@@ -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) {

View File

@@ -32,14 +32,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;
@@ -131,14 +129,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);
}
}

View File

@@ -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;
@@ -665,7 +666,7 @@ public class ShortcutManagerTestUtils {
d.appendText(description);
}
};
return Mockito.argThat(m);
return MockitoHamcrest.argThat(m);
}
public static List<ShortcutInfo> checkShortcutIds(String... ids) {