Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a3a4f81 authored by Paul Duffin's avatar Paul Duffin Committed by Gerrit Code Review
Browse files

Merge "Refactor code incompatible with Mockito 2.7.13"

parents 3dee2958 26e81d2a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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())
+2 −2
Original line number Diff line number Diff line
@@ -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();
        }
    }
+4 −4
Original line number Diff line number Diff line
@@ -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;
            }
+6 −5
Original line number Diff line number Diff line
@@ -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) {
+4 −7
Original line number Diff line number Diff line
@@ -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);
        }
    }

Loading