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);
}
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);
}
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();
}
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();
}
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;
}
});
}
Aggregations