Migrate settings robolectric tests to mockito 2
- Migrated ArgumentMatcher subclasses to lambdas - Replaced any() with nullable() where tests were failing Test: cd tests/robotests && mma Bug: 38456058 Change-Id: Ice8c39b435c45b87f82dbbd9860e68f235314cf8
This commit is contained in:
@@ -8,7 +8,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||
|
||||
# Include the testing libraries (JUnit4 + Robolectric libs).
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := \
|
||||
platform-system-robolectric \
|
||||
mockito-robolectric-prebuilt \
|
||||
truth-prebuilt
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := \
|
||||
|
@@ -16,6 +16,16 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.FragmentManager;
|
||||
@@ -23,10 +33,11 @@ import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -37,15 +48,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SettingsActivityTest {
|
||||
@@ -89,7 +91,7 @@ public class SettingsActivityTest {
|
||||
public void testSetTaskDescription_IconChanged() {
|
||||
mActivity.setTaskDescription(mTaskDescription);
|
||||
|
||||
verify(mTaskDescription).setIcon(any());
|
||||
verify(mTaskDescription).setIcon(nullable(Bitmap.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,8 +101,8 @@ public class SettingsActivityTest {
|
||||
mActivity.mDisplaySearch = true;
|
||||
mActivity.onCreateOptionsMenu(null);
|
||||
|
||||
verify(mFeatureFactory.getSearchFeatureProvider()).setUpSearchMenu(any(Menu.class),
|
||||
any(Activity.class));
|
||||
verify(mFeatureFactory.getSearchFeatureProvider()).setUpSearchMenu(nullable(Menu.class),
|
||||
nullable(Activity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -15,6 +15,20 @@
|
||||
*/
|
||||
package com.android.settings.accounts;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Matchers.any;
|
||||
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.never;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AuthenticatorDescription;
|
||||
@@ -49,19 +63,6 @@ import org.robolectric.shadows.ShadowApplication;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Matchers.any;
|
||||
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.never;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
@@ -442,8 +443,8 @@ public class AccountPreferenceControllerTest {
|
||||
mController.onResume();
|
||||
|
||||
// each account should be added only once
|
||||
verify(preferenceGroup).addPreference(argThat(new PreferenceMatcher("Acct11")));
|
||||
verify(preferenceGroup).addPreference(argThat(new PreferenceMatcher("Acct12")));
|
||||
verify(preferenceGroup).addPreference(argThat(titleMatches("Acct11")));
|
||||
verify(preferenceGroup).addPreference(argThat(titleMatches("Acct12")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -486,9 +487,9 @@ public class AccountPreferenceControllerTest {
|
||||
mController.onResume();
|
||||
|
||||
// each account should be added only once
|
||||
verify(preferenceGroup, times(1)).addPreference(argThat(new PreferenceMatcher("Acct11")));
|
||||
verify(preferenceGroup, times(1)).addPreference(argThat(new PreferenceMatcher("Acct12")));
|
||||
verify(preferenceGroup, times(1)).addPreference(argThat(new PreferenceMatcher("Acct13")));
|
||||
verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct11")));
|
||||
verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct12")));
|
||||
verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct13")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -524,7 +525,7 @@ public class AccountPreferenceControllerTest {
|
||||
// Resume should show the newly added account
|
||||
mController.onResume();
|
||||
|
||||
verify(preferenceGroup).addPreference(argThat(new PreferenceMatcher("Acct1")));
|
||||
verify(preferenceGroup).addPreference(argThat(titleMatches("Acct1")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -565,25 +566,12 @@ public class AccountPreferenceControllerTest {
|
||||
|
||||
mController.onResume();
|
||||
|
||||
verify(preferenceGroup, times(1)).addPreference(argThat(new PreferenceMatcher("Acct11")));
|
||||
verify(preferenceGroup, times(1)).addPreference(argThat(new PreferenceMatcher("Acct12")));
|
||||
verify(preferenceGroup, times(1)).removePreference(
|
||||
argThat(new PreferenceMatcher("Acct12")));
|
||||
verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct11")));
|
||||
verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct12")));
|
||||
verify(preferenceGroup, times(1)).removePreference(argThat(titleMatches("Acct12")));
|
||||
}
|
||||
|
||||
private static class PreferenceMatcher extends ArgumentMatcher<Preference> {
|
||||
|
||||
private final String mExpectedTitle;
|
||||
|
||||
public PreferenceMatcher(String title) {
|
||||
mExpectedTitle = title;
|
||||
private static ArgumentMatcher<Preference> titleMatches(String expected) {
|
||||
return preference -> TextUtils.equals(expected, preference.getTitle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object arg) {
|
||||
final Preference preference = (Preference) arg;
|
||||
return TextUtils.equals(mExpectedTitle, preference.getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -15,6 +15,16 @@
|
||||
*/
|
||||
package com.android.settings.accounts;
|
||||
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AccountManagerCallback;
|
||||
@@ -26,17 +36,14 @@ import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v14.preference.PreferenceFragment;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settings.AccessiblePreferenceCategory;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowAccountManager;
|
||||
import com.android.settings.testutils.shadow.ShadowContentResolver;
|
||||
|
||||
@@ -48,16 +55,6 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class RemoveAccountPreferenceControllerTest {
|
||||
@@ -134,7 +131,7 @@ public class RemoveAccountPreferenceControllerTest {
|
||||
mFragment, account, userHandle);
|
||||
dialog.onCreate(new Bundle());
|
||||
dialog.onClick(null, 0);
|
||||
verify(mAccountManager).removeAccountAsUser(eq(account), any(Activity.class),
|
||||
any(AccountManagerCallback.class), any(Handler.class), eq(userHandle));
|
||||
verify(mAccountManager).removeAccountAsUser(eq(account), nullable(Activity.class),
|
||||
nullable(AccountManagerCallback.class), nullable(Handler.class), eq(userHandle));
|
||||
}
|
||||
}
|
@@ -16,6 +16,10 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Matchers.nullable;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
@@ -35,10 +39,6 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DrawOverlayDetailsTest {
|
||||
@@ -66,11 +66,11 @@ public class DrawOverlayDetailsTest {
|
||||
public void logSpecialPermissionChange() {
|
||||
mFragment.onAttach(ShadowApplication.getInstance().getApplicationContext());
|
||||
mFragment.logSpecialPermissionChange(true, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_APPDRAW_ALLOW), eq("app"));
|
||||
|
||||
mFragment.logSpecialPermissionChange(false, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_APPDRAW_DENY), eq("app"));
|
||||
}
|
||||
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.applications;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -63,7 +64,8 @@ public class FetchPackageStorageAsyncLoaderTest {
|
||||
when(stats.getCodeBytes()).thenReturn(1L);
|
||||
when(stats.getDataBytes()).thenReturn(2L);
|
||||
when(stats.getCacheBytes()).thenReturn(3L);
|
||||
when(mSource.getStatsForPackage(anyString(), anyString(), any(UserHandle.class)))
|
||||
when(mSource.getStatsForPackage(nullable(String.class), nullable(String.class),
|
||||
any(UserHandle.class)))
|
||||
.thenReturn(stats);
|
||||
ApplicationInfo info = new ApplicationInfo();
|
||||
info.packageName = PACKAGE_NAME;
|
||||
|
@@ -16,13 +16,25 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import static com.android.settings.testutils.ApplicationTestUtils.buildInfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.Build;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
@@ -41,20 +53,9 @@ import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.android.settings.testutils.ApplicationTestUtils.buildInfo;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.anyObject;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link InstalledAppCounter}.
|
||||
*/
|
||||
@@ -113,11 +114,12 @@ public final class InstalledAppCounterTest {
|
||||
|
||||
private void expectQueryIntentActivities(int userId, String packageName, boolean launchable) {
|
||||
when(mPackageManager.queryIntentActivitiesAsUser(
|
||||
argThat(new IsLaunchIntentFor(packageName)),
|
||||
argThat(isLaunchIntentFor(packageName)),
|
||||
eq(PackageManager.GET_DISABLED_COMPONENTS | PackageManager.MATCH_DIRECT_BOOT_AWARE
|
||||
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE),
|
||||
eq(userId))).thenReturn(launchable ? Arrays.asList(new ResolveInfo())
|
||||
: new ArrayList<ResolveInfo>());
|
||||
eq(userId))).thenReturn(launchable
|
||||
? Collections.singletonList(new ResolveInfo())
|
||||
: new ArrayList<>());
|
||||
}
|
||||
|
||||
private void testCountInstalledAppsAcrossAllUsers(boolean async) {
|
||||
@@ -136,7 +138,7 @@ public final class InstalledAppCounterTest {
|
||||
verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(), eq(MAIN_USER_ID));
|
||||
verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(),
|
||||
eq(MANAGED_PROFILE_ID));
|
||||
verify(mPackageManager, atLeast(0)).queryIntentActivitiesAsUser(anyObject(), anyInt(),
|
||||
verify(mPackageManager, atLeast(0)).queryIntentActivitiesAsUser(any(Intent.class), anyInt(),
|
||||
anyInt());
|
||||
verifyNoMoreInteractions(mPackageManager);
|
||||
|
||||
@@ -251,16 +253,8 @@ public final class InstalledAppCounterTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static class IsLaunchIntentFor extends ArgumentMatcher<Intent> {
|
||||
private final String mPackageName;
|
||||
|
||||
IsLaunchIntentFor(String packageName) {
|
||||
mPackageName = packageName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object i) {
|
||||
final Intent intent = (Intent) i;
|
||||
private ArgumentMatcher<Intent> isLaunchIntentFor(String packageName) {
|
||||
return intent -> {
|
||||
if (intent == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -272,10 +266,10 @@ public final class InstalledAppCounterTest {
|
||||
!categories.contains(Intent.CATEGORY_LAUNCHER)) {
|
||||
return false;
|
||||
}
|
||||
if (!mPackageName.equals(intent.getPackage())) {
|
||||
if (!packageName.equals(intent.getPackage())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -19,10 +19,9 @@ package com.android.settings.applications;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.anyDouble;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -32,6 +31,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Fragment;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -53,6 +53,7 @@ import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.instantapps.InstantAppButtonsController;
|
||||
import com.android.settings.applications.instantapps.InstantAppButtonsController.ShowDialogDelegate;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
@@ -137,7 +138,7 @@ public final class InstalledAppDetailsTest {
|
||||
|
||||
@Test
|
||||
public void shouldShowUninstallForAll_installForOneOtherUserOnly_shouldReturnTrue() {
|
||||
when(mDevicePolicyManager.packageHasActiveAdmins(anyString())).thenReturn(false);
|
||||
when(mDevicePolicyManager.packageHasActiveAdmins(nullable(String.class))).thenReturn(false);
|
||||
when(mUserManager.getUsers().size()).thenReturn(2);
|
||||
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
|
||||
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
|
||||
@@ -153,7 +154,7 @@ public final class InstalledAppDetailsTest {
|
||||
|
||||
@Test
|
||||
public void shouldShowUninstallForAll_installForSelfOnly_shouldReturnFalse() {
|
||||
when(mDevicePolicyManager.packageHasActiveAdmins(anyString())).thenReturn(false);
|
||||
when(mDevicePolicyManager.packageHasActiveAdmins(nullable(String.class))).thenReturn(false);
|
||||
when(mUserManager.getUsers().size()).thenReturn(2);
|
||||
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
|
||||
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
|
||||
@@ -239,7 +240,7 @@ public final class InstalledAppDetailsTest {
|
||||
// Make this app appear to be instant.
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> true));
|
||||
when(mDevicePolicyManager.packageHasActiveAdmins(anyString())).thenReturn(false);
|
||||
when(mDevicePolicyManager.packageHasActiveAdmins(nullable(String.class))).thenReturn(false);
|
||||
when(mUserManager.getUsers().size()).thenReturn(2);
|
||||
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
@@ -349,16 +350,18 @@ public final class InstalledAppDetailsTest {
|
||||
|
||||
final InstantAppButtonsController buttonsController =
|
||||
mock(InstantAppButtonsController.class);
|
||||
when(buttonsController.setPackageName(anyString())).thenReturn(buttonsController);
|
||||
when(buttonsController.setPackageName(nullable(String.class)))
|
||||
.thenReturn(buttonsController);
|
||||
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
FakeFeatureFactory factory =
|
||||
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
when(factory.applicationFeatureProvider.newInstantAppButtonsController(
|
||||
any(), any(), any())).thenReturn(buttonsController);
|
||||
nullable(Fragment.class), nullable(View.class), nullable(ShowDialogDelegate.class)))
|
||||
.thenReturn(buttonsController);
|
||||
|
||||
fragment.maybeAddInstantAppButtons();
|
||||
verify(buttonsController).setPackageName(anyString());
|
||||
verify(buttonsController).setPackageName(nullable(String.class));
|
||||
verify(buttonsController).show();
|
||||
}
|
||||
|
||||
|
@@ -87,11 +87,12 @@ public final class InstalledAppListerTest {
|
||||
|
||||
private void expectQueryIntentActivities(int userId, String packageName, boolean launchable) {
|
||||
when(mPackageManager.queryIntentActivitiesAsUser(
|
||||
argThat(new IsLaunchIntentFor(packageName)),
|
||||
argThat(isLaunchIntentFor(packageName)),
|
||||
eq(PackageManager.GET_DISABLED_COMPONENTS | PackageManager.MATCH_DIRECT_BOOT_AWARE
|
||||
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE),
|
||||
eq(userId))).thenReturn(launchable ? Arrays.asList(new ResolveInfo())
|
||||
: new ArrayList<ResolveInfo>());
|
||||
eq(userId))).thenReturn(launchable
|
||||
? Collections.singletonList(new ResolveInfo())
|
||||
: Collections.emptyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -203,16 +204,8 @@ public final class InstalledAppListerTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static class IsLaunchIntentFor extends ArgumentMatcher<Intent> {
|
||||
private final String mPackageName;
|
||||
|
||||
IsLaunchIntentFor(String packageName) {
|
||||
mPackageName = packageName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object i) {
|
||||
final Intent intent = (Intent) i;
|
||||
private static ArgumentMatcher<Intent> isLaunchIntentFor(String packageName) {
|
||||
return intent -> {
|
||||
if (intent == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -224,10 +217,10 @@ public final class InstalledAppListerTest {
|
||||
!categories.contains(Intent.CATEGORY_LAUNCHER)) {
|
||||
return false;
|
||||
}
|
||||
if (!mPackageName.equals(intent.getPackage())) {
|
||||
if (!packageName.equals(intent.getPackage())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ package com.android.settings.applications;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.nullable;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -32,8 +32,8 @@ import android.view.LayoutInflater;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -82,7 +82,7 @@ public class MusicViewHolderControllerTest {
|
||||
|
||||
@Test
|
||||
public void storageShouldRepresentStorageStatsQuery() throws Exception {
|
||||
when(mSource.getExternalStorageStats(any(String.class), any(UserHandle.class))).thenReturn(
|
||||
when(mSource.getExternalStorageStats(nullable(String.class), nullable(UserHandle.class))).thenReturn(
|
||||
new StorageStatsSource.ExternalStorageStats(1, 1, 0, 0));
|
||||
|
||||
mController.queryStats();
|
||||
|
@@ -16,6 +16,12 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
@@ -30,12 +36,6 @@ import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@@ -83,11 +83,11 @@ public class PictureInPictureDetailsTest {
|
||||
@Test
|
||||
public void logSpecialPermissionChange() {
|
||||
mFragment.logSpecialPermissionChange(true, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_PICTURE_IN_PICTURE_ALLOW), eq("app"));
|
||||
|
||||
mFragment.logSpecialPermissionChange(false, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_PICTURE_IN_PICTURE_DENY), eq("app"));
|
||||
}
|
||||
|
||||
|
@@ -16,6 +16,10 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
@@ -33,10 +37,6 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class PremiumSmsAccessTest {
|
||||
@@ -60,17 +60,17 @@ public class PremiumSmsAccessTest {
|
||||
public void logSpecialPermissionChange() {
|
||||
mFragment.logSpecialPermissionChange(SmsUsageMonitor.PREMIUM_SMS_PERMISSION_ASK_USER,
|
||||
"app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_PREMIUM_SMS_ASK), eq("app"));
|
||||
|
||||
mFragment.logSpecialPermissionChange(SmsUsageMonitor.PREMIUM_SMS_PERMISSION_NEVER_ALLOW,
|
||||
"app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_PREMIUM_SMS_DENY), eq("app"));
|
||||
|
||||
mFragment.logSpecialPermissionChange(SmsUsageMonitor.PREMIUM_SMS_PERMISSION_ALWAYS_ALLOW,
|
||||
"app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_PREMIUM_SMS_ALWAYS_ALLOW),
|
||||
eq("app"));
|
||||
}
|
||||
|
@@ -16,6 +16,10 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
@@ -32,10 +36,6 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class UsageAccessDetailsTest {
|
||||
@@ -58,11 +58,11 @@ public class UsageAccessDetailsTest {
|
||||
@Test
|
||||
public void logSpecialPermissionChange() {
|
||||
mFragment.logSpecialPermissionChange(true, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_USAGE_VIEW_ALLOW), eq("app"));
|
||||
|
||||
mFragment.logSpecialPermissionChange(false, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_USAGE_VIEW_DENY), eq("app"));
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,10 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
@@ -31,10 +35,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class VrListenerSettingsTest {
|
||||
@@ -56,11 +56,11 @@ public class VrListenerSettingsTest {
|
||||
@Test
|
||||
public void logSpecialPermissionChange() {
|
||||
mFragment.logSpecialPermissionChange(true, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_VRHELPER_ALLOW), eq("app"));
|
||||
|
||||
mFragment.logSpecialPermissionChange(false, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_VRHELPER_DENY), eq("app"));
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,10 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
@@ -31,10 +35,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class WriteSettingsDetailsTest {
|
||||
@@ -56,12 +56,12 @@ public class WriteSettingsDetailsTest {
|
||||
@Test
|
||||
public void logSpecialPermissionChange() {
|
||||
mFragment.logSpecialPermissionChange(true, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_SETTINGS_CHANGE_ALLOW),
|
||||
eq("app"));
|
||||
|
||||
mFragment.logSpecialPermissionChange(false, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_SETTINGS_CHANGE_DENY),
|
||||
eq("app"));
|
||||
}
|
||||
|
@@ -15,6 +15,19 @@
|
||||
*/
|
||||
package com.android.settings.core.instrumentation;
|
||||
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
|
||||
.FIELD_SETTINGS_PREFERENCE_CHANGE_FLOAT_VALUE;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
|
||||
.FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
|
||||
.FIELD_SETTINGS_PREFERENCE_CHANGE_NAME;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Pair;
|
||||
@@ -34,18 +47,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
|
||||
.FIELD_SETTINGS_PREFERENCE_CHANGE_FLOAT_VALUE;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
|
||||
.FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
|
||||
.FIELD_SETTINGS_PREFERENCE_CHANGE_NAME;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SharedPreferenceLoggerTest {
|
||||
@@ -56,7 +57,7 @@ public class SharedPreferenceLoggerTest {
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
|
||||
private PairMatcher mNamePairMatcher;
|
||||
private ArgumentMatcher<Pair<Integer, Object>> mNamePairMatcher;
|
||||
private FakeFeatureFactory mFactory;
|
||||
private MetricsFeatureProvider mMetricsFeature;
|
||||
private SharedPreferencesLogger mSharedPrefLogger;
|
||||
@@ -69,7 +70,7 @@ public class SharedPreferenceLoggerTest {
|
||||
mMetricsFeature = mFactory.metricsFeatureProvider;
|
||||
|
||||
mSharedPrefLogger = new SharedPreferencesLogger(mContext, TEST_TAG);
|
||||
mNamePairMatcher = new PairMatcher(FIELD_SETTINGS_PREFERENCE_CHANGE_NAME, String.class);
|
||||
mNamePairMatcher = pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_NAME, String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,11 +84,9 @@ public class SharedPreferenceLoggerTest {
|
||||
editor.putInt(TEST_KEY, 2);
|
||||
editor.putInt(TEST_KEY, 2);
|
||||
|
||||
final PairMatcher longMatcher =
|
||||
new PairMatcher(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, Long.class);
|
||||
|
||||
verify(mMetricsFeature, times(6)).action(any(Context.class), anyInt(),
|
||||
argThat(mNamePairMatcher), argThat(longMatcher));
|
||||
argThat(mNamePairMatcher),
|
||||
argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, Long.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,15 +99,12 @@ public class SharedPreferenceLoggerTest {
|
||||
editor.putBoolean(TEST_KEY, false);
|
||||
|
||||
|
||||
final PairMatcher trueMatcher =
|
||||
new PairMatcher(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, true);
|
||||
final PairMatcher falseMatcher =
|
||||
new PairMatcher(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, false);
|
||||
|
||||
verify(mMetricsFeature).action(any(Context.class), anyInt(),
|
||||
argThat(mNamePairMatcher), argThat(trueMatcher));
|
||||
argThat(mNamePairMatcher),
|
||||
argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, true)));
|
||||
verify(mMetricsFeature, times(3)).action(any(Context.class), anyInt(),
|
||||
argThat(mNamePairMatcher), argThat(falseMatcher));
|
||||
argThat(mNamePairMatcher),
|
||||
argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,11 +116,9 @@ public class SharedPreferenceLoggerTest {
|
||||
editor.putLong(TEST_KEY, 1);
|
||||
editor.putLong(TEST_KEY, 2);
|
||||
|
||||
final PairMatcher longMatcher =
|
||||
new PairMatcher(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, Long.class);
|
||||
|
||||
verify(mMetricsFeature, times(4)).action(any(Context.class), anyInt(),
|
||||
argThat(mNamePairMatcher), argThat(longMatcher));
|
||||
argThat(mNamePairMatcher),
|
||||
argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, Long.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,40 +130,19 @@ public class SharedPreferenceLoggerTest {
|
||||
editor.putFloat(TEST_KEY, 1);
|
||||
editor.putFloat(TEST_KEY, 2);
|
||||
|
||||
final PairMatcher floatMatcher =
|
||||
new PairMatcher(FIELD_SETTINGS_PREFERENCE_CHANGE_FLOAT_VALUE, Float.class);
|
||||
|
||||
verify(mMetricsFeature, times(4)).action(any(Context.class), anyInt(),
|
||||
argThat(mNamePairMatcher), argThat(floatMatcher));
|
||||
argThat(mNamePairMatcher),
|
||||
argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_FLOAT_VALUE, Float.class)));
|
||||
}
|
||||
|
||||
private static class PairMatcher extends ArgumentMatcher<Pair<Integer, Object>> {
|
||||
|
||||
private final int mExpectedTag;
|
||||
private final Class mExpectedClass;
|
||||
private final Long mExpectedBoolean;
|
||||
|
||||
|
||||
public PairMatcher(int tag, Class clazz) {
|
||||
mExpectedTag = tag;
|
||||
mExpectedClass = clazz;
|
||||
mExpectedBoolean = null;
|
||||
private ArgumentMatcher<Pair<Integer, Object>> pairMatches(int tag, Class clazz) {
|
||||
return pair -> pair.first == tag && Platform.isInstanceOfType(pair.second, clazz);
|
||||
}
|
||||
|
||||
public PairMatcher(int tag, boolean bool) {
|
||||
mExpectedTag = tag;
|
||||
mExpectedClass = Long.class;
|
||||
mExpectedBoolean = bool ? 1L : 0L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object arg) {
|
||||
final Pair<Integer, Object> pair = (Pair) arg;
|
||||
boolean booleanMatch = mExpectedBoolean == null
|
||||
|| mExpectedBoolean == pair.second;
|
||||
return pair.first == mExpectedTag
|
||||
&& Platform.isInstanceOfType(pair.second, mExpectedClass)
|
||||
&& booleanMatch;
|
||||
}
|
||||
private ArgumentMatcher<Pair<Integer, Object>> pairMatches(int tag, boolean bool) {
|
||||
return pair ->
|
||||
pair.first == tag
|
||||
&& Platform.isInstanceOfType(pair.second, Long.class)
|
||||
&& pair.second.equals((bool ? 1L : 0L));
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,17 @@
|
||||
*/
|
||||
package com.android.settings.core.instrumentation;
|
||||
|
||||
import static com.android.settings.core.instrumentation.Instrumentable.METRICS_CATEGORY_UNKNOWN;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -31,16 +42,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.android.settings.core.instrumentation.Instrumentable.METRICS_CATEGORY_UNKNOWN;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@@ -62,7 +63,7 @@ public class VisibilityLoggerMixinTest {
|
||||
mMixin.onResume();
|
||||
|
||||
verify(mMetricsFeature, times(1))
|
||||
.visible(any(Context.class), eq(MetricsProto.MetricsEvent.VIEW_UNKNOWN),
|
||||
.visible(nullable(Context.class), eq(MetricsProto.MetricsEvent.VIEW_UNKNOWN),
|
||||
eq(TestInstrumentable.TEST_METRIC));
|
||||
}
|
||||
|
||||
@@ -77,7 +78,7 @@ public class VisibilityLoggerMixinTest {
|
||||
mMixin.onResume();
|
||||
|
||||
verify(mMetricsFeature, times(1))
|
||||
.visible(any(Context.class), eq(MetricsProto.MetricsEvent.SETTINGS_GESTURES),
|
||||
.visible(nullable(Context.class), eq(MetricsProto.MetricsEvent.SETTINGS_GESTURES),
|
||||
eq(TestInstrumentable.TEST_METRIC));
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ public class VisibilityLoggerMixinTest {
|
||||
mMixin.onPause();
|
||||
|
||||
verify(mMetricsFeature, times(1))
|
||||
.hidden(any(Context.class), eq(TestInstrumentable.TEST_METRIC));
|
||||
.hidden(nullable(Context.class), eq(TestInstrumentable.TEST_METRIC));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,7 +97,7 @@ public class VisibilityLoggerMixinTest {
|
||||
mMixin.onPause();
|
||||
|
||||
verify(mMetricsFeature, never())
|
||||
.hidden(any(Context.class), anyInt());
|
||||
.hidden(nullable(Context.class), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,7 +108,7 @@ public class VisibilityLoggerMixinTest {
|
||||
mMixin.onPause();
|
||||
|
||||
verify(mMetricsFeature, never())
|
||||
.hidden(any(Context.class), anyInt());
|
||||
.hidden(nullable(Context.class), anyInt());
|
||||
}
|
||||
|
||||
private final class TestInstrumentable implements Instrumentable {
|
||||
|
@@ -15,6 +15,15 @@
|
||||
*/
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.preference.Preference;
|
||||
@@ -43,15 +52,6 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DashboardFragmentTest {
|
||||
@@ -75,9 +75,10 @@ public class DashboardFragmentTest {
|
||||
mDashboardCategory.tiles.add(new Tile());
|
||||
mTestFragment = new TestFragment(ShadowApplication.getInstance().getApplicationContext());
|
||||
when(mFakeFeatureFactory.dashboardFeatureProvider.getProgressiveDisclosureMixin(
|
||||
any(Context.class), eq(mTestFragment), any(Bundle.class)))
|
||||
nullable(Context.class), eq(mTestFragment), nullable(Bundle.class)))
|
||||
.thenReturn(mDisclosureMixin);
|
||||
when(mFakeFeatureFactory.dashboardFeatureProvider.getTilesForCategory(anyString()))
|
||||
when(mFakeFeatureFactory.dashboardFeatureProvider
|
||||
.getTilesForCategory(nullable(String.class)))
|
||||
.thenReturn(mDashboardCategory);
|
||||
mTestFragment.onAttach(ShadowApplication.getInstance().getApplicationContext());
|
||||
when(mContext.getPackageName()).thenReturn("TestPackage");
|
||||
@@ -96,21 +97,23 @@ public class DashboardFragmentTest {
|
||||
|
||||
@Test
|
||||
public void displayTilesAsPreference_shouldAddTilesWithIntent() {
|
||||
when(mFakeFeatureFactory.dashboardFeatureProvider.getTilesForCategory(anyString()))
|
||||
when(mFakeFeatureFactory.dashboardFeatureProvider
|
||||
.getTilesForCategory(nullable(String.class)))
|
||||
.thenReturn(mDashboardCategory);
|
||||
when(mFakeFeatureFactory.dashboardFeatureProvider.getDashboardKeyForTile(any(Tile.class)))
|
||||
when(mFakeFeatureFactory.dashboardFeatureProvider
|
||||
.getDashboardKeyForTile(nullable(Tile.class)))
|
||||
.thenReturn("test_key");
|
||||
mTestFragment.onCreatePreferences(new Bundle(), "rootKey");
|
||||
|
||||
verify(mDisclosureMixin).addPreference(any(PreferenceScreen.class),
|
||||
any(Preference.class));
|
||||
verify(mDisclosureMixin).addPreference(nullable(PreferenceScreen.class),
|
||||
nullable(Preference.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayTilesAsPreference_shouldNotAddTilesWithoutIntent() {
|
||||
mTestFragment.onCreatePreferences(new Bundle(), "rootKey");
|
||||
|
||||
verify(mTestFragment.mScreen, never()).addPreference(any(Preference.class));
|
||||
verify(mTestFragment.mScreen, never()).addPreference(nullable(Preference.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,7 +121,7 @@ public class DashboardFragmentTest {
|
||||
mDashboardCategory.tiles = null;
|
||||
mTestFragment.onCreatePreferences(new Bundle(), "rootKey");
|
||||
|
||||
verify(mTestFragment.mScreen, never()).addPreference(any(Preference.class));
|
||||
verify(mTestFragment.mScreen, never()).addPreference(nullable(Preference.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -40,6 +40,8 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
@@ -118,7 +120,7 @@ public class ProgressiveDisclosureTest {
|
||||
|
||||
@Test
|
||||
public void findPreference_prefInCollapsedList_shouldFindIt() {
|
||||
when(mScreen.findPreference(anyString())).thenReturn(null);
|
||||
when(mScreen.findPreference(nullable(String.class))).thenReturn(null);
|
||||
mMixin.addToCollapsedList(mPreference);
|
||||
|
||||
Preference pref = mMixin.findPreference(mScreen, mPreference.getKey());
|
||||
@@ -139,7 +141,7 @@ public class ProgressiveDisclosureTest {
|
||||
|
||||
@Test
|
||||
public void findPreference_prefNotInCollapsedListOrScreen_shouldNotFindIt() {
|
||||
when(mScreen.findPreference(anyString())).thenReturn(null);
|
||||
when(mScreen.findPreference(nullable(String.class))).thenReturn(null);
|
||||
Preference pref = mMixin.findPreference(mScreen, mPreference.getKey());
|
||||
|
||||
assertThat(pref).isNull();
|
||||
@@ -147,7 +149,7 @@ public class ProgressiveDisclosureTest {
|
||||
|
||||
@Test
|
||||
public void findPreference_prefRemovedFromCollapsedList_shouldNotFindIt() {
|
||||
when(mScreen.findPreference(anyString())).thenReturn(null);
|
||||
when(mScreen.findPreference(nullable(String.class))).thenReturn(null);
|
||||
mMixin.addToCollapsedList(mPreference);
|
||||
mMixin.removePreference(mPreferenceFragment.getPreferenceScreen(), mPreference.getKey());
|
||||
|
||||
@@ -158,7 +160,7 @@ public class ProgressiveDisclosureTest {
|
||||
|
||||
@Test
|
||||
public void findPreference_nestedPrefInCollapsedList_shouldFindIt() {
|
||||
when(mScreen.findPreference(anyString())).thenReturn(null);
|
||||
when(mScreen.findPreference(nullable(String.class))).thenReturn(null);
|
||||
final PreferenceScreen prefGroup = spy(new PreferenceScreen(mAppContext, null));
|
||||
when(prefGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
|
||||
final Preference preference = mock(Preference.class);
|
||||
@@ -183,7 +185,7 @@ public class ProgressiveDisclosureTest {
|
||||
|
||||
@Test
|
||||
public void removeLastPreference_shouldRemoveExpandButtonToo() {
|
||||
when(mScreen.findPreference(anyString())).thenReturn(null);
|
||||
when(mScreen.findPreference(nullable(String.class))).thenReturn(null);
|
||||
mMixin.addToCollapsedList(mPreference);
|
||||
// Collapsed
|
||||
assertThat(mMixin.isCollapsed()).isTrue();
|
||||
@@ -204,7 +206,7 @@ public class ProgressiveDisclosureTest {
|
||||
|
||||
mMixin.collapse(screen);
|
||||
assertThat(mMixin.isCollapsed()).isFalse();
|
||||
verify(mExpandButton, never()).setSummary(anyString());
|
||||
verify(mExpandButton, never()).setSummary(nullable(String.class));
|
||||
verify(screen, never()).addPreference(any(Preference.class));
|
||||
verify(screen, never()).removePreference(any(Preference.class));
|
||||
}
|
||||
@@ -219,7 +221,7 @@ public class ProgressiveDisclosureTest {
|
||||
mMixin.collapse(screen);
|
||||
|
||||
assertThat(mMixin.isCollapsed()).isTrue();
|
||||
verify(mExpandButton, atLeastOnce()).setSummary(anyString());
|
||||
verify(mExpandButton, atLeastOnce()).setSummary(nullable(String.class));
|
||||
verify(screen).addPreference(any(ExpandPreference.class));
|
||||
verify(screen, times(3)).removePreference(any(Preference.class));
|
||||
}
|
||||
@@ -264,7 +266,7 @@ public class ProgressiveDisclosureTest {
|
||||
lastPref.setOrder(100);
|
||||
// Add something to collapsed list so we are in collapsed state.
|
||||
mMixin.addToCollapsedList(new Preference(mAppContext));
|
||||
verify(mExpandButton).setSummary(anyString());
|
||||
verify(mExpandButton).setSummary(nullable(String.class));
|
||||
assertThat(mMixin.getCollapsedPrefs().size()).isEqualTo(1);
|
||||
|
||||
// 3 prefs on screen, 2 are real and the last one is more button.
|
||||
@@ -286,7 +288,7 @@ public class ProgressiveDisclosureTest {
|
||||
lastPref.setOrder(100);
|
||||
// Add something to collapsed list so we are in collapsed state.
|
||||
mMixin.addToCollapsedList(new Preference(mAppContext));
|
||||
verify(mExpandButton).setSummary(anyString());
|
||||
verify(mExpandButton).setSummary(nullable(String.class));
|
||||
assertThat(mMixin.getCollapsedPrefs().size()).isEqualTo(1);
|
||||
|
||||
// 3 prefs on screen, 2 are real and the last one is more button.
|
||||
@@ -299,7 +301,7 @@ public class ProgressiveDisclosureTest {
|
||||
|
||||
verify(mScreen, never()).removePreference(any(Preference.class));
|
||||
verify(mScreen, never()).addPreference(any(Preference.class));
|
||||
verify(mExpandButton, times(2)).setSummary(anyString());
|
||||
verify(mExpandButton, times(2)).setSummary(nullable(String.class));
|
||||
assertThat(mMixin.getCollapsedPrefs().get(0)).isSameAs(toBeAdded);
|
||||
}
|
||||
|
||||
|
@@ -16,6 +16,15 @@
|
||||
|
||||
package com.android.settings.dashboard.suggestions;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
@@ -35,14 +44,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SuggestionDismissControllerTest {
|
||||
@@ -110,7 +111,7 @@ public class SuggestionDismissControllerTest {
|
||||
mController.onSwiped(vh, ItemTouchHelper.START);
|
||||
|
||||
verify(mFactory.suggestionsFeatureProvider).dismissSuggestion(
|
||||
eq(mContext), eq(mSuggestionParser), any(Tile.class));
|
||||
verify(mCallback).onSuggestionDismissed(any(Tile.class));
|
||||
eq(mContext), eq(mSuggestionParser), nullable(Tile.class));
|
||||
verify(mCallback).onSuggestionDismissed(nullable(Tile.class));
|
||||
}
|
||||
}
|
||||
|
@@ -15,14 +15,22 @@
|
||||
*/
|
||||
package com.android.settings.datausage;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.os.Process;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -31,11 +39,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class UnrestrictedDataAccessTest {
|
||||
@@ -75,11 +78,11 @@ public class UnrestrictedDataAccessTest {
|
||||
@Test
|
||||
public void logSpecialPermissionChange() {
|
||||
mFragment.logSpecialPermissionChange(true, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_UNL_DATA_ALLOW), eq("app"));
|
||||
|
||||
mFragment.logSpecialPermissionChange(false, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_UNL_DATA_DENY), eq("app"));
|
||||
}
|
||||
|
||||
|
@@ -16,6 +16,11 @@
|
||||
|
||||
package com.android.settings.datetime;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -33,11 +38,6 @@ import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ZonePickerTest {
|
||||
@@ -64,8 +64,8 @@ public class ZonePickerTest {
|
||||
|
||||
// Should render
|
||||
verify(mZonePicker).onCreateView(
|
||||
any(LayoutInflater.class),
|
||||
any(ViewGroup.class),
|
||||
any(Bundle.class));
|
||||
nullable(LayoutInflater.class),
|
||||
nullable(ViewGroup.class),
|
||||
nullable(Bundle.class));
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,12 @@
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.usage.StorageStatsManager;
|
||||
import android.icu.text.NumberFormat;
|
||||
@@ -41,12 +47,6 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class StorageSettingsTest {
|
||||
@@ -78,10 +78,10 @@ public class StorageSettingsTest {
|
||||
when(volumeInfo.isMountedReadable()).thenReturn(true);
|
||||
when(volumeInfo.getType()).thenReturn(VolumeInfo.TYPE_PRIVATE);
|
||||
when(mStorageManagerVolumeProvider.getTotalBytes(
|
||||
any(StorageStatsManager.class), any(VolumeInfo.class)))
|
||||
nullable(StorageStatsManager.class), nullable(VolumeInfo.class)))
|
||||
.thenReturn(500L);
|
||||
when(mStorageManagerVolumeProvider.getFreeBytes(
|
||||
any(StorageStatsManager.class), any(VolumeInfo.class)))
|
||||
nullable(StorageStatsManager.class), nullable(VolumeInfo.class)))
|
||||
.thenReturn(0L);
|
||||
|
||||
ReflectionHelpers.setField(
|
||||
|
@@ -16,8 +16,13 @@
|
||||
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.usb.UsbManager;
|
||||
|
||||
@@ -27,17 +32,10 @@ import com.android.settings.TestConfig;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class UsbBackendTest {
|
||||
@@ -70,13 +68,7 @@ public class UsbBackendTest {
|
||||
usbBackend.getCurrentMode();
|
||||
|
||||
verify(mContext).registerReceiver(eq(null),
|
||||
argThat(new ArgumentMatcher<IntentFilter>() {
|
||||
@Override
|
||||
public boolean matches(Object i) {
|
||||
final IntentFilter intentFilter = (IntentFilter) i;
|
||||
return intentFilter != null &&
|
||||
UsbManager.ACTION_USB_STATE.equals(intentFilter.getAction(0));
|
||||
}
|
||||
}));
|
||||
argThat(intentFilter -> intentFilter != null &&
|
||||
UsbManager.ACTION_USB_STATE.equals(intentFilter.getAction(0))));
|
||||
}
|
||||
}
|
||||
|
@@ -16,11 +16,12 @@
|
||||
package com.android.settings.deviceinfo.storage;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -28,7 +29,6 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -119,7 +119,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
|
||||
any(UserHandle.class));
|
||||
nullable(UserHandle.class));
|
||||
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
assertThat(intent.getType()).isEqualTo("image/*");
|
||||
@@ -134,7 +134,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
|
||||
any(UserHandle.class));
|
||||
nullable(UserHandle.class));
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
|
||||
@@ -161,7 +161,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
|
||||
any(UserHandle.class));
|
||||
nullable(UserHandle.class));
|
||||
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
|
||||
@@ -182,20 +182,20 @@ public class StorageItemPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testClickFiles() {
|
||||
when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
|
||||
when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(mVolume);
|
||||
mPreference.setKey("pref_files");
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
|
||||
any(UserHandle.class));
|
||||
nullable(UserHandle.class));
|
||||
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
Intent browseIntent = mVolume.buildBrowseIntent();
|
||||
assertThat(intent.getAction()).isEqualTo(browseIntent.getAction());
|
||||
assertThat(intent.getData()).isEqualTo(browseIntent.getData());
|
||||
verify(mMetricsFeatureProvider, times(1)).action(
|
||||
any(Context.class), eq(MetricsEvent.STORAGE_FILES));
|
||||
nullable(Context.class), eq(MetricsEvent.STORAGE_FILES));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -205,7 +205,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
|
||||
any(UserHandle.class));
|
||||
nullable(UserHandle.class));
|
||||
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
|
||||
@@ -223,7 +223,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
|
||||
any(UserHandle.class));
|
||||
nullable(UserHandle.class));
|
||||
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
|
||||
@@ -240,7 +240,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
assertThat(mController.handlePreferenceTreeClick(mPreference)).isTrue();
|
||||
|
||||
verify(mFragment.getFragmentManager().beginTransaction()).add(
|
||||
any(PrivateVolumeSettings.SystemInfoFragment.class), anyString());
|
||||
nullable(PrivateVolumeSettings.SystemInfoFragment.class), nullable(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -329,13 +329,13 @@ public class StorageItemPreferenceControllerTest {
|
||||
|
||||
mController.setUserId(new UserHandle(10));
|
||||
|
||||
verify(audio, times(2)).setIcon(any(Drawable.class));
|
||||
verify(video, times(2)).setIcon(any(Drawable.class));
|
||||
verify(image, times(2)).setIcon(any(Drawable.class));
|
||||
verify(games, times(2)).setIcon(any(Drawable.class));
|
||||
verify(apps, times(2)).setIcon(any(Drawable.class));
|
||||
verify(system, times(2)).setIcon(any(Drawable.class));
|
||||
verify(files, times(2)).setIcon(any(Drawable.class));
|
||||
verify(audio, times(2)).setIcon(nullable(Drawable.class));
|
||||
verify(video, times(2)).setIcon(nullable(Drawable.class));
|
||||
verify(image, times(2)).setIcon(nullable(Drawable.class));
|
||||
verify(games, times(2)).setIcon(nullable(Drawable.class));
|
||||
verify(apps, times(2)).setIcon(nullable(Drawable.class));
|
||||
verify(system, times(2)).setIcon(nullable(Drawable.class));
|
||||
verify(files, times(2)).setIcon(nullable(Drawable.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -359,7 +359,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
|
||||
.thenReturn(files);
|
||||
|
||||
when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
|
||||
when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(mVolume);
|
||||
when(mVolume.isMountedReadable()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(screen);
|
||||
@@ -388,7 +388,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
|
||||
.thenReturn(files);
|
||||
|
||||
when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
|
||||
when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(mVolume);
|
||||
when(mVolume.isMountedReadable()).thenReturn(false);
|
||||
|
||||
mController.displayPreference(screen);
|
||||
@@ -417,7 +417,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
|
||||
.thenReturn(files);
|
||||
|
||||
when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(null);
|
||||
when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(null);
|
||||
|
||||
mController.displayPreference(screen);
|
||||
|
||||
@@ -445,11 +445,11 @@ public class StorageItemPreferenceControllerTest {
|
||||
when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
|
||||
.thenReturn(files);
|
||||
|
||||
when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
|
||||
when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(mVolume);
|
||||
when(mVolume.isMountedReadable()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(screen);
|
||||
when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(null);
|
||||
when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(null);
|
||||
mController.setVolume(mVolume);
|
||||
|
||||
verify(screen).removePreference(files);
|
||||
@@ -480,7 +480,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
// This will hide it initially.
|
||||
mController.displayPreference(screen);
|
||||
|
||||
when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
|
||||
when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(mVolume);
|
||||
when(mVolume.isMountedReadable()).thenReturn(true);
|
||||
|
||||
// And we bring it back.
|
||||
|
@@ -16,6 +16,14 @@
|
||||
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@@ -43,13 +51,6 @@ import org.robolectric.annotation.Config;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.anyObject;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link EnterpriseSetDefaultAppsPreferenceController}.
|
||||
*/
|
||||
@@ -81,7 +82,7 @@ public final class EnterpriseSetDefaultAppsPreferenceControllerTest {
|
||||
final List<UserAppInfo> apps = new ArrayList<>(number);
|
||||
apps.add(new UserAppInfo(new UserInfo(i, "user." + i, UserInfo.FLAG_ADMIN), appInfo));
|
||||
when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(eq(i),
|
||||
argThat(new MatchesIntents(intents)))).thenReturn(apps);
|
||||
argThat(matchesIntents(intents)))).thenReturn(apps);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +117,7 @@ public final class EnterpriseSetDefaultAppsPreferenceControllerTest {
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(anyInt(),
|
||||
anyObject())).thenReturn(new ArrayList<UserAppInfo>());
|
||||
any(Intent[].class))).thenReturn(new ArrayList<>());
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
|
||||
setEnterpriseSetDefaultApps(EnterpriseDefaultApps.BROWSER.getIntents(), 1);
|
||||
@@ -136,28 +137,20 @@ public final class EnterpriseSetDefaultAppsPreferenceControllerTest {
|
||||
.isEqualTo("number_enterprise_set_default_apps");
|
||||
}
|
||||
|
||||
private static class MatchesIntents extends ArgumentMatcher<Intent[]> {
|
||||
private final Intent[] mExpectedIntents;
|
||||
|
||||
MatchesIntents(Intent[] intents) {
|
||||
mExpectedIntents = intents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object object) {
|
||||
final Intent[] actualIntents = (Intent[]) object;
|
||||
private ArgumentMatcher<Intent[]> matchesIntents(Intent[] intents) {
|
||||
return (Intent[] actualIntents) -> {
|
||||
if (actualIntents == null) {
|
||||
return false;
|
||||
}
|
||||
if (actualIntents.length != mExpectedIntents.length) {
|
||||
if (actualIntents.length != intents.length) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < mExpectedIntents.length; i++) {
|
||||
if (!mExpectedIntents[i].filterEquals(actualIntents[i])) {
|
||||
for (int i = 0; i < intents.length; i++) {
|
||||
if (!intents[i].filterEquals(actualIntents[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -18,10 +18,9 @@ package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
@@ -30,6 +29,7 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -61,7 +61,6 @@ import org.mockito.Answers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
@@ -122,22 +121,26 @@ public class AdvancedPowerUsageDetailTest {
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
doReturn(mActivity).when(mFragment).getActivity();
|
||||
doReturn(SUMMARY).when(mFragment).getString(anyInt());
|
||||
doReturn(APP_LABEL).when(mBundle).getString(anyString());
|
||||
doReturn(APP_LABEL).when(mBundle).getString(nullable(String.class));
|
||||
doReturn(mBundle).when(mFragment).getArguments();
|
||||
|
||||
ShadowEntityHeaderController.setUseMock(mEntityHeaderController);
|
||||
doReturn(mEntityHeaderController).when(mEntityHeaderController)
|
||||
.setRecyclerView(any(RecyclerView.class), any(Lifecycle.class));
|
||||
.setRecyclerView(nullable(RecyclerView.class), nullable(Lifecycle.class));
|
||||
doReturn(mEntityHeaderController).when(mEntityHeaderController)
|
||||
.setButtonActions(anyInt(), anyInt());
|
||||
doReturn(mEntityHeaderController).when(mEntityHeaderController)
|
||||
.setIcon(any(Drawable.class));
|
||||
doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(any(
|
||||
.setIcon(nullable(Drawable.class));
|
||||
doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(
|
||||
ApplicationsState.AppEntry.class));
|
||||
doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(anyString());
|
||||
doReturn(mEntityHeaderController).when(mEntityHeaderController)
|
||||
.setLabel(any(ApplicationsState.AppEntry.class));
|
||||
doReturn(mEntityHeaderController).when(mEntityHeaderController).setSummary(anyString());
|
||||
.setLabel(nullable(String.class));
|
||||
doReturn(mEntityHeaderController).when(mEntityHeaderController)
|
||||
.setLabel(nullable(String.class));
|
||||
doReturn(mEntityHeaderController).when(mEntityHeaderController)
|
||||
.setLabel(nullable(ApplicationsState.AppEntry.class));
|
||||
doReturn(mEntityHeaderController).when(mEntityHeaderController)
|
||||
.setSummary(nullable(String.class));
|
||||
|
||||
doReturn(UID).when(mBatterySipper).getUid();
|
||||
doReturn(APP_LABEL).when(mBatteryEntry).getLabel();
|
||||
@@ -160,15 +163,13 @@ public class AdvancedPowerUsageDetailTest {
|
||||
|
||||
final ArgumentCaptor<Bundle> captor = ArgumentCaptor.forClass(Bundle.class);
|
||||
|
||||
Answer<Void> callable = new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Exception {
|
||||
Answer<Void> callable = invocation -> {
|
||||
mBundle = captor.getValue();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(any(), anyString(),
|
||||
captor.capture(), anyInt(), any(), any());
|
||||
doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(
|
||||
nullable(Fragment.class), nullable(String.class), captor.capture(), anyInt(),
|
||||
nullable(CharSequence.class), nullable(UserHandle.class));
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -181,7 +182,7 @@ public class AdvancedPowerUsageDetailTest {
|
||||
mFragment.mAppEntry = null;
|
||||
mFragment.initHeader();
|
||||
|
||||
verify(mEntityHeaderController).setIcon(any(Drawable.class));
|
||||
verify(mEntityHeaderController).setIcon(nullable(Drawable.class));
|
||||
verify(mEntityHeaderController).setLabel(APP_LABEL);
|
||||
}
|
||||
|
||||
@@ -281,21 +282,20 @@ public class AdvancedPowerUsageDetailTest {
|
||||
mBatteryEntry, USAGE_PERCENT);
|
||||
|
||||
verify(mTestActivity).startPreferencePanelAsUser(
|
||||
any(), anyString(), any(), anyInt(), any(), eq(new UserHandle(10)));
|
||||
nullable(Fragment.class), nullable(String.class), nullable(Bundle.class), anyInt(),
|
||||
nullable(CharSequence.class), eq(new UserHandle(10)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartBatteryDetailPage_noBatteryUsage_hasBasicData() {
|
||||
final ArgumentCaptor<Bundle> captor = ArgumentCaptor.forClass(Bundle.class);
|
||||
Answer<Void> callable = new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Exception {
|
||||
Answer<Void> callable = invocation -> {
|
||||
mBundle = captor.getValue();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(any(), anyString(),
|
||||
captor.capture(), anyInt(), any(), any());
|
||||
doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(nullable(Fragment.class),
|
||||
nullable(String.class), captor.capture(), anyInt(), nullable(CharSequence.class),
|
||||
nullable(UserHandle.class));
|
||||
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, PACKAGE_NAME[0]);
|
||||
|
||||
|
@@ -15,8 +15,13 @@
|
||||
*/
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.PowerManager;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -35,16 +40,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static org.mockito.AdditionalMatchers.not;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@@ -84,7 +79,7 @@ public class BatteryHistoryPreferenceTest {
|
||||
mBatteryHistoryPreference.onBindViewHolder(mViewHolder);
|
||||
|
||||
verify(mViewHolder).findViewById(R.id.battery_usage);
|
||||
verify(mTextView).setText(anyString());
|
||||
verify(mTextView).setText(nullable(String.class));
|
||||
verify(mBatteryInfo).bindHistory(mUsageView);
|
||||
}
|
||||
}
|
||||
|
@@ -18,10 +18,8 @@ package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -84,9 +82,9 @@ public class BatteryOptimizationPreferenceControllerTest {
|
||||
final boolean handled = mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(handled).isTrue();
|
||||
verify(mSettingsActivity).startPreferencePanel(any(Fragment.class),
|
||||
anyString(), any(Bundle.class), anyInt(), any(CharSequence.class),
|
||||
any(Fragment.class), anyInt());
|
||||
verify(mSettingsActivity).startPreferencePanel(nullable(Fragment.class),
|
||||
nullable(String.class), nullable(Bundle.class), anyInt(),
|
||||
nullable(CharSequence.class), nullable(Fragment.class), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,9 +94,9 @@ public class BatteryOptimizationPreferenceControllerTest {
|
||||
final boolean handled = mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(handled).isFalse();
|
||||
verify(mSettingsActivity, never()).startPreferencePanel(any(Fragment.class),
|
||||
anyString(), any(Bundle.class), anyInt(), any(CharSequence.class),
|
||||
any(Fragment.class), anyInt());
|
||||
verify(mSettingsActivity, never()).startPreferencePanel(nullable(Fragment.class),
|
||||
nullable(String.class), nullable(Bundle.class), anyInt(),
|
||||
nullable(CharSequence.class), nullable(Fragment.class), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -18,10 +18,9 @@ package com.android.settings.fuelgauge.anomaly.checker;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -101,9 +100,10 @@ public class WakeLockAnomalyDetectorTest {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
ReflectionHelpers.setField(mPolicy, "wakeLockThreshold", WAKELOCK_THRESHOLD_MS);
|
||||
|
||||
doReturn(false).when(mBatteryUtils).shouldHideSipper(any());
|
||||
doReturn(false).when(mBatteryUtils).shouldHideSipper(nullable(BatterySipper.class));
|
||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||
doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfo(anyString(), anyInt());
|
||||
doReturn(mApplicationInfo).when(mPackageManager)
|
||||
.getApplicationInfo(nullable(String.class), anyInt());
|
||||
|
||||
mAnomalySipper.uidObj = mAnomalyUid;
|
||||
mAnomalyWakelocks = new ArrayMap<>();
|
||||
|
@@ -15,6 +15,13 @@
|
||||
*/
|
||||
package com.android.settings.location;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -37,13 +44,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class LocationPreferenceControllerTest {
|
||||
@@ -75,7 +75,7 @@ public class LocationPreferenceControllerTest {
|
||||
public void updateState_shouldSetSummary() {
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setSummary(anyString());
|
||||
verify(mPreference).setSummary(nullable(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,7 +83,7 @@ public class LocationPreferenceControllerTest {
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updateSummary();
|
||||
|
||||
verify(mPreference).setSummary(anyString());
|
||||
verify(mPreference).setSummary(nullable(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -39,6 +39,8 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -85,7 +87,7 @@ public class NetworkDashboardFragmentTest {
|
||||
|
||||
mFragment.onCreateOptionsMenu(null, null);
|
||||
|
||||
verify(resetController).buildMenuItem(any(Menu.class));
|
||||
verify(resetController).buildMenuItem(nullable(Menu.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -16,6 +16,10 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
@@ -31,10 +35,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class NotificationAccessSettingsTest {
|
||||
@@ -56,12 +56,12 @@ public class NotificationAccessSettingsTest {
|
||||
@Test
|
||||
public void logSpecialPermissionChange() {
|
||||
mFragment.logSpecialPermissionChange(true, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_NOTIVIEW_ALLOW),
|
||||
eq("app"));
|
||||
|
||||
mFragment.logSpecialPermissionChange(false, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_NOTIVIEW_DENY),
|
||||
eq("app"));
|
||||
}
|
||||
|
@@ -16,8 +16,14 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.preference.SeekBarVolumizer;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
@@ -31,13 +37,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class VolumeSeekBarPreferenceControllerTest {
|
||||
@@ -56,7 +55,7 @@ public class VolumeSeekBarPreferenceControllerTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
when(mScreen.findPreference(nullable(String.class))).thenReturn(mPreference);
|
||||
mController =
|
||||
new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback);
|
||||
}
|
||||
|
@@ -16,6 +16,16 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
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.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
@@ -38,16 +48,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
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.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class WorkSoundPreferenceControllerTest {
|
||||
@@ -94,9 +94,9 @@ public class WorkSoundPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void isAvailable_managedProfileAndNotSingleVolume_shouldReturnTrue() {
|
||||
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
|
||||
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
|
||||
.thenReturn(UserHandle.myUserId());
|
||||
when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
|
||||
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
|
||||
when(mAudioHelper.isSingleVolume()).thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
@@ -104,9 +104,9 @@ public class WorkSoundPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void isAvailable_noManagedProfile_shouldReturnFalse() {
|
||||
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
|
||||
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
|
||||
.thenReturn(UserHandle.USER_NULL);
|
||||
when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
|
||||
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
|
||||
when(mAudioHelper.isSingleVolume()).thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
@@ -114,9 +114,9 @@ public class WorkSoundPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void isAvailable_singleVolume_shouldReturnFalse() {
|
||||
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
|
||||
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
|
||||
.thenReturn(UserHandle.myUserId());
|
||||
when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
|
||||
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
|
||||
when(mAudioHelper.isSingleVolume()).thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
@@ -128,7 +128,7 @@ public class WorkSoundPreferenceControllerTest {
|
||||
when(mAudioHelper.isSingleVolume()).thenReturn(false);
|
||||
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
|
||||
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
|
||||
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
|
||||
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
|
||||
.thenReturn(UserHandle.USER_NULL);
|
||||
|
||||
// When the fragment first displays, the category should not appear.
|
||||
@@ -137,7 +137,7 @@ public class WorkSoundPreferenceControllerTest {
|
||||
|
||||
// However, when a managed profile is added later, the category should appear.
|
||||
mController.onResume();
|
||||
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
|
||||
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
|
||||
.thenReturn(UserHandle.myUserId());
|
||||
mController.onManagedProfileAdded(UserHandle.myUserId());
|
||||
|
||||
@@ -150,9 +150,9 @@ public class WorkSoundPreferenceControllerTest {
|
||||
when(mAudioHelper.isSingleVolume()).thenReturn(false);
|
||||
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
|
||||
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
|
||||
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
|
||||
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
|
||||
.thenReturn(UserHandle.myUserId());
|
||||
when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
|
||||
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
|
||||
|
||||
// Which is in resumed state:
|
||||
mController.displayPreference(mScreen);
|
||||
@@ -161,7 +161,7 @@ public class WorkSoundPreferenceControllerTest {
|
||||
verify(mWorkCategory, times(2)).setVisible(true);
|
||||
|
||||
// When a managed profile is removed, the category should be hidden.
|
||||
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
|
||||
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
|
||||
.thenReturn(UserHandle.USER_NULL);
|
||||
mController.onManagedProfileRemoved(UserHandle.myUserId());
|
||||
|
||||
@@ -171,9 +171,9 @@ public class WorkSoundPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void displayPreference_isAvailable_shouldShowPreferenceCategory() {
|
||||
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
|
||||
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
|
||||
.thenReturn(UserHandle.myUserId());
|
||||
when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
|
||||
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
|
||||
when(mAudioHelper.isSingleVolume()).thenReturn(false);
|
||||
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
|
||||
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
|
||||
@@ -184,7 +184,7 @@ public class WorkSoundPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void displayPreference_notAvailable_shouldHidePreferenceCategory() {
|
||||
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
|
||||
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
|
||||
.thenReturn(UserHandle.USER_NULL);
|
||||
when(mAudioHelper.isSingleVolume()).thenReturn(true);
|
||||
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
|
||||
@@ -200,7 +200,7 @@ public class WorkSoundPreferenceControllerTest {
|
||||
|
||||
mController.onPreferenceChange(preference, "hello");
|
||||
|
||||
verify(preference).setSummary(anyString());
|
||||
verify(preference).setSummary(nullable(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -208,9 +208,9 @@ public class WorkSoundPreferenceControllerTest {
|
||||
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
|
||||
mController = new WorkSoundPreferenceController(mContext, mFragment, null, mAudioHelper);
|
||||
|
||||
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
|
||||
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
|
||||
.thenReturn(UserHandle.myUserId());
|
||||
when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
|
||||
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
|
||||
when(mAudioHelper.isSingleVolume()).thenReturn(false);
|
||||
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
|
||||
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
|
||||
@@ -234,9 +234,9 @@ public class WorkSoundPreferenceControllerTest {
|
||||
when(mAudioHelper.isSingleVolume()).thenReturn(false);
|
||||
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
|
||||
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
|
||||
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
|
||||
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
|
||||
.thenReturn(UserHandle.myUserId());
|
||||
when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(false);
|
||||
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(false);
|
||||
|
||||
// When resumed:
|
||||
mController.displayPreference(mScreen);
|
||||
@@ -256,9 +256,9 @@ public class WorkSoundPreferenceControllerTest {
|
||||
@Test
|
||||
public void onResume_shouldSetUserIdToPreference() {
|
||||
final int managedProfileUserId = 10;
|
||||
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
|
||||
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
|
||||
.thenReturn(managedProfileUserId);
|
||||
when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
|
||||
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
|
||||
when(mAudioHelper.isSingleVolume()).thenReturn(false);
|
||||
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
|
||||
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.password;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
@@ -209,7 +210,8 @@ public class ChooseLockGenericControllerTest {
|
||||
@Test
|
||||
public void upgradeQuality_noDpmRequirement_shouldReturnQuality() {
|
||||
doReturn(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED)
|
||||
.when(mDevicePolicyManager).getPasswordQuality(any(ComponentName.class), anyInt());
|
||||
.when(mDevicePolicyManager)
|
||||
.getPasswordQuality(nullable(ComponentName.class), anyInt());
|
||||
|
||||
int upgradedQuality = mController.upgradeQuality(
|
||||
DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC);
|
||||
@@ -220,7 +222,8 @@ public class ChooseLockGenericControllerTest {
|
||||
@Test
|
||||
public void upgradeQuality_dpmRequirement_shouldReturnRequiredQuality() {
|
||||
doReturn(DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC)
|
||||
.when(mDevicePolicyManager).getPasswordQuality(any(ComponentName.class), anyInt());
|
||||
.when(mDevicePolicyManager)
|
||||
.getPasswordQuality(nullable(ComponentName.class), anyInt());
|
||||
|
||||
int upgradedQuality = mController.upgradeQuality(
|
||||
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
|
||||
|
@@ -17,6 +17,10 @@
|
||||
|
||||
package com.android.settings.search;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -36,10 +40,6 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SavedQueryViewHolderTest {
|
||||
@@ -71,7 +71,7 @@ public class SavedQueryViewHolderTest {
|
||||
mTitleView.performClick();
|
||||
mRemoveButton.performClick();
|
||||
|
||||
verify(mSearchFragment).onSavedQueryClicked(any(CharSequence.class));
|
||||
verify(mSearchFragment).onRemoveSavedQueryClicked(any(CharSequence.class));
|
||||
verify(mSearchFragment).onSavedQueryClicked(nullable(CharSequence.class));
|
||||
verify(mSearchFragment).onRemoveSavedQueryClicked(nullable(CharSequence.class));
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ package com.android.settings.wifi.details;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
@@ -158,7 +159,7 @@ public class WifiDetailPreferenceControllerTest {
|
||||
when(mockConnectivityManager.getNetworkInfo(any(Network.class)))
|
||||
.thenReturn(mockNetworkInfo);
|
||||
doNothing().when(mockConnectivityManagerWrapper).registerNetworkCallback(
|
||||
any(NetworkRequest.class), mCallbackCaptor.capture(), any(Handler.class));
|
||||
nullable(NetworkRequest.class), mCallbackCaptor.capture(), nullable(Handler.class));
|
||||
doNothing().when(mockForgetButton).setOnClickListener(mForgetClickListener.capture());
|
||||
|
||||
when(mockWifiInfo.getLinkSpeed()).thenReturn(LINK_SPEED);
|
||||
@@ -254,7 +255,7 @@ public class WifiDetailPreferenceControllerTest {
|
||||
mController.onResume();
|
||||
|
||||
verify(mockConnectivityManagerWrapper, times(1)).registerNetworkCallback(
|
||||
any(NetworkRequest.class), mCallbackCaptor.capture(), any(Handler.class));
|
||||
nullable(NetworkRequest.class), mCallbackCaptor.capture(), nullable(Handler.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user