Use external/robolectric-shadows/run_robotests.mk
This allows Settings to test against the latest framework changes. Also replaced TestConfig with traditional robolectric.properties. Bug: 73173204 Bug: 73892008 Test: make -j56 RunSettingsRoboTests Change-Id: I3135b4fa5f095ba79b282a76f45dd9baa2584bc7
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -31,10 +30,8 @@ import android.os.UserManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
@@ -44,20 +41,15 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = SettingsShadowResources.class)
|
||||
public class BluetoothDevicePreferenceTest {
|
||||
private static final boolean SHOW_DEVICES_WITHOUT_NAMES = true;
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||
@Mock
|
||||
private DeviceListPreferenceFragment mDeviceListPreferenceFragment;
|
||||
|
||||
private FakeFeatureFactory mFakeFeatureFactory;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@@ -79,8 +71,8 @@ public class BluetoothDevicePreferenceTest {
|
||||
|
||||
mPreference.onClicked();
|
||||
|
||||
verify(mMetricsFeatureProvider).action(
|
||||
mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT);
|
||||
verify(mMetricsFeatureProvider)
|
||||
.action(mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,8 +82,8 @@ public class BluetoothDevicePreferenceTest {
|
||||
|
||||
mPreference.onClicked();
|
||||
|
||||
verify(mMetricsFeatureProvider).action(
|
||||
mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT);
|
||||
verify(mMetricsFeatureProvider)
|
||||
.action(mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,10 +95,10 @@ public class BluetoothDevicePreferenceTest {
|
||||
|
||||
mPreference.onClicked();
|
||||
|
||||
verify(mMetricsFeatureProvider).action(
|
||||
mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
|
||||
verify(mMetricsFeatureProvider, never()).action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR_DEVICES_WITHOUT_NAMES);
|
||||
verify(mMetricsFeatureProvider)
|
||||
.action(mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
|
||||
verify(mMetricsFeatureProvider, never())
|
||||
.action(mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR_DEVICES_WITHOUT_NAMES);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,10 +110,10 @@ public class BluetoothDevicePreferenceTest {
|
||||
|
||||
mPreference.onClicked();
|
||||
|
||||
verify(mMetricsFeatureProvider).action(
|
||||
mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
|
||||
verify(mMetricsFeatureProvider).action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR_DEVICES_WITHOUT_NAMES);
|
||||
verify(mMetricsFeatureProvider)
|
||||
.action(mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
|
||||
verify(mMetricsFeatureProvider)
|
||||
.action(mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR_DEVICES_WITHOUT_NAMES);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,8 +139,7 @@ public class BluetoothDevicePreferenceTest {
|
||||
public void shouldHideSecondTarget_hasUserRestriction_shouldReturnTrue() {
|
||||
final UserManager um = mock(UserManager.class);
|
||||
ReflectionHelpers.setField(mPreference, "mUserManager", um);
|
||||
when(um.hasUserRestriction(UserManager.DISALLOW_CONFIG_BLUETOOTH))
|
||||
.thenReturn(true);
|
||||
when(um.hasUserRestriction(UserManager.DISALLOW_CONFIG_BLUETOOTH)).thenReturn(true);
|
||||
|
||||
assertThat(mPreference.shouldHideSecondTarget()).isTrue();
|
||||
}
|
||||
@@ -158,18 +149,17 @@ public class BluetoothDevicePreferenceTest {
|
||||
when(mCachedBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||
final UserManager um = mock(UserManager.class);
|
||||
ReflectionHelpers.setField(mPreference, "mUserManager", um);
|
||||
when(um.hasUserRestriction(UserManager.DISALLOW_CONFIG_BLUETOOTH))
|
||||
.thenReturn(false);
|
||||
when(um.hasUserRestriction(UserManager.DISALLOW_CONFIG_BLUETOOTH)).thenReturn(false);
|
||||
|
||||
assertThat(mPreference.shouldHideSecondTarget()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imagingDeviceIcon_isICSettingsPrint() {
|
||||
when(mCachedBluetoothDevice.getBatteryLevel()).thenReturn(
|
||||
BluetoothDevice.BATTERY_LEVEL_UNKNOWN);
|
||||
when(mCachedBluetoothDevice.getBtClass()).thenReturn(
|
||||
new BluetoothClass(BluetoothClass.Device.Major.IMAGING));
|
||||
when(mCachedBluetoothDevice.getBatteryLevel())
|
||||
.thenReturn(BluetoothDevice.BATTERY_LEVEL_UNKNOWN);
|
||||
when(mCachedBluetoothDevice.getBtClass())
|
||||
.thenReturn(new BluetoothClass(BluetoothClass.Device.Major.IMAGING));
|
||||
|
||||
mPreference.onDeviceAttributesChanged();
|
||||
assertThat(mPreference.getIcon()).isEqualTo(
|
||||
@@ -190,8 +180,7 @@ public class BluetoothDevicePreferenceTest {
|
||||
public void testVisible_hideDeviceWithoutNames_invisible() {
|
||||
doReturn(false).when(mCachedBluetoothDevice).hasHumanReadableName();
|
||||
BluetoothDevicePreference preference =
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
false);
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, false);
|
||||
|
||||
assertThat(preference.isVisible()).isFalse();
|
||||
}
|
||||
|
Reference in New Issue
Block a user