Search in sources :

Example 1 with AuthDevice

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();
}
Also used : Matchers.anyAction(com.amplifyframework.rx.Matchers.anyAction) Action(com.amplifyframework.core.Action) AuthDevice(com.amplifyframework.auth.AuthDevice) Test(org.junit.Test)

Example 2 with AuthDevice

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());
}
Also used : AuthDevice(com.amplifyframework.auth.AuthDevice) DeviceOperations(com.amazonaws.mobile.client.DeviceOperations) Test(org.junit.Test)

Example 3 with AuthDevice

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);
}
Also used : AuthDevice(com.amplifyframework.auth.AuthDevice) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

AuthDevice (com.amplifyframework.auth.AuthDevice)3 Test (org.junit.Test)3 DeviceOperations (com.amazonaws.mobile.client.DeviceOperations)1 Action (com.amplifyframework.core.Action)1 Matchers.anyAction (com.amplifyframework.rx.Matchers.anyAction)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1