Merge "Show only 1 entry for hearing aid devices without killing the activity." into pi-dev

This commit is contained in:
Isha Bobra
2018-04-16 16:42:33 +00:00
committed by Android (Google) Code Review
9 changed files with 88 additions and 7 deletions

View File

@@ -32,6 +32,9 @@ import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -50,14 +53,21 @@ public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsContro
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private EntityHeaderController mHeaderController;
@Mock
private LocalBluetoothManager mBluetoothManager;
@Mock
private CachedBluetoothDeviceManager mCachedDeviceManager;
@Override
public void setUp() {
super.setUp();
FakeFeatureFactory.setupForTest();
ShadowEntityHeaderController.setUseMock(mHeaderController);
when(mBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
when(mCachedDeviceManager.getHearingAidPairDeviceSummary(mCachedDevice)).thenReturn("abc");
mController =
new BluetoothDetailsHeaderController(mContext, mFragment, mCachedDevice, mLifecycle);
new BluetoothDetailsHeaderController(mContext, mFragment, mCachedDevice, mLifecycle,
mBluetoothManager);
mPreference = new LayoutPreference(mContext, R.layout.settings_entity_header);
mPreference.setKey(mController.getPreferenceKey());
mScreen.addPreference(mPreference);
@@ -86,6 +96,7 @@ public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsContro
verify(mHeaderController).setIcon(any(Drawable.class));
verify(mHeaderController).setIconContentDescription(any(String.class));
verify(mHeaderController).setSummary(any(String.class));
verify(mHeaderController).setSecondSummary(any(String.class));
verify(mHeaderController).done(mActivity, true);
}

View File

@@ -106,6 +106,16 @@ public class BluetoothDeviceUpdaterTest {
assertThat(mBluetoothDeviceUpdater.mPreferenceMap.containsKey(mBluetoothDevice)).isFalse();
}
@Test
public void testOnDeviceDeleted_deviceExists_removePreference() {
mBluetoothDeviceUpdater.mPreferenceMap.put(mBluetoothDevice, mPreference);
mBluetoothDeviceUpdater.onDeviceDeleted(mCachedBluetoothDevice);
verify(mDevicePreferenceCallback).onDeviceRemoved(mPreference);
assertThat(mBluetoothDeviceUpdater.mPreferenceMap.containsKey(mBluetoothDevice)).isFalse();
}
@Test
public void testRemovePreference_deviceNotExist_doNothing() {
mBluetoothDeviceUpdater.removePreference(mCachedBluetoothDevice);

View File

@@ -115,18 +115,22 @@ public class EntityHeaderControllerTest {
final View header =
mLayoutInflater.inflate(R.layout.settings_entity_header, null /* root */);
final TextView label = header.findViewById(R.id.entity_header_title);
final TextView version = header.findViewById(R.id.entity_header_summary);
final TextView summary = header.findViewById(R.id.entity_header_summary);
final TextView secondSummary = header.findViewById(R.id.entity_header_second_summary);
mController = EntityHeaderController.newInstance(mActivity, mFragment, header);
mController.setLabel(testString);
mController.setSummary(testString);
mController.setSecondSummary(testString);
mController.setIcon(mShadowContext.getDrawable(R.drawable.ic_add));
mController.done(mActivity);
assertThat(label).isNotNull();
assertThat(label.getText()).isEqualTo(testString);
assertThat(version).isNotNull();
assertThat(version.getText()).isEqualTo(testString);
assertThat(summary).isNotNull();
assertThat(summary.getText()).isEqualTo(testString);
assertThat(secondSummary).isNotNull();
assertThat(secondSummary.getText()).isEqualTo(testString);
}
@Test