Merge "Removed mocked BluetoothAdapter"
This commit is contained in:
@@ -16,8 +16,9 @@
|
|||||||
|
|
||||||
package com.android.settings.development;
|
package com.android.settings.development;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothManager;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
@@ -39,13 +40,20 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceController extends
|
|||||||
static final String MAX_CONNECTED_AUDIO_DEVICES_PROPERTY =
|
static final String MAX_CONNECTED_AUDIO_DEVICES_PROPERTY =
|
||||||
"persist.bluetooth.maxconnectedaudiodevices";
|
"persist.bluetooth.maxconnectedaudiodevices";
|
||||||
|
|
||||||
private final int mDefaultMaxConnectedAudioDevices;
|
private int mDefaultMaxConnectedAudioDevices = 0;
|
||||||
|
|
||||||
public BluetoothMaxConnectedAudioDevicesPreferenceController(Context context) {
|
public BluetoothMaxConnectedAudioDevicesPreferenceController(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
BluetoothManager mBluetoothManager = context.getSystemService(BluetoothManager.class);
|
|
||||||
mDefaultMaxConnectedAudioDevices = mBluetoothManager.getAdapter()
|
try {
|
||||||
.getMaxConnectedAudioDevices();
|
Resources res = context.getPackageManager().getResourcesForApplication(
|
||||||
|
"com.android.bluetooth");
|
||||||
|
mDefaultMaxConnectedAudioDevices = res.getInteger(res.getIdentifier(
|
||||||
|
"config_bluetooth_max_connected_audio_devices",
|
||||||
|
"integer", "com.android.bluetooth"));
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -24,9 +24,10 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
|
||||||
import android.bluetooth.BluetoothManager;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
|
|
||||||
import androidx.preference.ListPreference;
|
import androidx.preference.ListPreference;
|
||||||
@@ -46,17 +47,12 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest {
|
public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest {
|
||||||
|
|
||||||
private static final int TEST_MAX_CONNECTED_AUDIO_DEVICES = 3;
|
private static int TEST_MAX_CONNECTED_AUDIO_DEVICES = 5;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private PreferenceScreen mPreferenceScreen;
|
private PreferenceScreen mPreferenceScreen;
|
||||||
@Spy
|
@Spy
|
||||||
private Context mSpyContext = RuntimeEnvironment.application;
|
private Context mSpyContext = RuntimeEnvironment.application;
|
||||||
@Spy
|
|
||||||
private BluetoothManager mBluetoothManager =
|
|
||||||
mSpyContext.getSystemService(BluetoothManager.class);
|
|
||||||
@Spy
|
|
||||||
private BluetoothAdapter mBluetoothAdapter = mBluetoothManager.getAdapter();
|
|
||||||
|
|
||||||
private ListPreference mPreference;
|
private ListPreference mPreference;
|
||||||
private BluetoothMaxConnectedAudioDevicesPreferenceController mController;
|
private BluetoothMaxConnectedAudioDevicesPreferenceController mController;
|
||||||
@@ -67,16 +63,19 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
doReturn(mBluetoothManager).when(mSpyContext).getSystemService(BluetoothManager.class);
|
|
||||||
doReturn(mBluetoothAdapter).when(mBluetoothManager).getAdapter();
|
|
||||||
// Get XML values without mock
|
// Get XML values without mock
|
||||||
// Setup test list preference using XML values
|
// Setup test list preference using XML values
|
||||||
mPreference = new ListPreference(mSpyContext);
|
mPreference = new ListPreference(mSpyContext);
|
||||||
mPreference.setEntries(R.array.bluetooth_max_connected_audio_devices);
|
mPreference.setEntries(R.array.bluetooth_max_connected_audio_devices);
|
||||||
mPreference.setEntryValues(R.array.bluetooth_max_connected_audio_devices_values);
|
mPreference.setEntryValues(R.array.bluetooth_max_connected_audio_devices_values);
|
||||||
// Stub default max connected audio devices to a test controlled value
|
// Retrieve default max connected audio devices to a test controlled value
|
||||||
doReturn(TEST_MAX_CONNECTED_AUDIO_DEVICES).when(mBluetoothAdapter)
|
try {
|
||||||
.getMaxConnectedAudioDevices();
|
Resources res = mSpyContext.getPackageManager().getResourcesForApplication("com.android.bluetooth");
|
||||||
|
TEST_MAX_CONNECTED_AUDIO_DEVICES = res.getInteger(res.getIdentifier("config_bluetooth_max_connected_audio_devices", "integer", "com.android.bluetooth"));
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
// Init the actual controller
|
// Init the actual controller
|
||||||
mController = new BluetoothMaxConnectedAudioDevicesPreferenceController(mSpyContext);
|
mController = new BluetoothMaxConnectedAudioDevicesPreferenceController(mSpyContext);
|
||||||
// Construct preference in the controller via a mocked preference screen object
|
// Construct preference in the controller via a mocked preference screen object
|
||||||
|
Reference in New Issue
Block a user