Search in sources :

Example 36 with Action

use of com.amplifyframework.core.Action in project amplify-android by aws-amplify.

the class RxDataStoreBindingTest method stopSucceedsWhenCategoryBehaviorDoes.

/**
 * The Rx binding for the DataStore's stop() method will propagate success
 * faithfully from the underlying delegate.
 * @throws InterruptedException If interrupted while test observer is awaiting terminal event
 */
@Test
public void stopSucceedsWhenCategoryBehaviorDoes() throws InterruptedException {
    // Arrange success in the category behavior
    doAnswer(invocation -> {
        // 0 = onComplete, 1 = onFailure
        final int positionOfOnSuccess = 0;
        Action onSuccess = invocation.getArgument(positionOfOnSuccess);
        onSuccess.call();
        // "void"
        return null;
    }).when(delegate).stop(anyAction(), anyConsumer());
    // Act: stop the store.
    TestObserver<Void> observer = rxDataStore.stop().test();
    // Assert: success propagates through binding.
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertComplete();
}
Also used : Matchers.anyAction(com.amplifyframework.rx.Matchers.anyAction) Action(com.amplifyframework.core.Action) Test(org.junit.Test)

Aggregations

Action (com.amplifyframework.core.Action)36 Test (org.junit.Test)34 Cancelable (com.amplifyframework.core.async.Cancelable)23 Consumer (com.amplifyframework.core.Consumer)21 DataStoreException (com.amplifyframework.datastore.DataStoreException)21 ObserveQueryOptions (com.amplifyframework.core.model.query.ObserveQueryOptions)20 DataStoreQuerySnapshot (com.amplifyframework.datastore.DataStoreQuerySnapshot)20 Arrays (java.util.Arrays)20 List (java.util.List)20 TimeUnit (java.util.concurrent.TimeUnit)20 NoOpAction (com.amplifyframework.core.NoOpAction)19 NoOpConsumer (com.amplifyframework.core.NoOpConsumer)19 QuerySortBy (com.amplifyframework.core.model.query.QuerySortBy)19 BlogOwner (com.amplifyframework.testmodels.commentsblog.BlogOwner)19 Post (com.amplifyframework.testmodels.commentsblog.Post)19 PostStatus (com.amplifyframework.testmodels.commentsblog.PostStatus)19 ArrayList (java.util.ArrayList)19 Collections (java.util.Collections)19 Comparator (java.util.Comparator)19 CountDownLatch (java.util.concurrent.CountDownLatch)19