Remove more wrappers in favor of new Robolectric support
Bug: 76167422 Test: robotests Change-Id: Ic71a181bee6f90f25f9fa2a748cf708887495394
This commit is contained in:
@@ -6,7 +6,7 @@ import android.content.Context;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowPowerManagerWrapper;
|
||||
import com.android.settings.testutils.shadow.ShadowPowerManager;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
public class DisplaySettingsTest {
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowPowerManagerWrapper.class)
|
||||
@Config(shadows = ShadowPowerManager.class)
|
||||
public void testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen() {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
final DisplaySettings fragment = new DisplaySettings();
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.connecteddevice.usb;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -30,8 +29,6 @@ import android.hardware.usb.UsbPortStatus;
|
||||
import android.net.ConnectivityManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.UsbManagerWrapper;
|
||||
import com.android.settings.wrapper.UserManagerWrapper;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -50,8 +47,6 @@ public class UsbBackendTest {
|
||||
@Mock
|
||||
private UserManagerWrapper mUserManagerWrapper;
|
||||
@Mock
|
||||
private UsbManagerWrapper mUsbManagerWrapper;
|
||||
@Mock
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
@Mock
|
||||
private UsbPort mUsbPort;
|
||||
@@ -62,26 +57,18 @@ public class UsbBackendTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI))
|
||||
.thenReturn(true);
|
||||
when((Object)mContext.getSystemService(UsbManager.class)).thenReturn(mUsbManager);
|
||||
.thenReturn(true);
|
||||
when((Object) mContext.getSystemService(UsbManager.class)).thenReturn(mUsbManager);
|
||||
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
|
||||
.thenReturn(mConnectivityManager);
|
||||
when(mUsbManager.getPorts()).thenReturn(new UsbPort[]{ mUsbPort });
|
||||
when(mUsbManager.getPorts()).thenReturn(new UsbPort[] {mUsbPort});
|
||||
when(mUsbPortStatus.isConnected()).thenReturn(true);
|
||||
when(mUsbManager.getPortStatus(mUsbPort)).thenReturn(mUsbPortStatus);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_noUsbPort_shouldNotCrash() {
|
||||
final UsbBackend usbBackend =
|
||||
new UsbBackend(mContext, mUserManagerWrapper, mUsbManagerWrapper);
|
||||
// Should not crash
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDataRole_allRolesSupported_shouldSetDataRole() {
|
||||
final UsbBackend usbBackend =
|
||||
new UsbBackend(mContext, mUserManagerWrapper, mUsbManagerWrapper);
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
|
||||
|
||||
when(mUsbPortStatus
|
||||
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
|
||||
@@ -104,8 +91,7 @@ public class UsbBackendTest {
|
||||
|
||||
@Test
|
||||
public void setDataRole_notAllRolesSupported_shouldSetDataAndPowerRole() {
|
||||
final UsbBackend usbBackend =
|
||||
new UsbBackend(mContext, mUserManagerWrapper, mUsbManagerWrapper);
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
|
||||
|
||||
when(mUsbPortStatus
|
||||
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
|
||||
@@ -123,8 +109,7 @@ public class UsbBackendTest {
|
||||
|
||||
@Test
|
||||
public void setPowerRole_allRolesSupported_shouldSetPowerRole() {
|
||||
final UsbBackend usbBackend =
|
||||
new UsbBackend(mContext, mUserManagerWrapper, mUsbManagerWrapper);
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
|
||||
|
||||
when(mUsbPortStatus
|
||||
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
|
||||
@@ -148,8 +133,7 @@ public class UsbBackendTest {
|
||||
|
||||
@Test
|
||||
public void setPowerRole_notAllRolesSupported_shouldSetDataAndPowerRole() {
|
||||
final UsbBackend usbBackend =
|
||||
new UsbBackend(mContext, mUserManagerWrapper, mUsbManagerWrapper);
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
|
||||
|
||||
when(mUsbPortStatus
|
||||
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
|
||||
@@ -170,8 +154,7 @@ public class UsbBackendTest {
|
||||
when(mUserManagerWrapper.isUsbFileTransferRestricted()).thenReturn(true);
|
||||
when(mUserManagerWrapper.isUsbFileTransferRestrictedBySystem()).thenReturn(true);
|
||||
|
||||
final UsbBackend usbBackend =
|
||||
new UsbBackend(mContext, mUserManagerWrapper, mUsbManagerWrapper);
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
|
||||
|
||||
assertThat(usbBackend.areFunctionsSupported(UsbManager.FUNCTION_MTP)).isFalse();
|
||||
}
|
||||
@@ -181,8 +164,7 @@ public class UsbBackendTest {
|
||||
when(mUserManagerWrapper.isUsbFileTransferRestricted()).thenReturn(false);
|
||||
when(mUserManagerWrapper.isUsbFileTransferRestrictedBySystem()).thenReturn(false);
|
||||
|
||||
final UsbBackend usbBackend =
|
||||
new UsbBackend(mContext, mUserManagerWrapper, mUsbManagerWrapper);
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
|
||||
|
||||
assertThat(usbBackend.areFunctionsSupported(UsbManager.FUNCTION_MTP)).isTrue();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.display;
|
||||
|
||||
import static android.content.Context.POWER_SERVICE;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
@@ -26,12 +27,12 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings.System;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.PowerManagerWrapper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -40,13 +41,14 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.shadows.ShadowContentResolver;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class BrightnessLevelPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PowerManagerWrapper mPowerManager;
|
||||
private PowerManager mPowerManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
@@ -67,8 +69,10 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
when(mPowerManager.getMaximumScreenBrightnessSetting()).thenReturn(100);
|
||||
when(mPowerManager.getMinimumScreenBrightnessForVrSetting()).thenReturn(0);
|
||||
when(mPowerManager.getMaximumScreenBrightnessForVrSetting()).thenReturn(100);
|
||||
ShadowApplication.getInstance().setSystemService(POWER_SERVICE,
|
||||
mPowerManager);
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
mController = spy(new BrightnessLevelPreferenceController(mContext, null, mPowerManager));
|
||||
mController = spy(new BrightnessLevelPreferenceController(mContext, null));
|
||||
doReturn(false).when(mController).isInVrMode();
|
||||
}
|
||||
|
||||
@@ -80,23 +84,23 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
@Test
|
||||
public void onStart_shouldRegisterObserver() {
|
||||
BrightnessLevelPreferenceController controller =
|
||||
new BrightnessLevelPreferenceController(mContext, null, mPowerManager);
|
||||
new BrightnessLevelPreferenceController(mContext, null);
|
||||
ShadowContentResolver shadowContentResolver = Shadow.extract(mContentResolver);
|
||||
|
||||
controller.onStart();
|
||||
|
||||
assertThat(shadowContentResolver.getContentObservers(
|
||||
System.getUriFor(System.SCREEN_BRIGHTNESS))).isNotEmpty();
|
||||
System.getUriFor(System.SCREEN_BRIGHTNESS))).isNotEmpty();
|
||||
assertThat(shadowContentResolver.getContentObservers(
|
||||
System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR))).isNotEmpty();
|
||||
System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR))).isNotEmpty();
|
||||
assertThat(shadowContentResolver.getContentObservers(
|
||||
System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ))).isNotEmpty();
|
||||
System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ))).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStop_shouldUnregisterObserver() {
|
||||
BrightnessLevelPreferenceController controller =
|
||||
new BrightnessLevelPreferenceController(mContext, null, mPowerManager);
|
||||
new BrightnessLevelPreferenceController(mContext, null);
|
||||
ShadowContentResolver shadowContentResolver = Shadow.extract(mContext.getContentResolver());
|
||||
|
||||
controller.displayPreference(mScreen);
|
||||
@@ -104,11 +108,11 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
controller.onStop();
|
||||
|
||||
assertThat(shadowContentResolver.getContentObservers(
|
||||
System.getUriFor(System.SCREEN_BRIGHTNESS))).isEmpty();
|
||||
System.getUriFor(System.SCREEN_BRIGHTNESS))).isEmpty();
|
||||
assertThat(shadowContentResolver.getContentObservers(
|
||||
System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR))).isEmpty();
|
||||
System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR))).isEmpty();
|
||||
assertThat(shadowContentResolver.getContentObservers(
|
||||
System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ))).isEmpty();
|
||||
System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ))).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,7 +129,7 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
public void updateState_autoBrightness_shouldSetSummaryToAutoBrightness() {
|
||||
doReturn(false).when(mController).isInVrMode();
|
||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
|
||||
System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
|
||||
System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
|
||||
|
||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS, 31);
|
||||
|
||||
@@ -138,7 +142,7 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
public void updateState_manualBrightness_shouldSetSummaryToScreenBrightness() {
|
||||
doReturn(false).when(mController).isInVrMode();
|
||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
|
||||
System.SCREEN_BRIGHTNESS_MODE_MANUAL);
|
||||
System.SCREEN_BRIGHTNESS_MODE_MANUAL);
|
||||
|
||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS, 45);
|
||||
|
||||
|
||||
@@ -34,14 +34,12 @@ import android.printservice.PrintServiceInfo;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.PrintManagerWrapper;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
@@ -55,12 +53,13 @@ import java.util.List;
|
||||
public class PrintSettingsPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PrintManagerWrapper mPrintManager;
|
||||
private PrintManager mPrintManager;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private RestrictedPreference mPreference;
|
||||
|
||||
private Context mContext;
|
||||
private PrintSettingPreferenceController mController;
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private Lifecycle mLifecycle;
|
||||
@@ -83,7 +82,7 @@ public class PrintSettingsPreferenceControllerTest {
|
||||
mLifecycle.handleLifecycleEvent(ON_START);
|
||||
mLifecycle.handleLifecycleEvent(ON_STOP);
|
||||
|
||||
verify(mPrintManager).addPrintJobStateChanegListener(mController);
|
||||
verify(mPrintManager).addPrintJobStateChangeListener(mController);
|
||||
verify(mPrintManager).removePrintJobStateChangeListener(mController);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,18 +16,18 @@
|
||||
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.content.ComponentName;
|
||||
|
||||
import com.android.settings.wrapper.AccessibilityServiceInfoWrapper;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
@Implements(AccessibilityServiceInfoWrapper.class)
|
||||
public class ShadowAccessibilityServiceInfoWrapperImpl {
|
||||
|
||||
@Implements(AccessibilityServiceInfo.class)
|
||||
public class ShadowAccessibilityServiceInfo {
|
||||
private static ComponentName sComponentName;
|
||||
|
||||
public static void setComponentName(String componentName) {
|
||||
sComponentName = ComponentName.unflattenFromString(componentName);;
|
||||
sComponentName = ComponentName.unflattenFromString(componentName);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
@@ -17,12 +17,13 @@
|
||||
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import com.android.settings.wrapper.PowerManagerWrapper;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
@Implements(PowerManagerWrapper.class)
|
||||
public class ShadowPowerManagerWrapper {
|
||||
@Implements(PowerManager.class)
|
||||
public class ShadowPowerManager {
|
||||
|
||||
@Implementation
|
||||
public int getMinimumScreenBrightnessSetting() {
|
||||
@@ -23,11 +23,11 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WifiManager.ActionListener;
|
||||
import android.os.Handler;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.WifiManagerWrapper;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -40,12 +40,18 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class SavedAccessPointsWifiSettingsTest {
|
||||
|
||||
@Mock private WifiManagerWrapper mockWifiManager;
|
||||
@Mock private WifiDialog mockWifiDialog;
|
||||
@Mock private WifiConfigController mockConfigController;
|
||||
@Mock private WifiConfiguration mockWifiConfiguration;
|
||||
@Mock private AccessPoint mockAccessPoint;
|
||||
@Mock private Handler mHandler;
|
||||
@Mock
|
||||
private WifiManager mockWifiManager;
|
||||
@Mock
|
||||
private WifiDialog mockWifiDialog;
|
||||
@Mock
|
||||
private WifiConfigController mockConfigController;
|
||||
@Mock
|
||||
private WifiConfiguration mockWifiConfiguration;
|
||||
@Mock
|
||||
private AccessPoint mockAccessPoint;
|
||||
@Mock
|
||||
private Handler mHandler;
|
||||
|
||||
private SavedAccessPointsWifiSettings mSettings;
|
||||
|
||||
@@ -97,6 +103,6 @@ public class SavedAccessPointsWifiSettingsTest {
|
||||
when(mockAccessPoint.getConfig()).thenReturn(mockWifiConfiguration);
|
||||
mSettings.onForget(mockWifiDialog);
|
||||
verify(mockWifiManager)
|
||||
.forget(eq(mockWifiConfiguration.networkId), any(ActionListener.class));
|
||||
.forget(eq(mockWifiConfiguration.networkId), any(ActionListener.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowNfcAdapter;
|
||||
import com.android.settings.wrapper.WifiManagerWrapper;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -42,9 +42,9 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
public class WriteWifiConfigToNfcDialogTest {
|
||||
|
||||
@Mock
|
||||
Activity mActivity;
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
WifiManagerWrapper mWifiManager;
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
private WriteWifiConfigToNfcDialog mWriteWifiConfigToNfcDialog;
|
||||
|
||||
@@ -56,7 +56,8 @@ public class WriteWifiConfigToNfcDialogTest {
|
||||
.thenReturn(ReflectionHelpers.newInstance(InputMethodManager.class));
|
||||
|
||||
mWriteWifiConfigToNfcDialog = new WriteWifiConfigToNfcDialog(RuntimeEnvironment.application,
|
||||
0 /* security */, mWifiManager);
|
||||
0 /* security */);
|
||||
ReflectionHelpers.setField(mWriteWifiConfigToNfcDialog, "mWifiManager", mWifiManager);
|
||||
mWriteWifiConfigToNfcDialog.setOwnerActivity(mActivity);
|
||||
mWriteWifiConfigToNfcDialog.onCreate(null /* savedInstanceState */);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user