Search in sources :

Example 81 with TestObserver

use of io.reactivex.observers.TestObserver in project RxCache by VictorAlbertos.

the class ProcessorProvidersTest method When_No_Loader_And_Not_Cache_Then_Get_Throw_Exception.

@Test
public void When_No_Loader_And_Not_Cache_Then_Get_Throw_Exception() {
    TestObserver observerMock = getSubscriberCompleted(false, false, false, Loader.NULL, false);
    assertThat(observerMock.errorCount(), is(1));
    assertThat(observerMock.valueCount(), is(0));
}
Also used : TestObserver(io.reactivex.observers.TestObserver) BaseTest(io.rx_cache2.internal.common.BaseTest) Test(org.junit.Test)

Example 82 with TestObserver

use of io.reactivex.observers.TestObserver in project RxCache by VictorAlbertos.

the class ProcessorProvidersTest method When_Loader_Throws_Exception_And_Cache_Expired_Then_Get_Throw_Exception.

@Test
public void When_Loader_Throws_Exception_And_Cache_Expired_Then_Get_Throw_Exception() {
    TestObserver observerMock = getSubscriberCompleted(true, true, false, Loader.EXCEPTION, false);
    assertThat(observerMock.errorCount(), is(1));
    assertThat(observerMock.valueCount(), is(0));
}
Also used : TestObserver(io.reactivex.observers.TestObserver) BaseTest(io.rx_cache2.internal.common.BaseTest) Test(org.junit.Test)

Example 83 with TestObserver

use of io.reactivex.observers.TestObserver in project RxCache by VictorAlbertos.

the class ProcessorProvidersTest method getSubscriberCompleted.

private TestObserver getSubscriberCompleted(boolean hasCache, final boolean evictCache, boolean detailResponse, Loader loader, boolean useExpiredDataIfLoaderNotAvailable) {
    Observable observable;
    switch(loader) {
        case VALID:
            observable = Observable.just(new Mock("message"));
            break;
        case NULL:
            observable = Observable.error(new RuntimeException("No data"));
            break;
        default:
            observable = Observable.create(new ObservableOnSubscribe<Object>() {

                @Override
                public void subscribe(ObservableEmitter<Object> e) throws Exception {
                    throw new RuntimeException("error");
                }
            });
            break;
    }
    ConfigProvider configProvider = new ConfigProvider("mockKey", null, null, detailResponse, true, false, "", "", observable, new EvictProvider(evictCache));
    if (hasCache)
        twoLayersCacheMock.save("mockKey", "", "", new Mock("message"), configProvider.getLifeTimeMillis(), configProvider.isExpirable(), configProvider.isEncrypted());
    processorProvidersUT = new ProcessorProvidersBehaviour(twoLayersCacheMock, useExpiredDataIfLoaderNotAvailable, evictExpiredRecordsPersistence, getDeepCopy, doMigrations);
    TestObserver observerMock = processorProvidersUT.getData(configProvider).test();
    observerMock.awaitTerminalEvent();
    return observerMock;
}
Also used : ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) ConfigProvider(io.rx_cache2.ConfigProvider) EvictProvider(io.rx_cache2.EvictProvider) Observable(io.reactivex.Observable) ObservableEmitter(io.reactivex.ObservableEmitter) TestObserver(io.reactivex.observers.TestObserver)

Example 84 with TestObserver

use of io.reactivex.observers.TestObserver in project RxCache by VictorAlbertos.

the class ProcessorProvidersTest method When_Evict_Cache_Then_Source_Retrieved_Is_Cloud.

@Test
public void When_Evict_Cache_Then_Source_Retrieved_Is_Cloud() {
    TestObserver observerMock = getSubscriberCompleted(true, true, true, Loader.VALID, false);
    Reply<Mock> reply = (Reply) observerMock.values().get(0);
    assertThat(reply.getSource(), is(Source.CLOUD));
    assertNotNull(reply.getData());
}
Also used : Reply(io.rx_cache2.Reply) TestObserver(io.reactivex.observers.TestObserver) BaseTest(io.rx_cache2.internal.common.BaseTest) Test(org.junit.Test)

Example 85 with TestObserver

use of io.reactivex.observers.TestObserver in project mosby by sockeqwe.

the class DisposableIntentObserverTest method error.

@Test
public void error() {
    PublishSubject subject = PublishSubject.create();
    TestObserver sub = new TestObserver<>();
    subject.subscribeWith(sub);
    Exception originalException = new RuntimeException("I am the original Exception");
    Exception expectedException = new IllegalStateException("View intents must not throw errors", originalException);
    try {
        Observable.error(originalException).subscribe(new DisposableIntentObserver(subject));
        Assert.fail("Exception expected");
    } catch (Exception e) {
        Throwable cause = e.getCause();
        Assert.assertEquals(expectedException.getMessage(), cause.getMessage());
        Assert.assertEquals(originalException, cause.getCause());
    }
    sub.assertNotComplete().assertNoValues();
}
Also used : PublishSubject(io.reactivex.subjects.PublishSubject) TestObserver(io.reactivex.observers.TestObserver) 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