Bluetooth: Only show devices when their names are resolved am: 19ba320263
am: 7a6aadce4b
Change-Id: I93ab225467dfbb51c77ea9dfde0e3082a845624c
This commit is contained in:
@@ -39,6 +39,8 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -52,6 +54,8 @@ public class BluetoothDevicePreferenceTest {
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||
@Mock
|
||||
private DeviceListPreferenceFragment mDeviceListPreferenceFragment;
|
||||
|
||||
private FakeFeatureFactory mFakeFeatureFactory;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@@ -64,7 +68,8 @@ public class BluetoothDevicePreferenceTest {
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
|
||||
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice);
|
||||
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
mDeviceListPreferenceFragment);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,4 +156,49 @@ public class BluetoothDevicePreferenceTest {
|
||||
assertThat(mPreference.getIcon()).isEqualTo(
|
||||
mContext.getDrawable(R.drawable.ic_settings_print));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisible_notVisibleThenVisible() {
|
||||
when(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames()).thenReturn(false);
|
||||
final boolean[] humanReadableName = {false};
|
||||
doAnswer(invocation -> humanReadableName[0]).when(mCachedBluetoothDevice)
|
||||
.hasHumanReadableName();
|
||||
BluetoothDevicePreference preference =
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
mDeviceListPreferenceFragment);
|
||||
assertThat(preference.isVisible()).isFalse();
|
||||
humanReadableName[0] = true;
|
||||
preference.onDeviceAttributesChanged();
|
||||
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();
|
||||
BluetoothDevicePreference preference =
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
mDeviceListPreferenceFragment);
|
||||
assertThat(preference.isVisible()).isTrue();
|
||||
humanReadableName[0] = false;
|
||||
preference.onDeviceAttributesChanged();
|
||||
assertThat(preference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user