use of io.reactivex.observers.TestObserver in project apollo-android by apollographql.
the class Rx2ApolloTest method queryWatcherNotCalledWhenCanceled.
@Test
public void queryWatcherNotCalledWhenCanceled() throws Exception {
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_WITH_ID));
TestObserver<EpisodeHeroNameQuery.Data> testObserver = new TestObserver<>();
TestScheduler scheduler = new TestScheduler();
Disposable disposable = 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();
}
}).observeOn(scheduler).subscribeWith(testObserver);
scheduler.triggerActions();
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_CHANGE));
apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE))).responseFetcher(NETWORK_ONLY).enqueue(null);
disposable.dispose();
scheduler.triggerActions();
testObserver.assertValueCount(1).assertValueAt(0, new Predicate<EpisodeHeroNameQuery.Data>() {
@Override
public boolean test(EpisodeHeroNameQuery.Data data) throws Exception {
assertThat(data.hero().name()).isEqualTo("R2-D2");
return true;
}
});
}
use of io.reactivex.observers.TestObserver in project storio by pushtorefresh.
the class SingleOnSubscribeExecuteAsBlockingOptionalTest method shouldCallOnErrorIfExceptionOccurred.
@SuppressWarnings("CheckResult")
@Test
public void shouldCallOnErrorIfExceptionOccurred() {
// noinspection unchecked
final PreparedOperation<Object, Optional<Object>, Object> preparedOperation = mock(PreparedOperation.class);
StorIOException expectedException = new StorIOException("test exception");
when(preparedOperation.executeAsBlocking()).thenThrow(expectedException);
TestObserver<Optional<Object>> testObserver = new TestObserver<Optional<Object>>();
Single<Optional<Object>> single = Single.create(new SingleOnSubscribeExecuteAsBlockingOptional<Object, Object>(preparedOperation));
verifyZeroInteractions(preparedOperation);
single.subscribe(testObserver);
testObserver.assertError(expectedException);
testObserver.assertNotComplete();
verify(preparedOperation).executeAsBlocking();
}
use of io.reactivex.observers.TestObserver in project storio by pushtorefresh.
the class CompletableOnSubscribeExecuteAsBlockingTest method shouldExecuteAsBlockingAfterSubscription.
@SuppressWarnings("ResourceType")
@Test
public void shouldExecuteAsBlockingAfterSubscription() {
final PreparedCompletableOperation preparedOperation = mock(PreparedCompletableOperation.class);
TestObserver testObserver = new TestObserver();
verifyZeroInteractions(preparedOperation);
Completable completable = Completable.create(new CompletableOnSubscribeExecuteAsBlocking(preparedOperation));
verifyZeroInteractions(preparedOperation);
completable.subscribe(testObserver);
testObserver.assertNoErrors();
testObserver.assertComplete();
verify(preparedOperation).executeAsBlocking();
verify(preparedOperation, never()).asRxFlowable(any(BackpressureStrategy.class));
verify(preparedOperation, never()).asRxSingle();
verify(preparedOperation, never()).asRxCompletable();
}
use of io.reactivex.observers.TestObserver in project storio by pushtorefresh.
the class MaybeOnSubscribeExecuteAsBlockingTest method shouldCallOnErrorIfExceptionOccurred.
@SuppressWarnings("CheckResult")
@Test
public void shouldCallOnErrorIfExceptionOccurred() {
// noinspection unchecked
final PreparedMaybeOperation<Object, Object, Object> preparedOperation = mock(PreparedMaybeOperation.class);
StorIOException expectedException = new StorIOException("test exception");
when(preparedOperation.executeAsBlocking()).thenThrow(expectedException);
TestObserver<Object> testObserver = new TestObserver<Object>();
Maybe<Object> maybe = Maybe.create(new MaybeOnSubscribeExecuteAsBlocking<Object, Object, Object>(preparedOperation));
verifyZeroInteractions(preparedOperation);
maybe.subscribe(testObserver);
testObserver.assertError(expectedException);
testObserver.assertNotComplete();
verify(preparedOperation).executeAsBlocking();
}
use of io.reactivex.observers.TestObserver in project storio by pushtorefresh.
the class PreparedGetNumberOfResultsTest method shouldWrapExceptionIntoStorIOExceptionForSingle.
@Test
public void shouldWrapExceptionIntoStorIOExceptionForSingle() {
final StorIOContentResolver storIOContentResolver = mock(StorIOContentResolver.class);
Uri testUri = mock(Uri.class);
// noinspection unchecked
final GetResolver<Integer> getResolver = mock(GetResolver.class);
when(getResolver.performGet(eq(storIOContentResolver), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
final TestObserver<Integer> testObserver = new TestObserver<Integer>();
new PreparedGetNumberOfResults.Builder(storIOContentResolver).withQuery(Query.builder().uri(testUri).build()).withGetResolver(getResolver).prepare().asRxSingle().subscribe(testObserver);
testObserver.awaitTerminalEvent(60, SECONDS);
testObserver.assertError(StorIOException.class);
assertThat(testObserver.errors()).hasSize(1);
StorIOException storIOException = (StorIOException) testObserver.errors().get(0);
IllegalStateException cause = (IllegalStateException) storIOException.getCause();
assertThat(cause).hasMessage("test exception");
testObserver.dispose();
}
Aggregations