use of com.pushtorefresh.storio.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class DefaultGetResolverTest method query.
@Test
public void query() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.Internal internal = mock(StorIOSQLite.Internal.class);
final Query query = Query.builder().table("test_table").build();
final Cursor expectedCursor = mock(Cursor.class);
when(storIOSQLite.lowLevel()).thenReturn(internal);
when(internal.query(query)).thenReturn(expectedCursor);
final DefaultGetResolver<TestItem> defaultGetResolver = new DefaultGetResolver<TestItem>() {
@NonNull
@Override
public TestItem mapFromCursor(@NonNull Cursor cursor) {
return mock(TestItem.class);
}
};
final Cursor actualCursor = defaultGetResolver.performGet(storIOSQLite, query);
// only one request should occur
verify(internal, times(1)).query(any(Query.class));
// and this request should be equals to original
verify(internal, times(1)).query(query);
assertThat(actualCursor).isSameAs(expectedCursor);
}
use of com.pushtorefresh.storio.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class PreparedGetNumberOfResultsTest method shouldWrapExceptionIntoStorIOExceptionForSingle.
@Test
public void shouldWrapExceptionIntoStorIOExceptionForSingle() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
//noinspection unchecked
final GetResolver<Integer> getResolver = mock(GetResolver.class);
when(getResolver.performGet(eq(storIOSQLite), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
final TestSubscriber<Integer> testSubscriber = new TestSubscriber<Integer>();
new PreparedGetNumberOfResults.Builder(storIOSQLite).withQuery(Query.builder().table("test_table").build()).withGetResolver(getResolver).prepare().asRxSingle().subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent(60, SECONDS);
testSubscriber.assertError(StorIOException.class);
assertThat(testSubscriber.getOnErrorEvents()).hasSize(1);
StorIOException storIOException = (StorIOException) testSubscriber.getOnErrorEvents().get(0);
IllegalStateException cause = (IllegalStateException) storIOException.getCause();
assertThat(cause).hasMessage("test exception");
}
use of com.pushtorefresh.storio.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method observeChangesAndNotifyAboutChangesShouldWorkCorrectly.
@Test
public void observeChangesAndNotifyAboutChangesShouldWorkCorrectly() {
SQLiteOpenHelper sqLiteOpenHelper = mock(SQLiteOpenHelper.class);
StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).build();
TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
storIOSQLite.observeChanges().subscribe(testSubscriber);
testSubscriber.assertNoValues();
Changes changes = Changes.newInstance("test_table");
storIOSQLite.lowLevel().notifyAboutChanges(changes);
testSubscriber.assertValue(changes);
testSubscriber.assertNoErrors();
testSubscriber.unsubscribe();
}
use of com.pushtorefresh.storio.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method defaultSchedulerReturnsNullIfSpecifiedSchedulerNull.
@Test
public void defaultSchedulerReturnsNullIfSpecifiedSchedulerNull() {
StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(mock(SQLiteOpenHelper.class)).defaultScheduler(null).build();
assertThat(storIOSQLite.defaultScheduler()).isNull();
}
use of com.pushtorefresh.storio.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method observeChangesInTablesShouldNotAcceptNullAsTables.
@Test
public void observeChangesInTablesShouldNotAcceptNullAsTables() {
StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(mock(SQLiteOpenHelper.class)).build();
try {
//noinspection ConstantConditions
storIOSQLite.observeChangesInTables(null);
failBecauseExceptionWasNotThrown(NullPointerException.class);
} catch (NullPointerException expected) {
assertThat(expected).hasMessage("Set of tables can not be null");
}
}
Aggregations