Search in sources :

Example 61 with TestObserver

use of io.reactivex.observers.TestObserver in project reark by reark.

the class GitHubRepositoryStoreCoreTest method put_WithTwoDifferentIds_StoresTwoValues.

// PUT
@Test
public void put_WithTwoDifferentIds_StoresTwoValues() throws InterruptedException {
    final GitHubRepository value1 = create(100, "test name 1");
    final GitHubRepository value2 = create(200, "test name 2");
    TestObserver<GitHubRepository> testObserver1 = new TestObserver<>();
    TestObserver<GitHubRepository> testObserver2 = new TestObserver<>();
    gitHubRepositoryStoreCore.put(100, value1);
    gitHubRepositoryStoreCore.put(200, value2);
    Thread.sleep(PROVIDER_WAIT_TIME);
    gitHubRepositoryStoreCore.getCached(100).subscribe(testObserver1);
    gitHubRepositoryStoreCore.getCached(200).subscribe(testObserver2);
    testObserver1.awaitDone(PROVIDER_WAIT_TIME, TimeUnit.MILLISECONDS).assertComplete().assertNoErrors().assertValue(value1);
    testObserver2.awaitDone(PROVIDER_WAIT_TIME, TimeUnit.MILLISECONDS).assertComplete().assertNoErrors().assertValue(value2);
}
Also used : TestObserver(io.reactivex.observers.TestObserver) GitHubRepository(io.reark.rxgithubapp.shared.pojo.GitHubRepository) Test(org.junit.Test)

Example 62 with TestObserver

use of io.reactivex.observers.TestObserver in project reark by reark.

the class GitHubRepositoryStoreCoreTest method getStream_WithId_EmitsValuesForId_AndDoesNotComplete.

// GET STREAM
@Test
public void getStream_WithId_EmitsValuesForId_AndDoesNotComplete() {
    final GitHubRepository value1 = create(100, "test name 1");
    final GitHubRepository value2 = create(200, "test name 2");
    TestObserver<GitHubRepository> testObserver1 = new TestObserver<>();
    TestObserver<GitHubRepository> testObserver2 = new TestObserver<>();
    gitHubRepositoryStoreCore.getStream(100).subscribe(testObserver1);
    gitHubRepositoryStoreCore.getStream(200).subscribe(testObserver2);
    gitHubRepositoryStoreCore.put(100, value1);
    gitHubRepositoryStoreCore.put(200, value2);
    testObserver1.awaitDone(PROVIDER_WAIT_TIME, TimeUnit.MILLISECONDS).assertNotComplete().assertNoErrors().assertValue(value1);
    testObserver2.awaitDone(PROVIDER_WAIT_TIME, TimeUnit.MILLISECONDS).assertNotComplete().assertNoErrors().assertValue(value2);
}
Also used : TestObserver(io.reactivex.observers.TestObserver) GitHubRepository(io.reark.rxgithubapp.shared.pojo.GitHubRepository) Test(org.junit.Test)

Example 63 with TestObserver

use of io.reactivex.observers.TestObserver in project apollo-android by apollographql.

the class Rx2ApolloTest method callIsCanceledWhenDisposed.

@Test
public void callIsCanceledWhenDisposed() throws Exception {
    server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_WITH_ID));
    TestObserver<Response<EpisodeHeroNameQuery.Data>> testObserver = new TestObserver<>();
    Disposable disposable = Rx2Apollo.from(apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE)))).subscribeWith(testObserver);
    disposable.dispose();
    testObserver.assertComplete();
    assertThat(testObserver.isDisposed()).isTrue();
}
Also used : Utils.mockResponse(com.apollographql.apollo.Utils.mockResponse) Response(com.apollographql.apollo.api.Response) Disposable(io.reactivex.disposables.Disposable) EpisodeHeroNameQuery(com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 64 with TestObserver

use of io.reactivex.observers.TestObserver in project apollo-android by apollographql.

the class Rx2ApolloTest method prefetchIsCanceledWhenDisposed.

@Test
public void prefetchIsCanceledWhenDisposed() throws Exception {
    server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_WITH_ID));
    TestObserver<EpisodeHeroNameQuery.Data> testObserver = new TestObserver<>();
    Disposable disposable = Rx2Apollo.from(apolloClient.prefetch(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE)))).observeOn(new TestScheduler()).subscribeWith(testObserver);
    disposable.dispose();
    testObserver.assertNotComplete();
    assertThat(testObserver.isDisposed()).isTrue();
}
Also used : Disposable(io.reactivex.disposables.Disposable) EpisodeHeroNameQuery(com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery) TestScheduler(io.reactivex.schedulers.TestScheduler) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 65 with TestObserver

use of io.reactivex.observers.TestObserver in project apollo-android by apollographql.

the class Rx2ApolloTest method queryWatcherUpdatedSameQueryDifferentResults.

@Test
@SuppressWarnings("CheckReturnValue")
public void queryWatcherUpdatedSameQueryDifferentResults() throws Exception {
    server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_WITH_ID));
    TestObserver<EpisodeHeroNameQuery.Data> observer = new TestObserver<>();
    Rx2Apollo.from(apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE))).watcher()).map(new Function<Response<EpisodeHeroNameQuery.Data>, EpisodeHeroNameQuery.Data>() {

        @Override
        public EpisodeHeroNameQuery.Data apply(Response<EpisodeHeroNameQuery.Data> response) throws Exception {
            return response.data();
        }
    }).subscribeWith(observer);
    server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_CHANGE));
    apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE))).responseFetcher(NETWORK_ONLY).enqueue(null);
    observer.assertValueCount(2).assertValueAt(0, new Predicate<EpisodeHeroNameQuery.Data>() {

        @Override
        public boolean test(EpisodeHeroNameQuery.Data data) throws Exception {
            assertThat(data.hero().name()).isEqualTo("R2-D2");
            return true;
        }
    }).assertValueAt(1, new Predicate<EpisodeHeroNameQuery.Data>() {

        @Override
        public boolean test(EpisodeHeroNameQuery.Data data) throws Exception {
            assertThat(data.hero().name()).isEqualTo("Artoo");
            return true;
        }
    });
}
Also used : Utils.mockResponse(com.apollographql.apollo.Utils.mockResponse) Response(com.apollographql.apollo.api.Response) Function(io.reactivex.functions.Function) EpisodeHeroNameQuery(com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery) TestObserver(io.reactivex.observers.TestObserver) Predicate(io.reactivex.functions.Predicate) Test(org.junit.Test)

Aggregations

TestObserver (io.reactivex.observers.TestObserver)158 Test (org.junit.Test)128 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)31 TargetApi (android.annotation.TargetApi)21 Matchers.anyString (org.mockito.Matchers.anyString)21 StorIOException (com.pushtorefresh.storio3.StorIOException)19 TestException (io.reactivex.exceptions.TestException)19 Observable (io.reactivex.Observable)12 BaseTest (io.rx_cache2.internal.common.BaseTest)12 Completable (io.reactivex.Completable)11 Disposable (io.reactivex.disposables.Disposable)11 InOrder (org.mockito.InOrder)10 TestScheduler (io.reactivex.schedulers.TestScheduler)9 StorIOSQLite (com.pushtorefresh.storio3.sqlite.StorIOSQLite)8 EpisodeHeroNameQuery (com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery)7 Schedulers (io.reactivex.schedulers.Schedulers)6 Activity (android.app.Activity)5 Instrumentation (android.app.Instrumentation)5 ContentValues (android.content.ContentValues)5 Context (android.content.Context)5