use of io.reactivex.observers.TestObserver in project storio by pushtorefresh.
the class PreparedExecuteSQLTest method shouldWrapExceptionIntoStorIOExceptionCompletable.
@Test
public void shouldWrapExceptionIntoStorIOExceptionCompletable() {
final Stub stub = Stub.newInstanceApplyNotEmptyAffectedTablesAndTags();
IllegalStateException testException = new IllegalStateException("test exception");
doThrow(testException).when(stub.lowLevel).executeSQL(stub.rawQuery);
final TestObserver<Object> testObserver = new TestObserver<Object>();
stub.storIOSQLite.executeSQL().withQuery(stub.rawQuery).prepare().asRxCompletable().subscribe(testObserver);
testObserver.awaitTerminalEvent();
testObserver.assertNoValues();
testObserver.assertError(StorIOException.class);
// noinspection ThrowableResultOfMethodCallIgnored
StorIOException expected = (StorIOException) testObserver.errors().get(0);
IllegalStateException cause = (IllegalStateException) expected.getCause();
assertThat(cause).hasMessage("test exception");
verify(stub.storIOSQLite).executeSQL();
verify(stub.storIOSQLite).defaultRxScheduler();
verify(stub.storIOSQLite).lowLevel();
verify(stub.lowLevel).executeSQL(stub.rawQuery);
verify(stub.storIOSQLite).interceptors();
verifyNoMoreInteractions(stub.storIOSQLite, stub.lowLevel);
}
use of io.reactivex.observers.TestObserver in project sqlbrite by square.
the class QueryTest method mapToOneOrDefaultReturnsDefaultWhenNullCursor.
@Test
public void mapToOneOrDefaultReturnsDefaultWhenNullCursor() {
Employee defaultEmployee = new Employee("bob", "Bob Bobberson");
Query nully = new Query() {
@Nullable
@Override
public Cursor run() {
return null;
}
};
TestObserver<Employee> observer = new TestObserver<>();
Observable.just(nully).lift(Query.mapToOneOrDefault(MAPPER, defaultEmployee)).subscribe(observer);
observer.assertValues(defaultEmployee);
observer.assertComplete();
}
use of io.reactivex.observers.TestObserver in project sqlbrite by square.
the class QueryTest method mapToListIgnoresNullCursor.
@Test
public void mapToListIgnoresNullCursor() {
Query nully = new Query() {
@Nullable
@Override
public Cursor run() {
return null;
}
};
TestObserver<List<Employee>> subscriber = new TestObserver<>();
Observable.just(nully).lift(Query.mapToList(MAPPER)).subscribe(subscriber);
subscriber.assertNoValues();
subscriber.assertComplete();
}
use of io.reactivex.observers.TestObserver in project Store by NYTimes.
the class StoreRefreshWhenStaleTest method diskWasNotRefreshedWhenFreshRecord.
@Test
public void diskWasNotRefreshedWhenFreshRecord() {
when(fetcher.fetch(barCode)).thenReturn(Single.just(network1));
when(persister.read(barCode)).thenReturn(// get should return from disk
Maybe.just(disk1)).thenReturn(// backfill should read from disk again
Maybe.just(disk2));
when(persister.getRecordState(barCode)).thenReturn(RecordState.FRESH);
when(persister.write(barCode, network1)).thenReturn(Single.just(true));
TestObserver testObserver = store.get(barCode).test();
testObserver.awaitTerminalEvent();
testObserver.assertNoErrors();
testObserver.assertResult(disk1);
verify(fetcher, times(0)).fetch(barCode);
verify(persister, times(1)).getRecordState(barCode);
store.clear(barCode);
testObserver = store.get(barCode).test();
testObserver.awaitTerminalEvent();
testObserver.assertResult(disk2);
verify(fetcher, times(0)).fetch(barCode);
verify(persister, times(2)).getRecordState(barCode);
}
use of io.reactivex.observers.TestObserver in project RxCache by VictorAlbertos.
the class ProcessorProvidersTest method When_No_Loader_And_Cache_Expired_But_Use_Expired_Data_If_Loader_Not_Available_Then_Get_Mock.
@Test
public void When_No_Loader_And_Cache_Expired_But_Use_Expired_Data_If_Loader_Not_Available_Then_Get_Mock() {
processorProvidersUT = new io.rx_cache2.internal.ProcessorProvidersBehaviour(twoLayersCacheMock, false, evictExpiredRecordsPersistence, getDeepCopy, doMigrations);
TestObserver observerMock = getSubscriberCompleted(true, true, false, Loader.NULL, true);
assertThat(observerMock.errorCount(), is(0));
assertThat(observerMock.valueCount(), is(1));
}
Aggregations