use of rx.schedulers.TestScheduler in project MovieGuide by esoxjem.
the class MovieDetailsPresenterImplTest method shouldBeAbleToShowTrailers.
@Test
public void shouldBeAbleToShowTrailers() {
TestScheduler testScheduler = new TestScheduler();
TestSubscriber<List<Video>> testSubscriber = new TestSubscriber<>();
Observable<List<Video>> responseObservable = Observable.just(videos).subscribeOn(testScheduler);
responseObservable.subscribe(testSubscriber);
when(movieDetailsInteractor.getTrailers(anyString())).thenReturn(responseObservable);
movieDetailsPresenter.showTrailers(movie);
testScheduler.triggerActions();
testSubscriber.assertNoErrors();
testSubscriber.assertCompleted();
verify(view).showTrailers(videos);
}
use of rx.schedulers.TestScheduler in project MovieGuide by esoxjem.
the class MoviesListingPresenterImplTest method shouldBeAbleToDisplayMovies.
@Test
public void shouldBeAbleToDisplayMovies() {
TestScheduler testScheduler = new TestScheduler();
TestSubscriber<List<Movie>> testSubscriber = new TestSubscriber<>();
Observable<List<Movie>> responseObservable = Observable.just(movies).subscribeOn(testScheduler);
responseObservable.subscribe(testSubscriber);
when(interactor.fetchMovies()).thenReturn(responseObservable);
presenter.setView(view);
testScheduler.triggerActions();
testSubscriber.assertNoErrors();
testSubscriber.onCompleted();
verify(view).showMovies(movies);
}
use of rx.schedulers.TestScheduler in project apollo-android by apollographql.
the class RxApolloTest method queryWatcherNotCalledWhenCanceled.
@Test
public void queryWatcherNotCalledWhenCanceled() throws Exception {
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_WITH_ID));
server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_CHANGE));
final TestSubscriber<Response<EpisodeHeroNameQuery.Data>> testSubscriber = new TestSubscriber<>();
TestScheduler scheduler = new TestScheduler();
Subscription subscription = RxApollo.from(apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE))).watcher()).observeOn(scheduler).subscribe(testSubscriber);
scheduler.triggerActions();
apolloClient.query(new EpisodeHeroNameQuery(Input.fromNullable(EMPIRE))).responseFetcher(NETWORK_ONLY).enqueue(null);
subscription.unsubscribe();
scheduler.triggerActions();
testSubscriber.assertValueCount(1);
assertThat(testSubscriber.getOnNextEvents().get(0).data().hero().name()).isEqualTo("R2-D2");
}
use of rx.schedulers.TestScheduler in project AnDevCon-RxPatterns by colintheshots.
the class Example16Test method test_anomalous_network_event.
@Test
public void test_anomalous_network_event() {
// TestScheduler lets you advance time by hand
TestScheduler scheduler = Schedulers.test();
TestSubscriber<NetworkResponse> subscriber = new TestSubscriber<>();
// Scheduler.Worker lets you schedule events in time
Scheduler.Worker worker = scheduler.createWorker();
// Subjects allow both input and output, so they can be swapped in for
// Retrofit calls to unit test your code.
final PublishSubject<NetworkResponse> networkSubject = PublishSubject.create();
// schedule a first observable event to occur at 1000 ms
worker.schedule(new Action0() {
@Override
public void call() {
networkSubject.onError(new TimeoutException());
}
}, 10000, TimeUnit.MILLISECONDS);
// subscribing so events appear
networkSubject.subscribeOn(scheduler).subscribe(subscriber);
scheduler.advanceTimeBy(20000, TimeUnit.MILLISECONDS);
subscriber.awaitTerminalEvent();
// we use the class-based assertError method, since it's easier to match
subscriber.assertError(TimeoutException.class);
subscriber.assertValueCount(0);
subscriber.assertUnsubscribed();
}
use of rx.schedulers.TestScheduler in project android-oss by kickstarter.
the class SearchViewModelTest method testFeaturedPopularRefTags.
@Test
public void testFeaturedPopularRefTags() {
final TestScheduler scheduler = new TestScheduler();
final List<Project> projects = Arrays.asList(ProjectFactory.allTheWayProject(), ProjectFactory.almostCompletedProject(), ProjectFactory.backedProject());
final MockApiClient apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<DiscoverEnvelope> fetchProjects(@NonNull final DiscoveryParams params) {
return Observable.just(DiscoverEnvelopeFactory.discoverEnvelope(projects));
}
};
final Environment env = environment().toBuilder().scheduler(scheduler).apiClient(apiClient).build();
setUpEnvironment(env);
// populate search and overcome debounce
this.vm.inputs.search("");
scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
this.vm.inputs.projectClicked(projects.get(0));
this.goToRefTag.assertValues(RefTag.searchPopularFeatured());
this.goToProject.assertValues(projects.get(0));
}
Aggregations