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