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.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
@@ -29,7 +28,6 @@ import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
|
||||
@@ -38,11 +36,10 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AlwaysDiscoverableTest {
|
||||
|
||||
@Mock
|
||||
private LocalBluetoothAdapter mLocalAdapter;
|
||||
|
||||
@@ -100,14 +97,14 @@ public class AlwaysDiscoverableTest {
|
||||
@Test
|
||||
public void resetsToDiscoverableModeWhenScanModeChanges() {
|
||||
mAlwaysDiscoverable.start();
|
||||
verify(mLocalAdapter, times(1)).setScanMode(
|
||||
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
verify(mLocalAdapter, times(1))
|
||||
.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
|
||||
sendScanModeChangedIntent(BluetoothAdapter.SCAN_MODE_CONNECTABLE,
|
||||
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
|
||||
verify(mLocalAdapter, times(2)).setScanMode(
|
||||
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
verify(mLocalAdapter, times(2))
|
||||
.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
}
|
||||
|
||||
private void sendScanModeChangedIntent(int newMode, int previousMode) {
|
||||
|
@@ -30,7 +30,6 @@ import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
@@ -43,8 +42,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = SettingsShadowBluetoothDevice.class)
|
||||
@Config(shadows = SettingsShadowBluetoothDevice.class)
|
||||
public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsControllerTestBase {
|
||||
private BluetoothDetailsButtonsController mController;
|
||||
private ActionButtonPreference mButtonsPref;
|
||||
@@ -58,8 +56,8 @@ public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsContr
|
||||
RuntimeEnvironment.application, R.layout.two_action_buttons, null /* parent */);
|
||||
mConnectButton = buttons.findViewById(R.id.button2_positive);
|
||||
mForgetButton = buttons.findViewById(R.id.button1_positive);
|
||||
mController = new BluetoothDetailsButtonsController(mContext, mFragment, mCachedDevice,
|
||||
mLifecycle);
|
||||
mController =
|
||||
new BluetoothDetailsButtonsController(mContext, mFragment, mCachedDevice, mLifecycle);
|
||||
mButtonsPref = ActionButtonPreferenceTest.createMock();
|
||||
when(mButtonsPref.getKey()).thenReturn(mController.getPreferenceKey());
|
||||
when(mButtonsPref.setButton2OnClickListener(any(View.OnClickListener.class)))
|
||||
|
@@ -26,7 +26,6 @@ import android.support.v14.preference.PreferenceFragment;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -36,34 +35,13 @@ import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows=SettingsShadowBluetoothDevice.class)
|
||||
@Config(shadows = SettingsShadowBluetoothDevice.class)
|
||||
public class BluetoothDetailsControllerEventsTest extends BluetoothDetailsControllerTestBase {
|
||||
|
||||
static class TestController extends BluetoothDetailsController {
|
||||
public TestController(Context context, PreferenceFragment fragment,
|
||||
CachedBluetoothDevice device,
|
||||
Lifecycle lifecycle) {
|
||||
super(context, fragment, device, lifecycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(PreferenceScreen screen) {}
|
||||
|
||||
@Override
|
||||
protected void refresh() {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pauseResumeEvents() {
|
||||
|
||||
TestController controller = spy(new TestController(mContext, mFragment, mCachedDevice,
|
||||
mLifecycle));
|
||||
TestController controller =
|
||||
spy(new TestController(mContext, mFragment, mCachedDevice, mLifecycle));
|
||||
verify(mLifecycle).addObserver(any(BluetoothDetailsController.class));
|
||||
|
||||
showScreen(controller);
|
||||
@@ -81,4 +59,22 @@ public class BluetoothDetailsControllerEventsTest extends BluetoothDetailsContro
|
||||
// The init function should only have been called once
|
||||
verify(controller, times(1)).init(mScreen);
|
||||
}
|
||||
|
||||
private static class TestController extends BluetoothDetailsController {
|
||||
private TestController(Context context, PreferenceFragment fragment,
|
||||
CachedBluetoothDevice device, Lifecycle lifecycle) {
|
||||
super(context, fragment, device, lifecycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(PreferenceScreen screen) {}
|
||||
|
||||
@Override
|
||||
protected void refresh() {}
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,6 @@ import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -39,11 +38,10 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothDetailsControllerTestBase {
|
||||
|
||||
protected Context mContext;
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
protected Lifecycle mLifecycle;
|
||||
@@ -82,58 +80,60 @@ public class BluetoothDetailsControllerTestBase {
|
||||
}
|
||||
|
||||
protected static class DeviceConfig {
|
||||
|
||||
private String name;
|
||||
private String address;
|
||||
private int majorDeviceClass;
|
||||
private boolean connected;
|
||||
private String connectionSummary;
|
||||
|
||||
public DeviceConfig setName(String newValue) {
|
||||
DeviceConfig setName(String newValue) {
|
||||
this.name = newValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeviceConfig setAddress(String newValue) {
|
||||
DeviceConfig setAddress(String newValue) {
|
||||
this.address = newValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeviceConfig setMajorDeviceClass(int newValue) {
|
||||
DeviceConfig setMajorDeviceClass(int newValue) {
|
||||
this.majorDeviceClass = newValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeviceConfig setConnected(boolean newValue) {
|
||||
DeviceConfig setConnected(boolean newValue) {
|
||||
this.connected = newValue;
|
||||
return this;
|
||||
}
|
||||
public DeviceConfig setConnectionSummary(String connectionSummary) {
|
||||
|
||||
DeviceConfig setConnectionSummary(String connectionSummary) {
|
||||
this.connectionSummary = connectionSummary;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public int getMajorDeviceClass() {
|
||||
int getMajorDeviceClass() {
|
||||
return majorDeviceClass;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
boolean isConnected() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
public String getConnectionSummary() {
|
||||
String getConnectionSummary() {
|
||||
return connectionSummary;
|
||||
}
|
||||
}
|
||||
|
||||
protected DeviceConfig makeDefaultDeviceConfig() {
|
||||
DeviceConfig makeDefaultDeviceConfig() {
|
||||
return new DeviceConfig()
|
||||
.setName("Mock Device")
|
||||
.setAddress("B4:B0:34:B5:3B:1B")
|
||||
@@ -144,9 +144,8 @@ public class BluetoothDetailsControllerTestBase {
|
||||
|
||||
/**
|
||||
* Sets up the device mock to return various state based on a test config.
|
||||
* @param config
|
||||
*/
|
||||
protected void setupDevice(DeviceConfig config) {
|
||||
void setupDevice(DeviceConfig config) {
|
||||
when(mCachedDevice.getName()).thenReturn(config.getName());
|
||||
when(mBluetoothDeviceClass.getMajorDeviceClass()).thenReturn(config.getMajorDeviceClass());
|
||||
when(mCachedDevice.isConnected()).thenReturn(config.isConnected());
|
||||
@@ -160,7 +159,7 @@ public class BluetoothDetailsControllerTestBase {
|
||||
/**
|
||||
* Convenience method to call displayPreference and onResume.
|
||||
*/
|
||||
protected void showScreen(BluetoothDetailsController controller) {
|
||||
void showScreen(BluetoothDetailsController controller) {
|
||||
controller.displayPreference(mScreen);
|
||||
controller.onResume();
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -26,12 +25,10 @@ import static org.mockito.Mockito.when;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
|
||||
@@ -45,11 +42,9 @@ import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {SettingsShadowBluetoothDevice.class, ShadowEntityHeaderController.class,
|
||||
SettingsShadowResources.class})
|
||||
@Config(shadows = {SettingsShadowBluetoothDevice.class, ShadowEntityHeaderController.class})
|
||||
public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsControllerTestBase {
|
||||
|
||||
private BluetoothDetailsHeaderController mController;
|
||||
private LayoutPreference mPreference;
|
||||
|
||||
@@ -61,8 +56,8 @@ public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsContro
|
||||
super.setUp();
|
||||
FakeFeatureFactory.setupForTest();
|
||||
ShadowEntityHeaderController.setUseMock(mHeaderController);
|
||||
mController = new BluetoothDetailsHeaderController(mContext, mFragment, mCachedDevice,
|
||||
mLifecycle);
|
||||
mController =
|
||||
new BluetoothDetailsHeaderController(mContext, mFragment, mCachedDevice, mLifecycle);
|
||||
mPreference = new LayoutPreference(mContext, R.layout.settings_entity_header);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
mScreen.addPreference(mPreference);
|
||||
@@ -97,20 +92,20 @@ public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsContro
|
||||
@Test
|
||||
public void connectionStatusChangesWhileScreenOpen() {
|
||||
InOrder inOrder = inOrder(mHeaderController);
|
||||
when(mCachedDevice.getConnectionSummary()).thenReturn(
|
||||
mContext.getString(R.string.bluetooth_connected));
|
||||
when(mCachedDevice.getConnectionSummary())
|
||||
.thenReturn(mContext.getString(R.string.bluetooth_connected));
|
||||
showScreen(mController);
|
||||
inOrder.verify(mHeaderController).setSummary(
|
||||
mContext.getString(R.string.bluetooth_connected));
|
||||
inOrder.verify(mHeaderController)
|
||||
.setSummary(mContext.getString(R.string.bluetooth_connected));
|
||||
|
||||
when(mCachedDevice.getConnectionSummary()).thenReturn(null);
|
||||
mController.onDeviceAttributesChanged();
|
||||
inOrder.verify(mHeaderController).setSummary((CharSequence) null);
|
||||
|
||||
when(mCachedDevice.getConnectionSummary()).thenReturn(
|
||||
mContext.getString(R.string.bluetooth_connecting));
|
||||
when(mCachedDevice.getConnectionSummary())
|
||||
.thenReturn(mContext.getString(R.string.bluetooth_connecting));
|
||||
mController.onDeviceAttributesChanged();
|
||||
inOrder.verify(mHeaderController).setSummary(
|
||||
mContext.getString(R.string.bluetooth_connecting));
|
||||
inOrder.verify(mHeaderController)
|
||||
.setSummary(mContext.getString(R.string.bluetooth_connecting));
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@ package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
@@ -27,25 +26,24 @@ import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = SettingsShadowBluetoothDevice.class)
|
||||
@Config(shadows = SettingsShadowBluetoothDevice.class)
|
||||
public class BluetoothDetailsMacAddressControllerTest extends BluetoothDetailsControllerTestBase {
|
||||
|
||||
private BluetoothDetailsMacAddressController mController;
|
||||
private BluetoothDetailsMacAddressController mController;
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
mController = new BluetoothDetailsMacAddressController(mContext, mFragment, mCachedDevice,
|
||||
mLifecycle);
|
||||
setupDevice(mDeviceConfig);
|
||||
}
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
mController =
|
||||
new BluetoothDetailsMacAddressController(mContext, mFragment, mCachedDevice, mLifecycle);
|
||||
setupDevice(mDeviceConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void macAddress() {
|
||||
showScreen(mController);
|
||||
FooterPreference footer = (FooterPreference) mScreen.findPreference(
|
||||
mController.getPreferenceKey());
|
||||
assertThat(footer.getTitle().toString()).endsWith(mDeviceConfig.getAddress());
|
||||
}
|
||||
@Test
|
||||
public void macAddress() {
|
||||
showScreen(mController);
|
||||
FooterPreference footer =
|
||||
(FooterPreference) mScreen.findPreference(mController.getPreferenceKey());
|
||||
assertThat(footer.getTitle().toString()).endsWith(mDeviceConfig.getAddress());
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -33,7 +32,6 @@ import android.support.v7.preference.PreferenceCategory;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.A2dpProfile;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -52,11 +50,13 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows=SettingsShadowBluetoothDevice.class)
|
||||
@Config(shadows = SettingsShadowBluetoothDevice.class)
|
||||
public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsControllerTestBase {
|
||||
|
||||
private BluetoothDetailsProfilesController mController;
|
||||
private List<LocalBluetoothProfile> mConnectableProfiles;
|
||||
private PreferenceCategory mProfiles;
|
||||
@@ -87,14 +87,13 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
||||
}
|
||||
|
||||
static class FakeBluetoothProfile implements LocalBluetoothProfile {
|
||||
protected HashSet<BluetoothDevice> mConnectedDevices;
|
||||
protected HashMap<BluetoothDevice, Boolean> mPreferred;
|
||||
protected Context mContext;
|
||||
protected int mNameResourceId;
|
||||
|
||||
public FakeBluetoothProfile(Context context, int nameResourceId) {
|
||||
mConnectedDevices = new HashSet<>();
|
||||
mPreferred = new HashMap<>();
|
||||
private Set<BluetoothDevice> mConnectedDevices = new HashSet<>();
|
||||
private Map<BluetoothDevice, Boolean> mPreferred = new HashMap<>();
|
||||
private Context mContext;
|
||||
private int mNameResourceId;
|
||||
|
||||
private FakeBluetoothProfile(Context context, int nameResourceId) {
|
||||
mContext = context;
|
||||
mNameResourceId = nameResourceId;
|
||||
}
|
||||
@@ -180,8 +179,8 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
||||
/**
|
||||
* Creates and adds a mock LocalBluetoothProfile to the list of connectable profiles for the
|
||||
* device.
|
||||
@param profileNameResId the resource id for the name used by this profile
|
||||
@param deviceIsPreferred whether this profile should start out as enabled for the device
|
||||
* @param profileNameResId the resource id for the name used by this profile
|
||||
* @param deviceIsPreferred whether this profile should start out as enabled for the device
|
||||
*/
|
||||
private LocalBluetoothProfile addFakeProfile(int profileNameResId,
|
||||
boolean deviceIsPreferred) {
|
||||
@@ -200,7 +199,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
||||
assertThat(mConnectableProfiles).isNotEmpty();
|
||||
assertThat(mProfiles.getPreferenceCount()).isEqualTo(mConnectableProfiles.size());
|
||||
}
|
||||
ArrayList<SwitchPreference> result = new ArrayList<>();
|
||||
List<SwitchPreference> result = new ArrayList<>();
|
||||
for (int i = 0; i < mProfiles.getPreferenceCount(); i++) {
|
||||
result.add((SwitchPreference)mProfiles.getPreference(i));
|
||||
}
|
||||
@@ -209,8 +208,8 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
||||
|
||||
private void verifyProfileSwitchTitles(List<SwitchPreference> switches) {
|
||||
for (int i = 0; i < switches.size(); i++) {
|
||||
String expectedTitle = mContext.getString(
|
||||
mConnectableProfiles.get(i).getNameResource(mDevice));
|
||||
String expectedTitle =
|
||||
mContext.getString(mConnectableProfiles.get(i).getNameResource(mDevice));
|
||||
assertThat(switches.get(i).getTitle()).isEqualTo(expectedTitle);
|
||||
}
|
||||
}
|
||||
@@ -285,8 +284,8 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
||||
@Test
|
||||
public void pbapProfileStartsEnabled() {
|
||||
setupDevice(makeDefaultDeviceConfig());
|
||||
when(mCachedDevice.getPhonebookPermissionChoice()).thenReturn(
|
||||
CachedBluetoothDevice.ACCESS_ALLOWED);
|
||||
when(mCachedDevice.getPhonebookPermissionChoice())
|
||||
.thenReturn(CachedBluetoothDevice.ACCESS_ALLOWED);
|
||||
PbapServerProfile psp = mock(PbapServerProfile.class);
|
||||
when(psp.getNameResource(mDevice)).thenReturn(R.string.bluetooth_profile_pbap);
|
||||
when(psp.toString()).thenReturn(PbapServerProfile.NAME);
|
||||
@@ -307,8 +306,8 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
||||
@Test
|
||||
public void pbapProfileStartsDisabled() {
|
||||
setupDevice(makeDefaultDeviceConfig());
|
||||
when(mCachedDevice.getPhonebookPermissionChoice()).thenReturn(
|
||||
CachedBluetoothDevice.ACCESS_REJECTED);
|
||||
when(mCachedDevice.getPhonebookPermissionChoice())
|
||||
.thenReturn(CachedBluetoothDevice.ACCESS_REJECTED);
|
||||
PbapServerProfile psp = mock(PbapServerProfile.class);
|
||||
when(psp.getNameResource(mDevice)).thenReturn(R.string.bluetooth_profile_pbap);
|
||||
when(psp.toString()).thenReturn(PbapServerProfile.NAME);
|
||||
@@ -333,8 +332,8 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
||||
when(mapProfile.getNameResource(mDevice)).thenReturn(R.string.bluetooth_profile_map);
|
||||
when(mProfileManager.getMapProfile()).thenReturn(mapProfile);
|
||||
when(mProfileManager.getProfileByName(eq(mapProfile.toString()))).thenReturn(mapProfile);
|
||||
when(mCachedDevice.getMessagePermissionChoice()).thenReturn(
|
||||
CachedBluetoothDevice.ACCESS_REJECTED);
|
||||
when(mCachedDevice.getMessagePermissionChoice())
|
||||
.thenReturn(CachedBluetoothDevice.ACCESS_REJECTED);
|
||||
showScreen(mController);
|
||||
List<SwitchPreference> switches = getProfileSwitches(false);
|
||||
assertThat(switches.size()).isEqualTo(1);
|
||||
@@ -352,8 +351,8 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
||||
A2dpProfile profile = mock(A2dpProfile.class);
|
||||
when(mProfileManager.getProfileByName(eq(profile.toString()))).thenReturn(profile);
|
||||
when(profile.getNameResource(mDevice)).thenReturn(R.string.bluetooth_profile_a2dp);
|
||||
when(profile.getHighQualityAudioOptionLabel(mDevice)).thenReturn(mContext.getString(
|
||||
R.string.bluetooth_profile_a2dp_high_quality_unknown_codec));
|
||||
when(profile.getHighQualityAudioOptionLabel(mDevice)).thenReturn(
|
||||
mContext.getString(R.string.bluetooth_profile_a2dp_high_quality_unknown_codec));
|
||||
when(profile.supportsHighQualityAudio(mDevice)).thenReturn(supportsHighQualityAudio);
|
||||
when(profile.isHighQualityAudioEnabled(mDevice)).thenReturn(highQualityAudioEnabled);
|
||||
when(profile.isPreferred(mDevice)).thenReturn(preferred);
|
||||
@@ -390,8 +389,8 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
||||
showScreen(mController);
|
||||
assertThat(mProfiles.getPreferenceCount()).isEqualTo(1);
|
||||
SwitchPreference pref = (SwitchPreference) mProfiles.getPreference(0);
|
||||
assertThat(pref.getKey()).isNotEqualTo(
|
||||
BluetoothDetailsProfilesController.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
assertThat(pref.getKey())
|
||||
.isNotEqualTo(BluetoothDetailsProfilesController.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
assertThat(pref.getTitle()).isEqualTo(mContext.getString(R.string.bluetooth_profile_a2dp));
|
||||
}
|
||||
|
||||
@@ -414,8 +413,8 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
||||
|
||||
// Disabling media audio should cause the high quality audio switch to disappear, but not
|
||||
// the regular audio one.
|
||||
SwitchPreference audioPref = (SwitchPreference) mScreen.findPreference(
|
||||
audioProfile.toString());
|
||||
SwitchPreference audioPref =
|
||||
(SwitchPreference) mScreen.findPreference(audioProfile.toString());
|
||||
audioPref.performClick();
|
||||
verify(audioProfile).setPreferred(mDevice, false);
|
||||
when(audioProfile.isPreferred(mDevice)).thenReturn(false);
|
||||
@@ -438,8 +437,8 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
||||
setupDevice(makeDefaultDeviceConfig());
|
||||
A2dpProfile audioProfile = addMockA2dpProfile(false, true, true);
|
||||
showScreen(mController);
|
||||
SwitchPreference audioPref = (SwitchPreference) mScreen.findPreference(
|
||||
audioProfile.toString());
|
||||
SwitchPreference audioPref =
|
||||
(SwitchPreference) mScreen.findPreference(audioProfile.toString());
|
||||
SwitchPreference highQualityAudioPref = getHighQualityAudioPref();
|
||||
assertThat(audioPref).isNotNull();
|
||||
assertThat(audioPref.isChecked()).isFalse();
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
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.doReturn;
|
||||
@@ -35,7 +34,6 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
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.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -49,12 +47,11 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.fakes.RoboMenu;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothDeviceDetailsFragmentTest {
|
||||
|
||||
private BluetoothDeviceDetailsFragment mFragment;
|
||||
private Context mContext;
|
||||
|
||||
@@ -98,8 +95,8 @@ public class BluetoothDeviceDetailsFragmentTest {
|
||||
MenuInflater inflater = new MenuInflater(mContext);
|
||||
mFragment.onCreateOptionsMenu(menu, inflater);
|
||||
MenuItem item = menu.getItem(0);
|
||||
assertThat(item.getItemId()).isEqualTo(
|
||||
BluetoothDeviceDetailsFragment.EDIT_DEVICE_NAME_ITEM_ID);
|
||||
assertThat(item.getItemId())
|
||||
.isEqualTo(BluetoothDeviceDetailsFragment.EDIT_DEVICE_NAME_ITEM_ID);
|
||||
|
||||
FragmentManager fragmentManager = mock(FragmentManager.class);
|
||||
when(mFragment.getFragmentManager()).thenReturn(fragmentManager);
|
||||
|
@@ -22,12 +22,12 @@ import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
|
||||
@@ -37,11 +37,10 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothDeviceNamePreferenceControllerTest {
|
||||
|
||||
private static final String DEVICE_NAME = "Nightshade";
|
||||
private static final int ORDER = 1;
|
||||
|
||||
@@ -60,11 +59,10 @@ public class BluetoothDeviceNamePreferenceControllerTest {
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
|
||||
doReturn(mContext).when(mPreferenceScreen).getContext();
|
||||
when(mPreferenceScreen.getContext()).thenReturn(mContext);
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference.setKey(BluetoothDeviceNamePreferenceController.KEY_DEVICE_NAME);
|
||||
mController = spy(new BluetoothDeviceNamePreferenceController(
|
||||
mContext, mLocalAdapter));
|
||||
mController = spy(new BluetoothDeviceNamePreferenceController(mContext, mLocalAdapter));
|
||||
doReturn(DEVICE_NAME).when(mController).getDeviceName();
|
||||
}
|
||||
|
||||
@@ -81,8 +79,8 @@ public class BluetoothDeviceNamePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testCreateBluetoothDeviceNamePreference() {
|
||||
Preference preference = mController.createBluetoothDeviceNamePreference(mPreferenceScreen,
|
||||
ORDER);
|
||||
Preference preference =
|
||||
mController.createBluetoothDeviceNamePreference(mPreferenceScreen, ORDER);
|
||||
|
||||
assertThat(preference.getKey()).isEqualTo(mController.KEY_DEVICE_NAME);
|
||||
assertThat(preference.getOrder()).isEqualTo(ORDER);
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -30,7 +30,6 @@ import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
|
||||
@@ -41,10 +40,8 @@ import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothDeviceRenamePreferenceControllerTest {
|
||||
|
||||
private static final String DEVICE_NAME = "Nightshade";
|
||||
|
@@ -20,6 +20,7 @@ import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
@@ -27,7 +28,6 @@ import android.content.Intent;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -40,11 +40,10 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothDeviceUpdaterTest {
|
||||
|
||||
@Mock
|
||||
private DashboardFragment mDashboardFragment;
|
||||
@Mock
|
||||
@@ -66,11 +65,11 @@ public class BluetoothDeviceUpdaterTest {
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
doReturn(mContext).when(mDashboardFragment).getContext();
|
||||
doReturn(mBluetoothDevice).when(mCachedBluetoothDevice).getDevice();
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||
|
||||
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, false);
|
||||
mBluetoothDeviceUpdater = new BluetoothDeviceUpdater(mDashboardFragment,
|
||||
mDevicePreferenceCallback, null) {
|
||||
mBluetoothDeviceUpdater =
|
||||
new BluetoothDeviceUpdater(mDashboardFragment, mDevicePreferenceCallback, null) {
|
||||
@Override
|
||||
public boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice) {
|
||||
return true;
|
||||
|
@@ -15,6 +15,15 @@
|
||||
*/
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
@@ -28,7 +37,6 @@ import android.widget.Switch;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.widget.MasterSwitchController;
|
||||
import com.android.settings.widget.MasterSwitchPreference;
|
||||
@@ -47,20 +55,8 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Mockito.never;
|
||||
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, shadows = {
|
||||
SettingsShadowResources.class, SettingsShadowResources.SettingsShadowTheme.class
|
||||
})
|
||||
@Config(shadows = SettingsShadowResources.SettingsShadowTheme.class)
|
||||
public class BluetoothEnablerTest {
|
||||
|
||||
private static EnforcedAdmin sFakeEnforcedAdmin;
|
||||
@@ -80,8 +76,7 @@ public class BluetoothEnablerTest {
|
||||
private LocalBluetoothAdapter mBluetoothAdapter;
|
||||
|
||||
private Context mContext;
|
||||
Switch mSwitch;
|
||||
private MasterSwitchPreference mMasterSwitchPreference;
|
||||
private Switch mSwitch;
|
||||
private MasterSwitchController mMasterSwitchController;
|
||||
private BluetoothEnabler mBluetoothEnabler;
|
||||
|
||||
@@ -92,8 +87,8 @@ public class BluetoothEnablerTest {
|
||||
when(mBluetoothManager.getBluetoothAdapter()).thenReturn(mBluetoothAdapter);
|
||||
|
||||
mSwitch = new Switch(mContext);
|
||||
mMasterSwitchPreference = new MasterSwitchPreference(mContext);
|
||||
mMasterSwitchController = spy(new MasterSwitchController(mMasterSwitchPreference));
|
||||
MasterSwitchPreference masterSwitchPreference = new MasterSwitchPreference(mContext);
|
||||
mMasterSwitchController = spy(new MasterSwitchController(masterSwitchPreference));
|
||||
mBluetoothEnabler = new BluetoothEnabler(
|
||||
mContext,
|
||||
mMasterSwitchController,
|
||||
@@ -103,7 +98,7 @@ public class BluetoothEnablerTest {
|
||||
mRestrictionUtils);
|
||||
PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(mock(View.class));
|
||||
when(holder.findViewById(R.id.switchWidget)).thenReturn(mSwitch);
|
||||
mMasterSwitchPreference.onBindViewHolder(holder);
|
||||
masterSwitchPreference.onBindViewHolder(holder);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -24,19 +24,17 @@ import android.os.Bundle;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothFilesPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private BluetoothFilesPreferenceController mController;
|
||||
private Preference mPreference;
|
||||
@@ -57,12 +55,12 @@ public class BluetoothFilesPreferenceControllerTest {
|
||||
|
||||
final Intent intent = ShadowApplication.getInstance().getNextStartedActivity();
|
||||
assertThat(intent).isNotNull();
|
||||
assertThat(intent.getAction()).isEqualTo(
|
||||
BluetoothFilesPreferenceController.ACTION_OPEN_FILES);
|
||||
assertThat(intent.getAction())
|
||||
.isEqualTo(BluetoothFilesPreferenceController.ACTION_OPEN_FILES);
|
||||
|
||||
final Bundle bundle = intent.getExtras();
|
||||
assertThat(bundle.getInt(BluetoothFilesPreferenceController.EXTRA_DIRECTION)).isEqualTo(1);
|
||||
assertThat(bundle.getBoolean(
|
||||
BluetoothFilesPreferenceController.EXTRA_SHOW_ALL_FILES)).isTrue();
|
||||
assertThat(bundle.getBoolean(BluetoothFilesPreferenceController.EXTRA_SHOW_ALL_FILES))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,6 @@ import android.content.Context;
|
||||
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -41,10 +40,8 @@ import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothMasterSwitchPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -60,13 +57,12 @@ public class BluetoothMasterSwitchPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private BluetoothMasterSwitchPreferenceController mController;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
FakeFeatureFactory.setupForTest();
|
||||
|
||||
mController = new BluetoothMasterSwitchPreferenceController(
|
||||
mContext, mBluetoothManager, mRestrictionUtils, mFragment);
|
||||
@@ -90,8 +86,8 @@ public class BluetoothMasterSwitchPreferenceControllerTest {
|
||||
public void onPause_shouldUnregisterCallback() {
|
||||
mController.onPause();
|
||||
|
||||
verify(mBluetoothManager.getEventManager()).unregisterCallback(
|
||||
any(BluetoothCallback.class));
|
||||
verify(mBluetoothManager.getEventManager())
|
||||
.unregisterCallback(any(BluetoothCallback.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,7 +102,6 @@ public class BluetoothMasterSwitchPreferenceControllerTest {
|
||||
public void onStop_shouldRegisterPreferenceChangeListener() {
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onStart();
|
||||
|
||||
mController.onStop();
|
||||
|
||||
verify(mPreference).setOnPreferenceChangeListener(null);
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
@@ -35,7 +34,6 @@ import android.support.v7.preference.PreferenceGroup;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
@@ -48,10 +46,8 @@ import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothPairingDetailTest {
|
||||
|
||||
@Mock
|
||||
@@ -87,10 +83,10 @@ public class BluetoothPairingDetailTest {
|
||||
|
||||
@Test
|
||||
public void testInitPreferencesFromPreferenceScreen_findPreferences() {
|
||||
doReturn(mAvailableDevicesCategory).when(mFragment).findPreference(
|
||||
BluetoothPairingDetail.KEY_AVAIL_DEVICES);
|
||||
doReturn(mFooterPreference).when(mFragment).findPreference(
|
||||
BluetoothPairingDetail.KEY_FOOTER_PREF);
|
||||
doReturn(mAvailableDevicesCategory).when(mFragment)
|
||||
.findPreference(BluetoothPairingDetail.KEY_AVAIL_DEVICES);
|
||||
doReturn(mFooterPreference).when(mFragment)
|
||||
.findPreference(BluetoothPairingDetail.KEY_FOOTER_PREF);
|
||||
|
||||
mFragment.initPreferencesFromPreferenceScreen();
|
||||
|
||||
@@ -196,5 +192,4 @@ public class BluetoothPairingDetailTest {
|
||||
// Verify that clean up only happen once at initialization
|
||||
verify(mAvailableDevicesCategory, times(1)).removeAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
@@ -38,23 +37,18 @@ import android.widget.CheckBox;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadows.ShadowAlertDialog;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.FragmentTestUtil;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows=ShadowEventLogWriter.class)
|
||||
public class BluetoothPairingDialogTest {
|
||||
|
||||
private static final String FILLER = "text that goes in a view";
|
||||
@@ -139,7 +133,7 @@ public class BluetoothPairingDialogTest {
|
||||
when(controller.getDeviceVariantMessageHintId())
|
||||
.thenReturn(BluetoothPairingController.INVALID_DIALOG_TYPE);
|
||||
|
||||
Context context = spy(ShadowApplication.getInstance().getApplicationContext());
|
||||
Context context = spy(RuntimeEnvironment.application);
|
||||
InputMethodManager imm = mock(InputMethodManager.class);
|
||||
doReturn(imm).when(context).getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
@@ -176,8 +170,7 @@ public class BluetoothPairingDialogTest {
|
||||
|
||||
// get the relevant views
|
||||
View messagePairing = frag.getmDialog().findViewById(R.id.pairing_code_message);
|
||||
TextView pairingViewContent =
|
||||
(TextView) frag.getmDialog().findViewById(R.id.pairing_subhead);
|
||||
TextView pairingViewContent = frag.getmDialog().findViewById(R.id.pairing_subhead);
|
||||
View pairingViewCaption = frag.getmDialog().findViewById(R.id.pairing_caption);
|
||||
|
||||
// check that the relevant views are visible and that the passkey is shown
|
||||
@@ -288,8 +281,8 @@ public class BluetoothPairingDialogTest {
|
||||
BluetoothPairingDialogFragment frag = makeFragment();
|
||||
|
||||
// verify that the checkbox is visible and that the device name is correct
|
||||
CheckBox sharingCheckbox = (CheckBox) frag.getmDialog()
|
||||
.findViewById(R.id.phonebook_sharing_message_confirm_pin);
|
||||
CheckBox sharingCheckbox =
|
||||
frag.getmDialog().findViewById(R.id.phonebook_sharing_message_confirm_pin);
|
||||
assertThat(sharingCheckbox.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@@ -306,8 +299,8 @@ public class BluetoothPairingDialogTest {
|
||||
BluetoothPairingDialogFragment frag = makeFragment();
|
||||
|
||||
// verify that the checkbox is gone
|
||||
CheckBox sharingCheckbox = (CheckBox) frag.getmDialog()
|
||||
.findViewById(R.id.phonebook_sharing_message_confirm_pin);
|
||||
CheckBox sharingCheckbox =
|
||||
frag.getmDialog().findViewById(R.id.phonebook_sharing_message_confirm_pin);
|
||||
assertThat(sharingCheckbox.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@@ -325,7 +318,7 @@ public class BluetoothPairingDialogTest {
|
||||
BluetoothPairingDialogFragment frag = makeFragment();
|
||||
|
||||
// verify message is what we expect it to be and is visible
|
||||
TextView message = (TextView) frag.getmDialog().findViewById(R.id.message_below_pin);
|
||||
TextView message = frag.getmDialog().findViewById(R.id.message_below_pin);
|
||||
assertThat(message.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(TextUtils.equals(frag.getString(R.string.cancel), message.getText())).isTrue();
|
||||
}
|
||||
@@ -344,7 +337,7 @@ public class BluetoothPairingDialogTest {
|
||||
BluetoothPairingDialogFragment frag = makeFragment();
|
||||
|
||||
// verify message is what we expect it to be and is visible
|
||||
TextView hint = (TextView) frag.getmDialog().findViewById(R.id.pin_values_hint);
|
||||
TextView hint = frag.getmDialog().findViewById(R.id.pin_values_hint);
|
||||
assertThat(hint.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(TextUtils.equals(frag.getString(R.string.cancel), hint.getText())).isTrue();
|
||||
}
|
||||
@@ -364,16 +357,16 @@ public class BluetoothPairingDialogTest {
|
||||
BluetoothPairingDialogFragment frag = makeFragment();
|
||||
|
||||
// verify message is what we expect it to be and is visible
|
||||
TextView hint = (TextView) frag.getmDialog().findViewById(R.id.pin_values_hint);
|
||||
TextView hint = frag.getmDialog().findViewById(R.id.pin_values_hint);
|
||||
assertThat(hint.getVisibility()).isEqualTo(View.GONE);
|
||||
TextView message = (TextView) frag.getmDialog().findViewById(R.id.message_below_pin);
|
||||
TextView message = frag.getmDialog().findViewById(R.id.message_below_pin);
|
||||
assertThat(message.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pairingStringIsFormattedCorrectly() {
|
||||
final String device = "test_device";
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
assertThat(context.getString(R.string.bluetooth_pb_acceptance_dialog_text, device, device))
|
||||
.contains(device);
|
||||
}
|
||||
@@ -443,6 +436,7 @@ public class BluetoothPairingDialogTest {
|
||||
when(fragment.getPairingViewText()).thenReturn(existingText);
|
||||
setupFragment(fragment);
|
||||
AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog();
|
||||
assertThat(dialog).isNotNull();
|
||||
boolean expected = !TextUtils.isEmpty(existingText);
|
||||
assertThat(dialog.getButton(Dialog.BUTTON_POSITIVE).isEnabled()).isEqualTo(expected);
|
||||
}
|
||||
|
@@ -28,7 +28,6 @@ import android.content.Intent;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
@@ -39,11 +38,10 @@ import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothPairingPreferenceControllerTest {
|
||||
|
||||
private static final int ORDER = 1;
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -74,8 +72,8 @@ public class BluetoothPairingPreferenceControllerTest {
|
||||
assertThat(pref.getKey()).isEqualTo(BluetoothPairingPreferenceController.KEY_PAIRING);
|
||||
assertThat(pref.getIcon()).isEqualTo(mContext.getDrawable(R.drawable.ic_menu_add));
|
||||
assertThat(pref.getOrder()).isEqualTo(ORDER);
|
||||
assertThat(pref.getTitle()).isEqualTo(
|
||||
mContext.getString(R.string.bluetooth_pairing_pref_title));
|
||||
assertThat(pref.getTitle())
|
||||
.isEqualTo(mContext.getString(R.string.bluetooth_pairing_pref_title));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -16,11 +16,12 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -30,12 +31,8 @@ import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothSettingsSummaryProviderTest {
|
||||
|
||||
private Context mContext;
|
||||
@@ -50,8 +47,8 @@ public class BluetoothSettingsSummaryProviderTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application.getApplicationContext();
|
||||
mSummaryProvider = new BluetoothSettings.SummaryProvider(mContext, mSummaryLoader,
|
||||
mBluetoothManager);
|
||||
mSummaryProvider =
|
||||
new BluetoothSettings.SummaryProvider(mContext, mSummaryLoader, mBluetoothManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,5 +74,4 @@ public class BluetoothSettingsSummaryProviderTest {
|
||||
|
||||
verify(mSummaryLoader).setSummary(mSummaryProvider, summary);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
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.doReturn;
|
||||
@@ -26,16 +25,14 @@ import static org.mockito.Mockito.spy;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
|
||||
@@ -45,12 +42,10 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothSettingsTest {
|
||||
|
||||
private static final String FOOTAGE_MAC_STRING = "Bluetooth mac: xxxx";
|
||||
@@ -103,8 +98,8 @@ public class BluetoothSettingsTest {
|
||||
|
||||
@Test
|
||||
public void setUpdateMyDevicePreference_setTitleCorrectly() {
|
||||
doReturn(FOOTAGE_MAC_STRING).when(mFragment).getString(
|
||||
eq(R.string.bluetooth_footer_mac_message), any());
|
||||
doReturn(FOOTAGE_MAC_STRING).when(mFragment)
|
||||
.getString(eq(R.string.bluetooth_footer_mac_message), any());
|
||||
|
||||
mFragment.updateFooterPreference(mFooterPreference);
|
||||
|
||||
@@ -129,10 +124,10 @@ public class BluetoothSettingsTest {
|
||||
|
||||
@Test
|
||||
public void testInitPreferencesFromPreferenceScreen() {
|
||||
doReturn(mPairedDevicesCategory).when(mFragment).findPreference(
|
||||
BluetoothSettings.KEY_PAIRED_DEVICES);
|
||||
doReturn(mFooterPreference).when(mFragment).findPreference(
|
||||
BluetoothSettings.KEY_FOOTER_PREF);
|
||||
doReturn(mPairedDevicesCategory).when(mFragment)
|
||||
.findPreference(BluetoothSettings.KEY_PAIRED_DEVICES);
|
||||
doReturn(mFooterPreference).when(mFragment)
|
||||
.findPreference(BluetoothSettings.KEY_FOOTER_PREF);
|
||||
|
||||
mFragment.initPreferencesFromPreferenceScreen();
|
||||
|
||||
@@ -144,18 +139,17 @@ public class BluetoothSettingsTest {
|
||||
public void testSearchIndexProvider_pairPageEnabled_keyNotAdded() {
|
||||
doReturn(true).when(mFeatureFactory.bluetoothFeatureProvider).isPairingPageEnabled();
|
||||
|
||||
final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||
mContext);
|
||||
final List<String> keys =
|
||||
BluetoothSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
|
||||
|
||||
assertThat(keys).doesNotContain(BluetoothSettings.DATA_KEY_REFERENCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_pairPageDisabled_keyAdded() {
|
||||
final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||
mContext);
|
||||
final List<String> keys =
|
||||
BluetoothSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
|
||||
|
||||
assertThat(keys).contains(BluetoothSettings.DATA_KEY_REFERENCE);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doCallRealMethod;
|
||||
@@ -31,7 +30,6 @@ import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
@@ -44,14 +42,13 @@ import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothSummaryUpdaterTest {
|
||||
|
||||
private static final String DEVICE_NAME = "Nightshade";
|
||||
private static final String DEVICE_KEYBOARD_NAME = "Bluetooth Keyboard";
|
||||
|
||||
@@ -91,8 +88,7 @@ public class BluetoothSummaryUpdaterTest {
|
||||
doAnswer(invocation -> mDeviceConnected[0]).when(mConnectedDevice).isConnected();
|
||||
// Setup second device
|
||||
doReturn(DEVICE_KEYBOARD_NAME).when(mConnectedKeyBoardDevice).getName();
|
||||
doAnswer(invocation -> mDeviceConnected[1]).when(mConnectedKeyBoardDevice)
|
||||
.isConnected();
|
||||
doAnswer(invocation -> mDeviceConnected[1]).when(mConnectedKeyBoardDevice).isConnected();
|
||||
doReturn(mBondedDevices).when(mBtAdapter).getBondedDevices();
|
||||
}
|
||||
|
||||
@@ -242,8 +238,7 @@ public class BluetoothSummaryUpdaterTest {
|
||||
mSummaryUpdater.onConnectionStateChanged(null /* device */,
|
||||
BluetoothAdapter.STATE_CONNECTED);
|
||||
|
||||
verify(mListener).onSummaryChanged(
|
||||
mContext.getString(R.string.disconnected));
|
||||
verify(mListener).onSummaryChanged(mContext.getString(R.string.disconnected));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -274,8 +269,8 @@ public class BluetoothSummaryUpdaterTest {
|
||||
public void getConnectedDeviceSummary_hasConnectedDevice_returnOneDeviceSummary() {
|
||||
mBondedDevices.add(mConnectedDevice);
|
||||
mDeviceConnected[0] = true;
|
||||
final String expectedSummary = mContext.getString(R.string.bluetooth_connected_summary,
|
||||
DEVICE_NAME);
|
||||
final String expectedSummary =
|
||||
mContext.getString(R.string.bluetooth_connected_summary, DEVICE_NAME);
|
||||
|
||||
assertThat(mSummaryUpdater.getConnectedDeviceSummary()).isEqualTo(expectedSummary);
|
||||
}
|
||||
@@ -286,8 +281,8 @@ public class BluetoothSummaryUpdaterTest {
|
||||
mBondedDevices.add(mConnectedKeyBoardDevice);
|
||||
mDeviceConnected[0] = true;
|
||||
mDeviceConnected[1] = true;
|
||||
final String expectedSummary = mContext.getString(
|
||||
R.string.bluetooth_connected_multiple_devices_summary);
|
||||
final String expectedSummary =
|
||||
mContext.getString(R.string.bluetooth_connected_multiple_devices_summary);
|
||||
|
||||
assertThat(mSummaryUpdater.getConnectedDeviceSummary()).isEqualTo(expectedSummary);
|
||||
}
|
||||
@@ -300,5 +295,4 @@ public class BluetoothSummaryUpdaterTest {
|
||||
this.summary = summary;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -28,7 +27,6 @@ import android.content.Context;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -42,10 +40,8 @@ import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothSwitchPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -68,8 +64,8 @@ public class BluetoothSwitchPreferenceControllerTest {
|
||||
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
||||
FakeFeatureFactory.setupForTest();
|
||||
|
||||
mController = new BluetoothSwitchPreferenceController(
|
||||
mContext, mBluetoothManager, mRestrictionUtils);
|
||||
mController =
|
||||
new BluetoothSwitchPreferenceController(mContext, mBluetoothManager, mRestrictionUtils);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||
}
|
||||
@@ -78,16 +74,16 @@ public class BluetoothSwitchPreferenceControllerTest {
|
||||
public void testGetAvailabilityStatus_adapterNull_returnDisabled() {
|
||||
mController.mBluetoothAdapter = null;
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.DISABLED_UNSUPPORTED);
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.DISABLED_UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAvailabilityStatus_adapterExisted_returnAvailable() {
|
||||
mController.mBluetoothAdapter = mLocalBluetoothAdapter;
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -20,12 +20,12 @@ import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -37,11 +37,10 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ConnectedBluetoothDeviceUpdaterTest {
|
||||
|
||||
@Mock
|
||||
private DashboardFragment mDashboardFragment;
|
||||
@Mock
|
||||
@@ -60,7 +59,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
doReturn(mContext).when(mDashboardFragment).getContext();
|
||||
doReturn(mBluetoothDevice).when(mCachedBluetoothDevice).getDevice();
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||
|
||||
mBluetoothDeviceUpdater = spy(new ConnectedBluetoothDeviceUpdater(mDashboardFragment,
|
||||
mDevicePreferenceCallback, null));
|
||||
@@ -104,5 +103,4 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
||||
|
||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.eq;
|
||||
@@ -28,12 +27,10 @@ import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
@@ -44,17 +41,14 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DeviceListPreferenceFragmentTest {
|
||||
|
||||
private static final String FOOTAGE_MAC_STRING = "Bluetooth mac: xxxx";
|
||||
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private Resources mResource;
|
||||
@Mock
|
||||
@@ -78,8 +72,8 @@ public class DeviceListPreferenceFragmentTest {
|
||||
|
||||
@Test
|
||||
public void setUpdateMyDevicePreference_setTitleCorrectly() {
|
||||
doReturn(FOOTAGE_MAC_STRING).when(mFragment).getString(
|
||||
eq(R.string.bluetooth_footer_mac_message), any());
|
||||
doReturn(FOOTAGE_MAC_STRING).when(mFragment)
|
||||
.getString(eq(R.string.bluetooth_footer_mac_message), any());
|
||||
|
||||
mFragment.updateFooterPreference(mMyDevicePreference);
|
||||
|
||||
@@ -212,5 +206,4 @@ public class DeviceListPreferenceFragmentTest {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -18,22 +18,17 @@ package com.android.settings.bluetooth;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DevicePickerFragmentTest {
|
||||
@Mock
|
||||
private LocalBluetoothAdapter mLocalAdapter;
|
||||
|
||||
@Mock
|
||||
private BluetoothProgressCategory mAvailableDevicesCategory;
|
||||
private DevicePickerFragment mFragment;
|
||||
|
@@ -16,7 +16,12 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.app.Activity;
|
||||
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;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
@@ -24,8 +29,6 @@ import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
|
||||
import com.android.settingslib.R;
|
||||
import com.android.settingslib.bluetooth.A2dpProfile;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -40,47 +43,39 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.FragmentTestUtil;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
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.when;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
|
||||
ShadowEventLogWriter.class
|
||||
})
|
||||
public class DeviceProfilesSettingsTest {
|
||||
Context mContext;
|
||||
@Mock Activity mActivity;
|
||||
@Mock LocalBluetoothManager mManager;
|
||||
@Mock LocalBluetoothAdapter mAdapter;
|
||||
@Mock LocalBluetoothProfileManager mProfileManager;
|
||||
@Mock CachedBluetoothDeviceManager mDeviceManager;
|
||||
@Mock CachedBluetoothDevice mCachedDevice;
|
||||
@Mock A2dpProfile mProfile;
|
||||
|
||||
ArrayList<LocalBluetoothProfile> mProfiles;
|
||||
DeviceProfilesSettings mFragment;
|
||||
@Mock
|
||||
private LocalBluetoothManager mManager;
|
||||
@Mock
|
||||
private LocalBluetoothAdapter mAdapter;
|
||||
@Mock
|
||||
private LocalBluetoothProfileManager mProfileManager;
|
||||
@Mock
|
||||
private CachedBluetoothDeviceManager mDeviceManager;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedDevice;
|
||||
@Mock
|
||||
private A2dpProfile mProfile;
|
||||
|
||||
private DeviceProfilesSettings mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
when(mProfile.getNameResource(any())).thenReturn(R.string.bluetooth_profile_a2dp);
|
||||
mProfiles = new ArrayList<>();
|
||||
mProfiles.add(mProfile);
|
||||
when(mCachedDevice.getConnectableProfiles()).thenReturn(mProfiles);
|
||||
List<LocalBluetoothProfile> profiles = new ArrayList<>();
|
||||
profiles.add(mProfile);
|
||||
when(mCachedDevice.getConnectableProfiles()).thenReturn(profiles);
|
||||
|
||||
mFragment = new DeviceProfilesSettings();
|
||||
mFragment.setArguments(new Bundle());
|
||||
@@ -101,8 +96,8 @@ public class DeviceProfilesSettingsTest {
|
||||
FragmentTestUtil.startFragment(mFragment);
|
||||
|
||||
ViewGroup profilesGroup = mFragment.getDialog().findViewById(R.id.profiles_section);
|
||||
CheckBox box = (CheckBox) profilesGroup.findViewWithTag(
|
||||
DeviceProfilesSettings.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
CheckBox box =
|
||||
profilesGroup.findViewWithTag(DeviceProfilesSettings.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
assertThat(box).isNotNull();
|
||||
assertThat(box.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(box.isEnabled()).isTrue();
|
||||
@@ -125,8 +120,8 @@ public class DeviceProfilesSettingsTest {
|
||||
// Make sure that the high quality audio option is present but disabled when the device
|
||||
// is busy.
|
||||
ViewGroup profilesGroup = mFragment.getDialog().findViewById(R.id.profiles_section);
|
||||
CheckBox box = (CheckBox) profilesGroup.findViewWithTag(
|
||||
DeviceProfilesSettings.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
CheckBox box =
|
||||
profilesGroup.findViewWithTag(DeviceProfilesSettings.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
assertThat(box).isNotNull();
|
||||
assertThat(box.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(box.isEnabled()).isFalse();
|
||||
@@ -141,8 +136,8 @@ public class DeviceProfilesSettingsTest {
|
||||
|
||||
ViewGroup profilesGroup = mFragment.getDialog().findViewById(R.id.profiles_section);
|
||||
CheckBox audioBox = profilesGroup.findViewWithTag(mProfile.toString());
|
||||
CheckBox highQualityAudioBox = profilesGroup.findViewWithTag(
|
||||
DeviceProfilesSettings.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
CheckBox highQualityAudioBox =
|
||||
profilesGroup.findViewWithTag(DeviceProfilesSettings.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
assertThat(audioBox).isNotNull();
|
||||
assertThat(audioBox.isChecked()).isTrue();
|
||||
assertThat(highQualityAudioBox).isNotNull();
|
||||
@@ -152,8 +147,8 @@ public class DeviceProfilesSettingsTest {
|
||||
when(mProfile.isPreferred(any())).thenReturn(false);
|
||||
mFragment.onDeviceAttributesChanged();
|
||||
audioBox = profilesGroup.findViewWithTag(mProfile.toString());
|
||||
highQualityAudioBox = profilesGroup.findViewWithTag(
|
||||
DeviceProfilesSettings.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
highQualityAudioBox =
|
||||
profilesGroup.findViewWithTag(DeviceProfilesSettings.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
assertThat(audioBox).isNotNull();
|
||||
assertThat(audioBox.isChecked()).isFalse();
|
||||
assertThat(highQualityAudioBox).isNotNull();
|
||||
@@ -163,8 +158,8 @@ public class DeviceProfilesSettingsTest {
|
||||
when(mProfile.isPreferred(any())).thenReturn(true);
|
||||
mFragment.onDeviceAttributesChanged();
|
||||
audioBox = profilesGroup.findViewWithTag(mProfile.toString());
|
||||
highQualityAudioBox = profilesGroup.findViewWithTag(
|
||||
DeviceProfilesSettings.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
highQualityAudioBox =
|
||||
profilesGroup.findViewWithTag(DeviceProfilesSettings.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
assertThat(audioBox).isNotNull();
|
||||
assertThat(audioBox.isChecked()).isTrue();
|
||||
assertThat(highQualityAudioBox).isNotNull();
|
||||
@@ -180,8 +175,8 @@ public class DeviceProfilesSettingsTest {
|
||||
FragmentTestUtil.startFragment(mFragment);
|
||||
ViewGroup profilesGroup = mFragment.getDialog().findViewById(R.id.profiles_section);
|
||||
CheckBox audioBox = profilesGroup.findViewWithTag(mProfile.toString());
|
||||
CheckBox highQualityAudioBox = profilesGroup.findViewWithTag(
|
||||
DeviceProfilesSettings.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
CheckBox highQualityAudioBox =
|
||||
profilesGroup.findViewWithTag(DeviceProfilesSettings.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
|
||||
assertThat(audioBox).isNotNull();
|
||||
assertThat(audioBox.isChecked()).isFalse();
|
||||
@@ -198,9 +193,8 @@ public class DeviceProfilesSettingsTest {
|
||||
// A device that doesn't support high quality audio shouldn't have the checkbox for
|
||||
// high quality audio support.
|
||||
ViewGroup profilesGroup = mFragment.getDialog().findViewById(R.id.profiles_section);
|
||||
CheckBox box = (CheckBox) profilesGroup.findViewWithTag(
|
||||
DeviceProfilesSettings.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
CheckBox box =
|
||||
profilesGroup.findViewWithTag(DeviceProfilesSettings.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||
assertThat(box).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -27,7 +27,6 @@ import static org.mockito.Mockito.when;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -39,11 +38,9 @@ import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowDialog;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ForgetDeviceDialogFragmentTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
|
@@ -31,7 +31,6 @@ import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
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.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -42,12 +41,10 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowDialog;
|
||||
import org.robolectric.util.FragmentTestUtil;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class RemoteDeviceNameDialogFragmentTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -82,7 +79,7 @@ public class RemoteDeviceNameDialogFragmentTest {
|
||||
public void deviceNameDisplayIsCorrect() {
|
||||
String deviceName = "ABC Corp Headphones";
|
||||
AlertDialog dialog = startDialog(deviceName);
|
||||
EditText editText = (EditText) dialog.findViewById(R.id.edittext);
|
||||
EditText editText = dialog.findViewById(R.id.edittext);
|
||||
assertThat(editText.getText().toString()).isEqualTo(deviceName);
|
||||
|
||||
// Make sure that the "rename" button isn't enabled since the text hasn't changed yet, but
|
||||
@@ -108,7 +105,7 @@ public class RemoteDeviceNameDialogFragmentTest {
|
||||
|
||||
// Once we modify the text, the positive button should be clickable, and clicking it should
|
||||
// cause a call to change the name.
|
||||
EditText editText = (EditText) dialog.findViewById(R.id.edittext);
|
||||
EditText editText = dialog.findViewById(R.id.edittext);
|
||||
editText.setText(deviceNameModified);
|
||||
assertThat(positiveButton.isEnabled()).isTrue();
|
||||
positiveButton.performClick();
|
||||
@@ -124,7 +121,7 @@ public class RemoteDeviceNameDialogFragmentTest {
|
||||
// Modifying the text but then hitting cancel should not cause the name to change.
|
||||
Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
|
||||
assertThat(negativeButton.isEnabled()).isTrue();
|
||||
EditText editText = (EditText) dialog.findViewById(R.id.edittext);
|
||||
EditText editText = dialog.findViewById(R.id.edittext);
|
||||
editText.setText(deviceNameModified);
|
||||
negativeButton.performClick();
|
||||
verify(mCachedDevice, never()).setName(anyString());
|
||||
|
@@ -20,12 +20,12 @@ import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -37,11 +37,10 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SavedBluetoothDeviceUpdaterTest {
|
||||
|
||||
@Mock
|
||||
private DashboardFragment mDashboardFragment;
|
||||
@Mock
|
||||
@@ -60,7 +59,7 @@ public class SavedBluetoothDeviceUpdaterTest {
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
doReturn(mContext).when(mDashboardFragment).getContext();
|
||||
doReturn(mBluetoothDevice).when(mCachedBluetoothDevice).getDevice();
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||
|
||||
mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mDashboardFragment,
|
||||
mDevicePreferenceCallback, null));
|
||||
@@ -91,18 +90,17 @@ public class SavedBluetoothDeviceUpdaterTest {
|
||||
|
||||
@Test
|
||||
public void testOnConnectionStateChanged_deviceConnected_removePreference() {
|
||||
mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothAdapter.STATE_CONNECTED);
|
||||
mBluetoothDeviceUpdater
|
||||
.onConnectionStateChanged(mCachedBluetoothDevice, BluetoothAdapter.STATE_CONNECTED);
|
||||
|
||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnConnectionStateChanged_deviceDisconnected_addPreference() {
|
||||
mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothAdapter.STATE_DISCONNECTED);
|
||||
mBluetoothDeviceUpdater
|
||||
.onConnectionStateChanged(mCachedBluetoothDevice, BluetoothAdapter.STATE_DISCONNECTED);
|
||||
|
||||
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -25,10 +25,8 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
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.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
@@ -38,24 +36,19 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = SettingsShadowResources.class)
|
||||
public class UtilsTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
|
||||
private FakeFeatureFactory mFakeFeatureFactory;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
|
||||
mMetricsFeatureProvider = FakeFeatureFactory.setupForTest().getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user