Search in sources :

Example 1 with DeviceOperations

use of com.amazonaws.mobile.client.DeviceOperations in project amplify-android by aws-amplify.

the class AuthComponentTest method forgetCurrentDevice.

/**
 * Tests that forgetDevice calls the AWSMobileClient forget device method to forget
 * the current device.
 * @throws AuthException test fails if this gets thrown since method should succeed
 */
@Test
public void forgetCurrentDevice() throws AuthException {
    DeviceOperations deviceOps = mock(DeviceOperations.class);
    when(mobileClient.getDeviceOperations()).thenReturn(deviceOps);
    doAnswer(invocation -> {
        Callback<Void> callback = invocation.getArgument(0);
        callback.onResult(null);
        return null;
    }).when(deviceOps).forget(Mockito.<Callback<Void>>any());
    synchronousAuth.forgetDevice();
    verify(mobileClient.getDeviceOperations()).forget(Mockito.<Callback<Void>>any());
}
Also used : DeviceOperations(com.amazonaws.mobile.client.DeviceOperations) Test(org.junit.Test)

Example 2 with DeviceOperations

use of com.amazonaws.mobile.client.DeviceOperations 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 DeviceOperations

use of com.amazonaws.mobile.client.DeviceOperations in project amplify-android by aws-amplify.

the class AuthComponentTest method rememberCurrentDevice.

/**
 * Tests that rememberDevice calls the AWSMobileClient device update status method to set
 * remember status to true.
 * @throws AuthException test fails if this gets thrown since method should succeed
 */
@Test
public void rememberCurrentDevice() 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).updateStatus(anyBoolean(), any());
    synchronousAuth.rememberDevice();
    verify(mobileClient.getDeviceOperations()).updateStatus(eq(true), any());
}
Also used : DeviceOperations(com.amazonaws.mobile.client.DeviceOperations) Test(org.junit.Test)

Example 4 with DeviceOperations

use of com.amazonaws.mobile.client.DeviceOperations in project amplify-android by aws-amplify.

the class AuthComponentTest method fetchDevices.

/**
 * Tests that fetchDevices calls the AWSMobileClient list devices method to obtain
 * a list of remembered devices.
 * @throws AuthException test fails if this gets thrown since method should succeed
 */
@Test
public void fetchDevices() throws AuthException {
    ListDevicesResult listResult = new ListDevicesResult(new ArrayList<>(), null);
    DeviceOperations deviceOps = mock(DeviceOperations.class);
    when(mobileClient.getDeviceOperations()).thenReturn(deviceOps);
    doAnswer(invocation -> {
        Callback<ListDevicesResult> callback = invocation.getArgument(0);
        callback.onResult(listResult);
        return null;
    }).when(deviceOps).list(any());
    synchronousAuth.fetchDevices();
    verify(mobileClient.getDeviceOperations()).list(any());
}
Also used : ListDevicesResult(com.amazonaws.mobile.client.results.ListDevicesResult) DeviceOperations(com.amazonaws.mobile.client.DeviceOperations) Test(org.junit.Test)

Aggregations

DeviceOperations (com.amazonaws.mobile.client.DeviceOperations)4 Test (org.junit.Test)4 ListDevicesResult (com.amazonaws.mobile.client.results.ListDevicesResult)1 AuthDevice (com.amplifyframework.auth.AuthDevice)1