use of com.pushtorefresh.storio3.StorIOException in project storio by pushtorefresh.
the class PreparedGetNumberOfResultsTest method shouldWrapExceptionIntoStorIOExceptionForBlocking.
@Test
public void shouldWrapExceptionIntoStorIOExceptionForBlocking() {
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"));
try {
new PreparedGetNumberOfResults.Builder(storIOSQLite).withQuery(Query.builder().table("test_table").build()).withGetResolver(getResolver).prepare().executeAsBlocking();
failBecauseExceptionWasNotThrown(StorIOException.class);
} catch (StorIOException expected) {
IllegalStateException cause = (IllegalStateException) expected.getCause();
assertThat(cause).hasMessage("test exception");
}
}
use of com.pushtorefresh.storio3.StorIOException in project storio by pushtorefresh.
the class PreparedPutContentValuesIterableTest method shouldFinishTransactionIfExceptionHasOccurredCompletable.
@Test
public void shouldFinishTransactionIfExceptionHasOccurredCompletable() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
// 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(true).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(lowLevel).beginTransaction();
verify(lowLevel, never()).setTransactionSuccessful();
verify(lowLevel).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.StorIOException in project storio by pushtorefresh.
the class PreparedPutContentValuesIterableTest method shouldFinishTransactionIfExceptionHasOccurredSingle.
@Test
public void shouldFinishTransactionIfExceptionHasOccurredSingle() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
// 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(true).prepare().asRxSingle().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(lowLevel).beginTransaction();
verify(lowLevel, never()).setTransactionSuccessful();
verify(lowLevel).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.StorIOException in project storio by pushtorefresh.
the class PreparedPutContentValuesIterableTest method shouldWrapExceptionIntoStorIOExceptionFlowable.
@Test
public void shouldWrapExceptionIntoStorIOExceptionFlowable() {
final PutContentValuesStub stub = PutContentValuesStub.newPutStubForMultipleContentValues(true);
IllegalStateException testException = new IllegalStateException("test exception");
doThrow(testException).when(stub.putResolver).performPut(eq(stub.storIOSQLite), any(ContentValues.class));
final TestSubscriber<Object> testSubscriber = new TestSubscriber<Object>();
stub.storIOSQLite.put().contentValues(stub.contentValues).withPutResolver(stub.putResolver).prepare().asRxFlowable(MISSING).subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
testSubscriber.assertNoValues();
testSubscriber.assertError(StorIOException.class);
// noinspection ThrowableResultOfMethodCallIgnored
StorIOException expected = (StorIOException) testSubscriber.errors().get(0);
assertThat(expected).hasMessageStartingWith("Error has occurred during Put operation. contentValues =");
IllegalStateException cause = (IllegalStateException) expected.getCause();
assertThat(cause).hasMessage("test exception");
verify(stub.storIOSQLite).put();
verify(stub.storIOSQLite).lowLevel();
verify(stub.lowLevel).beginTransaction();
verify(stub.lowLevel).endTransaction();
verify(stub.storIOSQLite).defaultRxScheduler();
verify(stub.storIOSQLite).interceptors();
verifyNoMoreInteractions(stub.storIOSQLite, stub.lowLevel);
}
use of com.pushtorefresh.storio3.StorIOException 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);
}
}
Aggregations