Merge "Bluetooth: Dismiss pairing dialog on user click" into oc-dev am: fdd8d3f6ae

am: a16bcf17d4

Change-Id: I7e8341383751e04f12f163bbe56eb90376ef491b
This commit is contained in:
Jack He
2017-04-27 00:40:57 +00:00
committed by android-build-merger
4 changed files with 118 additions and 18 deletions

View File

@@ -54,9 +54,13 @@ public class BluetoothPairingDialogTest {
@Mock
private BluetoothPairingController controller;
@Mock
private BluetoothPairingDialog dialogActivity;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
doNothing().when(dialogActivity).dismiss();
}
@Test
@@ -214,6 +218,17 @@ public class BluetoothPairingDialogTest {
fail("Setting the controller multiple times should throw an exception.");
}
@Test(expected = IllegalStateException.class)
public void dialogDoesNotAllowSwappingActivity() {
// instantiate a fragment
BluetoothPairingDialogFragment frag = new BluetoothPairingDialogFragment();
frag.setPairingDialogActivity(dialogActivity);
// this should throw an error
frag.setPairingDialogActivity(dialogActivity);
fail("Setting the dialog activity multiple times should throw an exception.");
}
@Test
public void dialogPositiveButtonDisabledWhenUserInputInvalid() {
// set the correct dialog type
@@ -342,11 +357,52 @@ public class BluetoothPairingDialogTest {
.contains(device);
}
@Test
public void pairingDialogDismissedOnPositiveClick() {
// set the dialog variant to confirmation/consent
when(controller.getDialogType()).thenReturn(BluetoothPairingController.CONFIRMATION_DIALOG);
// we don't care what this does, just that it is called
doNothing().when(controller).onDialogPositiveClick(any());
// build the fragment
BluetoothPairingDialogFragment frag = makeFragment();
// click the button and verify that the controller hook was called
frag.onClick(frag.getmDialog(), AlertDialog.BUTTON_POSITIVE);
verify(controller, times(1)).onDialogPositiveClick(any());
verify(dialogActivity, times(1)).dismiss();
}
@Test
public void pairingDialogDismissedOnNegativeClick() {
// set the dialog variant to confirmation/consent
when(controller.getDialogType()).thenReturn(BluetoothPairingController.CONFIRMATION_DIALOG);
// we don't care what this does, just that it is called
doNothing().when(controller).onDialogNegativeClick(any());
// build the fragment
BluetoothPairingDialogFragment frag = makeFragment();
// click the button and verify that the controller hook was called
frag.onClick(frag.getmDialog(), AlertDialog.BUTTON_NEGATIVE);
verify(controller, times(1)).onDialogNegativeClick(any());
verify(dialogActivity, times(1)).dismiss();
}
private BluetoothPairingDialogFragment makeFragment() {
BluetoothPairingDialogFragment frag = new BluetoothPairingDialogFragment();
assertThat(frag.isPairingControllerSet()).isFalse();
frag.setPairingController(controller);
assertThat(frag.isPairingDialogActivitySet()).isFalse();
frag.setPairingDialogActivity(dialogActivity);
FragmentTestUtil.startFragment(frag);
assertThat(frag.getmDialog()).isNotNull();
assertThat(frag.isPairingControllerSet()).isTrue();
assertThat(frag.isPairingDialogActivitySet()).isTrue();
return frag;
}
}