use of com.amplifyframework.core.Action in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testDeleteUser.
/**
* Tests that a successful request to delete the currently signed in user will
* propagate a completion back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testDeleteUser() throws InterruptedException {
// Arrange an invocation of the success Action
doAnswer(invocation -> {
// 0 = onComplete, 1 = onFailure
Action onCompletion = invocation.getArgument(0);
onCompletion.call();
return null;
}).when(delegate).deleteUser(anyAction(), anyConsumer());
// Act: call the binding
TestObserver<Void> observer = auth.deleteUser().test();
// Assert: Completable completes with success
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertComplete();
}
use of com.amplifyframework.core.Action in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testSignOutSucceeds.
/**
* Validates that a successful sign-out will propagate up into the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testSignOutSucceeds() throws InterruptedException {
// Arrange an invocation of the success action
doAnswer(invocation -> {
// 0 = onComplete, 1 = onFailure
int positionOfCompletionAction = 0;
Action onComplete = invocation.getArgument(positionOfCompletionAction);
onComplete.call();
return null;
}).when(delegate).signOut(anyAction(), anyConsumer());
// Act: call the binding
TestObserver<Void> observer = auth.signOut().test();
// Assert: Completable completes successfully
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertComplete();
}
use of com.amplifyframework.core.Action 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.core.Action in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testForgetCurrentDevice.
/**
* Tests that a successful request to forget current auth device will propagate a completion
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testForgetCurrentDevice() throws InterruptedException {
// Arrange an invocation of the success Action
doAnswer(invocation -> {
// 0 = onComplete, 1 = onFailure
Action onCompletion = invocation.getArgument(0);
onCompletion.call();
return null;
}).when(delegate).forgetDevice(anyAction(), anyConsumer());
// Act: call the binding
TestObserver<Void> observer = auth.forgetDevice().test();
// Assert: Completable completes with success
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertComplete();
}
use of com.amplifyframework.core.Action in project amplify-android by aws-amplify.
the class RxDataStoreBindingTest method observeCompletesWhenCategoryBehaviorDoes.
/**
* The Rx binding for the DataStore's observe method is an Observable. It should
* complete when the Rx binding's completion callback is triggered.
* @throws InterruptedException If interrupted while test observer is awaiting terminal event
*/
@Test
public void observeCompletesWhenCategoryBehaviorDoes() throws InterruptedException {
// Category behavior is arranged to complete
doAnswer(invocation -> {
// 0 = clazz, 1 = onStart, 2 = onNext, 3 = onFailure, 4 = onComplete
final int positionOfOnStart = 2;
Consumer<Cancelable> onStart = invocation.getArgument(positionOfOnStart);
onStart.accept(new NoOpCancelable());
final int positionOfOnComplete = 4;
Action onComplete = invocation.getArgument(positionOfOnComplete);
onComplete.call();
// "void"
return null;
}).when(delegate).observe(eq(Model.class), anyConsumer(), anyConsumer(), anyConsumer(), anyAction());
// Act: observe via Rx binding
TestObserver<DataStoreItemChange<Model>> observer = rxDataStore.observe(Model.class).test();
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertComplete();
verify(delegate).observe(eq(Model.class), anyConsumer(), anyConsumer(), anyConsumer(), anyAction());
}
Aggregations