Search in sources :

Example 56 with TestSubscriber

use of rx.observers.TestSubscriber in project retrofit by square.

the class AsyncTest method success.

@Test
public void success() throws InterruptedException {
    TestSubscriber<Void> subscriber = new TestSubscriber<>();
    service.completable().subscribe(subscriber);
    assertFalse(subscriber.awaitValueCount(1, 1, SECONDS));
    server.enqueue(new MockResponse());
    subscriber.awaitTerminalEvent(1, SECONDS);
    subscriber.assertCompleted();
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) TestSubscriber(rx.observers.TestSubscriber) Test(org.junit.Test)

Example 57 with TestSubscriber

use of rx.observers.TestSubscriber in project retrofit by square.

the class AsyncTest method throwingInOnCompleteDeliveredToPlugin.

@Test
public void throwingInOnCompleteDeliveredToPlugin() throws InterruptedException {
    server.enqueue(new MockResponse());
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Throwable> errorRef = new AtomicReference<>();
    RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {

        @Override
        public void handleError(Throwable throwable) {
            if (!errorRef.compareAndSet(null, throwable)) {
                // Don't swallow secondary errors!
                throw Exceptions.propagate(throwable);
            }
            latch.countDown();
        }
    });
    final TestSubscriber<Void> subscriber = new TestSubscriber<>();
    final RuntimeException e = new RuntimeException();
    service.completable().unsafeSubscribe(new AsyncCompletableSubscriber() {

        @Override
        public void onCompleted() {
            throw e;
        }

        @Override
        public void onError(Throwable t) {
            subscriber.onError(t);
        }
    });
    latch.await(1, SECONDS);
    assertThat(errorRef.get()).isSameAs(e);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) RxJavaErrorHandler(rx.plugins.RxJavaErrorHandler) AsyncCompletableSubscriber(rx.observers.AsyncCompletableSubscriber) TestSubscriber(rx.observers.TestSubscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 58 with TestSubscriber

use of rx.observers.TestSubscriber in project retrofit by square.

the class AsyncTest method bodyThrowingInOnErrorDeliveredToPlugin.

@Test
public void bodyThrowingInOnErrorDeliveredToPlugin() throws InterruptedException {
    server.enqueue(new MockResponse().setResponseCode(404));
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
    RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {

        @Override
        public void handleError(Throwable throwable) {
            if (!pluginRef.compareAndSet(null, throwable)) {
                // Don't swallow secondary errors!
                throw Exceptions.propagate(throwable);
            }
            latch.countDown();
        }
    });
    final TestSubscriber<Void> subscriber = new TestSubscriber<>();
    final RuntimeException e = new RuntimeException();
    final AtomicReference<Throwable> errorRef = new AtomicReference<>();
    service.completable().unsafeSubscribe(new AsyncCompletableSubscriber() {

        @Override
        public void onCompleted() {
            subscriber.onCompleted();
        }

        @Override
        public void onError(Throwable t) {
            errorRef.set(t);
            throw e;
        }
    });
    latch.await(1, SECONDS);
    //noinspection ThrowableResultOfMethodCallIgnored
    CompositeException composite = (CompositeException) pluginRef.get();
    assertThat(composite.getExceptions()).containsExactly(errorRef.get(), e);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) RxJavaErrorHandler(rx.plugins.RxJavaErrorHandler) AsyncCompletableSubscriber(rx.observers.AsyncCompletableSubscriber) CompositeException(rx.exceptions.CompositeException) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) TestSubscriber(rx.observers.TestSubscriber) Test(org.junit.Test)

Example 59 with TestSubscriber

use of rx.observers.TestSubscriber 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);
}
Also used : TestSubscriber(rx.observers.TestSubscriber) List(java.util.List) TestScheduler(rx.schedulers.TestScheduler) Test(org.junit.Test)

Example 60 with TestSubscriber

use of rx.observers.TestSubscriber 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);
}
Also used : TestSubscriber(rx.observers.TestSubscriber) List(java.util.List) TestScheduler(rx.schedulers.TestScheduler) Test(org.junit.Test)

Aggregations

TestSubscriber (rx.observers.TestSubscriber)238 Test (org.junit.Test)213 Intent (android.content.Intent)48 Environment (com.kickstarter.libs.Environment)43 Cursor (android.database.Cursor)36 Changes (com.pushtorefresh.storio.contentresolver.Changes)34 Project (com.kickstarter.models.Project)33 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)21 MockApiClient (com.kickstarter.services.MockApiClient)21 ApiClientType (com.kickstarter.services.ApiClientType)20 TargetApi (android.annotation.TargetApi)18 CurrentUserType (com.kickstarter.libs.CurrentUserType)18 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)18 StorIOException (com.pushtorefresh.storio.StorIOException)17 TestCollapserTimer (com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer)16 Matchers.anyString (org.mockito.Matchers.anyString)16 User (com.kickstarter.models.User)15 PutResult (com.pushtorefresh.storio.contentresolver.operations.put.PutResult)15 Uri (android.net.Uri)14 NonNull (android.support.annotation.NonNull)14