Make HearingAid code more generic

-handle UI updating when sub device connection state changes
-add test case

Bug: 112735753
Test: make -j42 RunSettingsRoboTests
Change-Id: Ie2643657c47a0956aac3f8cac4bfdbdea0399ce8
This commit is contained in:
timhypeng
2018-10-09 11:19:23 +08:00
committed by Hugh Chen
parent 2f5200ea5a
commit c95056d7b5
5 changed files with 36 additions and 7 deletions

View File

@@ -63,8 +63,12 @@ public class BluetoothDeviceUpdaterTest {
@Mock
private CachedBluetoothDevice mCachedBluetoothDevice;
@Mock
private CachedBluetoothDevice mSubCachedBluetoothDevice;
@Mock
private BluetoothDevice mBluetoothDevice;
@Mock
private BluetoothDevice mSubBluetoothDevice;
@Mock
private SettingsActivity mSettingsActivity;
@Mock
private LocalBluetoothManager mLocalManager;
@@ -86,6 +90,7 @@ public class BluetoothDeviceUpdaterTest {
mCachedDevices.add(mCachedBluetoothDevice);
doReturn(mContext).when(mDashboardFragment).getContext();
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
when(mSubCachedBluetoothDevice.getDevice()).thenReturn(mSubBluetoothDevice);
when(mLocalManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices);
@@ -146,6 +151,20 @@ public class BluetoothDeviceUpdaterTest {
verify(mDevicePreferenceCallback, never()).onDeviceRemoved(any(Preference.class));
}
@Test
public void testRemovePreference_subDeviceExist_removePreference() {
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mSubCachedBluetoothDevice);
mBluetoothDeviceUpdater.mPreferenceMap.put(mSubBluetoothDevice, mPreference);
assertThat(mBluetoothDeviceUpdater.mPreferenceMap.
containsKey(mSubBluetoothDevice)).isTrue();
mBluetoothDeviceUpdater.removePreference(mCachedBluetoothDevice);
verify(mDevicePreferenceCallback).onDeviceRemoved(mPreference);
assertThat(mBluetoothDeviceUpdater.mPreferenceMap.
containsKey(mSubBluetoothDevice)).isFalse();
}
@Test
public void testDeviceProfilesListener_click_startBluetoothDeviceDetailPage() {
doReturn(mSettingsActivity).when(mDashboardFragment).getContext();