Decouple BluetoothDevicePreference and DeviceListPreferenceFragment
The BluetoothDevicePreference need to know whether to display with an invalid name. However pass in the whole fragment is over-killing. This cl decouple it for several reasons: 1. In P, BluetoothDevicePreference will be used in other fragment. 2. In preference lifecycle from end user side, this flag is constant. Bug: 69333961 Test: RunSettingsRoboTests Change-Id: I3dbcd2a4aafa3ead74371534250e5e7c3ee221f7
This commit is contained in:
@@ -41,6 +41,7 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -51,6 +52,7 @@ import static org.mockito.Mockito.when;
|
||||
@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
|
||||
@@ -70,7 +72,7 @@ public class BluetoothDevicePreferenceTest {
|
||||
mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
|
||||
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
mDeviceListPreferenceFragment);
|
||||
SHOW_DEVICES_WITHOUT_NAMES);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -177,47 +179,22 @@ public class BluetoothDevicePreferenceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisible_notVisibleThenVisible() {
|
||||
when(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames()).thenReturn(false);
|
||||
final boolean[] humanReadableName = {false};
|
||||
doAnswer(invocation -> humanReadableName[0]).when(mCachedBluetoothDevice)
|
||||
.hasHumanReadableName();
|
||||
public void testVisible_showDeviceWithoutNames_visible() {
|
||||
doReturn(false).when(mCachedBluetoothDevice).hasHumanReadableName();
|
||||
BluetoothDevicePreference preference =
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
mDeviceListPreferenceFragment);
|
||||
assertThat(preference.isVisible()).isFalse();
|
||||
humanReadableName[0] = true;
|
||||
preference.onDeviceAttributesChanged();
|
||||
SHOW_DEVICES_WITHOUT_NAMES);
|
||||
|
||||
assertThat(preference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisible_visibleThenNotVisible() {
|
||||
when(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames()).thenReturn(false);
|
||||
final boolean[] humanReadableName = {true};
|
||||
doAnswer(invocation -> humanReadableName[0]).when(mCachedBluetoothDevice)
|
||||
.hasHumanReadableName();
|
||||
public void testVisible_hideDeviceWithoutNames_invisible() {
|
||||
doReturn(false).when(mCachedBluetoothDevice).hasHumanReadableName();
|
||||
BluetoothDevicePreference preference =
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
mDeviceListPreferenceFragment);
|
||||
assertThat(preference.isVisible()).isTrue();
|
||||
humanReadableName[0] = false;
|
||||
preference.onDeviceAttributesChanged();
|
||||
assertThat(preference.isVisible()).isFalse();
|
||||
}
|
||||
false);
|
||||
|
||||
@Test
|
||||
public void testVisible_alwaysVisibleWhenEnabled() {
|
||||
when(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames()).thenReturn(true);
|
||||
final boolean[] humanReadableName = {true};
|
||||
doAnswer(invocation -> humanReadableName[0]).when(mCachedBluetoothDevice)
|
||||
.hasHumanReadableName();
|
||||
BluetoothDevicePreference preference =
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
mDeviceListPreferenceFragment);
|
||||
assertThat(preference.isVisible()).isTrue();
|
||||
humanReadableName[0] = false;
|
||||
preference.onDeviceAttributesChanged();
|
||||
assertThat(preference.isVisible()).isTrue();
|
||||
assertThat(preference.isVisible()).isFalse();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user