use of com.pushtorefresh.storio.StorIOException in project storio by pushtorefresh.
the class PreparedGetCursorTest method shouldWrapExceptionIntoStorIOExceptionForSingle.
@Test
public void shouldWrapExceptionIntoStorIOExceptionForSingle() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
//noinspection unchecked
final GetResolver<Cursor> getResolver = mock(GetResolver.class);
when(getResolver.performGet(eq(storIOSQLite), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
final TestSubscriber<Cursor> testSubscriber = new TestSubscriber<Cursor>();
new PreparedGetCursor.Builder(storIOSQLite).withQuery(Query.builder().table("test_table").build()).withGetResolver(getResolver).prepare().asRxSingle().subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent(60, SECONDS);
testSubscriber.assertError(StorIOException.class);
StorIOException storIOException = (StorIOException) testSubscriber.getOnErrorEvents().get(0);
IllegalStateException cause = (IllegalStateException) storIOException.getCause();
assertThat(cause).hasMessage("test exception");
}
use of com.pushtorefresh.storio.StorIOException in project storio by pushtorefresh.
the class PreparedGetCursorTest method shouldWrapExceptionIntoStorIOExceptionForBlocking.
@Test
public void shouldWrapExceptionIntoStorIOExceptionForBlocking() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
//noinspection unchecked
final GetResolver<Cursor> getResolver = mock(GetResolver.class);
when(getResolver.performGet(eq(storIOSQLite), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
try {
new PreparedGetCursor.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.storio.StorIOException in project storio by pushtorefresh.
the class PreparedPutContentValuesIterableTest method shouldFinishTransactionIfExceptionHasOccurredObservable.
@Test
public void shouldFinishTransactionIfExceptionHasOccurredObservable() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.Internal internal = mock(StorIOSQLite.Internal.class);
when(storIOSQLite.lowLevel()).thenReturn(internal);
//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(true).prepare().asRxObservable().subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
testSubscriber.assertNoValues();
testSubscriber.assertError(StorIOException.class);
//noinspection ThrowableResultOfMethodCallIgnored
StorIOException expected = (StorIOException) testSubscriber.getOnErrorEvents().get(0);
IllegalStateException cause = (IllegalStateException) expected.getCause();
assertThat(cause).hasMessage("test exception");
verify(internal).beginTransaction();
verify(internal, never()).setTransactionSuccessful();
verify(internal).endTransaction();
verify(storIOSQLite).lowLevel();
verify(storIOSQLite).defaultScheduler();
verify(putResolver).performPut(same(storIOSQLite), any(ContentValues.class));
verifyNoMoreInteractions(storIOSQLite, internal, putResolver);
}
use of com.pushtorefresh.storio.StorIOException in project storio by pushtorefresh.
the class PreparedDeleteObject method executeAsBlocking.
/**
* Executes Delete Operation immediately in current thread.
* <p>
* Notice: This is blocking I/O operation that should not be executed on the Main Thread,
* it can cause ANR (Activity Not Responding dialog), block the UI and drop animations frames.
* So please, call this method on some background thread. See {@link WorkerThread}.
*
* @return non-null result of Delete Operation.
*/
@SuppressWarnings("unchecked")
@WorkerThread
@NonNull
@Override
public DeleteResult executeAsBlocking() {
try {
final DeleteResolver<T> deleteResolver;
if (explicitDeleteResolver != null) {
deleteResolver = explicitDeleteResolver;
} else {
final ContentResolverTypeMapping<T> typeMapping = storIOContentResolver.lowLevel().typeMapping((Class<T>) object.getClass());
if (typeMapping == null) {
throw new IllegalStateException("Object does not have type mapping: " + "object = " + object + ", object.class = " + object.getClass() + ", " + "ContentProvider was not affected by this operation, please add type mapping for this type");
}
deleteResolver = typeMapping.deleteResolver();
}
return deleteResolver.performDelete(storIOContentResolver, object);
} catch (Exception exception) {
throw new StorIOException("Error has occurred during Delete operation. object = " + object, exception);
}
}
use of com.pushtorefresh.storio.StorIOException in project storio by pushtorefresh.
the class PreparedPutObject method executeAsBlocking.
/**
* Executes Put Operation immediately in current thread.
* <p>
* Notice: This is blocking I/O operation that should not be executed on the Main Thread,
* it can cause ANR (Activity Not Responding dialog), block the UI and drop animations frames.
* So please, call this method on some background thread. See {@link WorkerThread}.
*
* @return non-null results of Put Operation.
*/
@SuppressWarnings("unchecked")
@WorkerThread
@NonNull
@Override
public PutResult executeAsBlocking() {
try {
final PutResolver<T> putResolver;
if (explicitPutResolver != null) {
putResolver = explicitPutResolver;
} else {
final ContentResolverTypeMapping<T> typeMapping = storIOContentResolver.lowLevel().typeMapping((Class<T>) object.getClass());
if (typeMapping == null) {
throw new IllegalStateException("Object does not have type mapping: " + "object = " + object + ", object.class = " + object.getClass() + ", " + "ContentProvider was not affected by this operation, please add type mapping for this type");
}
putResolver = typeMapping.putResolver();
}
return putResolver.performPut(storIOContentResolver, object);
} catch (Exception exception) {
throw new StorIOException("Error has occurred during Put operation. object = " + object, exception);
}
}
Aggregations