use of com.amplifyframework.auth.AuthDevice in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testForgetSpecificDevice.
/**
* Tests that a successful request to forget a specific auth device will propagate a completion
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testForgetSpecificDevice() throws InterruptedException {
// Arrange an invocation of the success Action
doAnswer(invocation -> {
// 0 = deviceToForget, 1 = onComplete, 2 = onFailure
Action onCompletion = invocation.getArgument(1);
onCompletion.call();
return null;
}).when(delegate).forgetDevice(any(), anyAction(), anyConsumer());
// Act: call the binding
AuthDevice deviceToForget = AuthDevice.fromId(RandomString.string());
TestObserver<Void> observer = auth.forgetDevice(deviceToForget).test();
// Assert: Completable completes with success
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertComplete();
}
use of com.amplifyframework.auth.AuthDevice in project amplify-android by aws-amplify.
the class AuthComponentTest method forgetDevice.
/**
* Tests that forgetDevice calls the AWSMobileClient forget device method to forget
* a device with matching ID.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
public void forgetDevice() throws AuthException {
DeviceOperations deviceOps = mock(DeviceOperations.class);
when(mobileClient.getDeviceOperations()).thenReturn(deviceOps);
doAnswer(invocation -> {
Callback<Void> callback = invocation.getArgument(1);
callback.onResult(null);
return null;
}).when(deviceOps).forget(any(), any());
AuthDevice device = AuthDevice.fromId(RandomString.string());
synchronousAuth.forgetDevice(device);
verify(mobileClient.getDeviceOperations()).forget(eq(device.getDeviceId()), any());
}
use of com.amplifyframework.auth.AuthDevice in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testFetchDevices.
/**
* Tests that a successful request to fetch remembered auth devices will propagate a completion
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testFetchDevices() throws InterruptedException {
// Arrange delegate to furnish a result
AuthDevice device = AuthDevice.fromId(RandomString.string());
List<AuthDevice> expected = Collections.singletonList(device);
doAnswer(invocation -> {
// 0 = onComplete, 1 = onFailure
Consumer<List<AuthDevice>> onCompletion = invocation.getArgument(0);
onCompletion.accept(expected);
return null;
}).when(delegate).fetchDevices(anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<List<AuthDevice>> observer = auth.fetchDevices().test();
// Assert: result was furnished via Rx Single
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(expected);
}
Aggregations