use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class PreparedPutContentValuesIterableTest method verifyBehaviorInCaseOfExceptionWithoutTransactionBlocking.
@Test
public void verifyBehaviorInCaseOfExceptionWithoutTransactionBlocking() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
// noinspection unchecked
final PutResolver<ContentValues> putResolver = mock(PutResolver.class);
final List<ContentValues> contentValues = singletonList(mock(ContentValues.class));
when(putResolver.performPut(same(storIOSQLite), any(ContentValues.class))).thenThrow(new IllegalStateException("test exception"));
try {
new PreparedPutContentValuesIterable.Builder(storIOSQLite, contentValues).withPutResolver(putResolver).useTransaction(false).prepare().executeAsBlocking();
failBecauseExceptionWasNotThrown(StorIOException.class);
} catch (StorIOException expected) {
IllegalStateException cause = (IllegalStateException) expected.getCause();
assertThat(cause).hasMessage("test exception");
// Main check of this test
verify(lowLevel, never()).endTransaction();
verify(storIOSQLite).lowLevel();
verify(storIOSQLite).interceptors();
verify(putResolver).performPut(same(storIOSQLite), any(ContentValues.class));
verifyNoMoreInteractions(storIOSQLite, lowLevel, putResolver);
}
}
use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class PreparedPutContentValuesIterableTest method verifyBehaviorInCaseOfExceptionWithoutTransactionCompletable.
@Test
public void verifyBehaviorInCaseOfExceptionWithoutTransactionCompletable() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
// noinspection unchecked
final PutResolver<ContentValues> putResolver = mock(PutResolver.class);
final List<ContentValues> contentValues = singletonList(mock(ContentValues.class));
when(putResolver.performPut(same(storIOSQLite), any(ContentValues.class))).thenThrow(new IllegalStateException("test exception"));
final TestObserver<PutResults<ContentValues>> testObserver = new TestObserver<PutResults<ContentValues>>();
new PreparedPutContentValuesIterable.Builder(storIOSQLite, contentValues).withPutResolver(putResolver).useTransaction(false).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");
// Main check of this test
verify(lowLevel, never()).endTransaction();
verify(storIOSQLite).lowLevel();
verify(storIOSQLite).defaultRxScheduler();
verify(storIOSQLite).interceptors();
verify(putResolver).performPut(same(storIOSQLite), any(ContentValues.class));
verifyNoMoreInteractions(storIOSQLite, lowLevel, putResolver);
}
use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class PreparedPutContentValuesIterableTest method verifyBehaviorInCaseOfExceptionWithoutTransactionFlowable.
@Test
public void verifyBehaviorInCaseOfExceptionWithoutTransactionFlowable() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
// noinspection unchecked
final PutResolver<ContentValues> putResolver = mock(PutResolver.class);
final List<ContentValues> contentValues = singletonList(mock(ContentValues.class));
when(putResolver.performPut(same(storIOSQLite), any(ContentValues.class))).thenThrow(new IllegalStateException("test exception"));
final TestSubscriber<PutResults<ContentValues>> testSubscriber = new TestSubscriber<PutResults<ContentValues>>();
new PreparedPutContentValuesIterable.Builder(storIOSQLite, contentValues).withPutResolver(putResolver).useTransaction(false).prepare().asRxFlowable(MISSING).subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
testSubscriber.assertNoValues();
testSubscriber.assertError(StorIOException.class);
// noinspection ThrowableResultOfMethodCallIgnored
StorIOException expected = (StorIOException) testSubscriber.errors().get(0);
IllegalStateException cause = (IllegalStateException) expected.getCause();
assertThat(cause).hasMessage("test exception");
// Main check of this test
verify(lowLevel, never()).endTransaction();
verify(storIOSQLite).lowLevel();
verify(storIOSQLite).defaultRxScheduler();
verify(storIOSQLite).interceptors();
verify(putResolver).performPut(same(storIOSQLite), any(ContentValues.class));
verifyNoMoreInteractions(storIOSQLite, lowLevel, putResolver);
}
use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class DefaultGetResolverTest method query.
@Test
public void query() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
final Query query = Query.builder().table("test_table").build();
final Cursor expectedCursor = mock(Cursor.class);
when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
when(lowLevel.query(query)).thenReturn(expectedCursor);
final DefaultGetResolver<TestItem> defaultGetResolver = new DefaultGetResolver<TestItem>() {
@NonNull
@Override
public TestItem mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) {
return mock(TestItem.class);
}
};
final Cursor actualCursor = defaultGetResolver.performGet(storIOSQLite, query);
// only one request should occur
verify(lowLevel, times(1)).query(any(Query.class));
// and this request should be equals to original
verify(lowLevel, times(1)).query(query);
assertThat(actualCursor).isSameAs(expectedCursor);
}
use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class DefaultGetResolverTest method rawQuery.
@Test
public void rawQuery() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
final RawQuery rawQuery = RawQuery.builder().query("test sql").build();
final Cursor expectedCursor = mock(Cursor.class);
when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
when(lowLevel.rawQuery(rawQuery)).thenReturn(expectedCursor);
final DefaultGetResolver<TestItem> defaultGetResolver = new DefaultGetResolver<TestItem>() {
@NonNull
@Override
public TestItem mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) {
return mock(TestItem.class);
}
};
final Cursor actualCursor = defaultGetResolver.performGet(storIOSQLite, rawQuery);
// only one request should occur
verify(lowLevel, times(1)).rawQuery(any(RawQuery.class));
// and this request should be equals to original
verify(lowLevel, times(1)).rawQuery(rawQuery);
assertThat(actualCursor).isSameAs(expectedCursor);
}
Aggregations