Search in sources :

Example 16 with StorIOException

use of com.pushtorefresh.storio.StorIOException in project storio by pushtorefresh.

the class PreparedPutContentValuesIterableTest method shouldFinishTransactionIfExceptionHasOccurredCompletable.

@Test
public void shouldFinishTransactionIfExceptionHasOccurredCompletable() {
    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().asRxCompletable().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);
}
Also used : ContentValues(android.content.ContentValues) StorIOException(com.pushtorefresh.storio.StorIOException) TestSubscriber(rx.observers.TestSubscriber) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 17 with StorIOException

use of com.pushtorefresh.storio.StorIOException in project storio by pushtorefresh.

the class PreparedDeleteByQueryTest method shouldWrapExceptionIntoStorIOExceptionBlocking.

@Test
public void shouldWrapExceptionIntoStorIOExceptionBlocking() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    final StorIOSQLite.Internal internal = mock(StorIOSQLite.Internal.class);
    when(storIOSQLite.lowLevel()).thenReturn(internal);
    //noinspection unchecked
    final DeleteResolver<DeleteQuery> deleteResolver = mock(DeleteResolver.class);
    when(deleteResolver.performDelete(same(storIOSQLite), any(DeleteQuery.class))).thenThrow(new IllegalStateException("test exception"));
    try {
        new PreparedDeleteByQuery.Builder(storIOSQLite, DeleteQuery.builder().table("test_table").build()).withDeleteResolver(deleteResolver).prepare().executeAsBlocking();
        failBecauseExceptionWasNotThrown(StorIOException.class);
    } catch (StorIOException expected) {
        IllegalStateException cause = (IllegalStateException) expected.getCause();
        assertThat(cause).hasMessage("test exception");
        verify(deleteResolver).performDelete(same(storIOSQLite), any(DeleteQuery.class));
        verifyNoMoreInteractions(storIOSQLite, internal, deleteResolver);
    }
}
Also used : StorIOException(com.pushtorefresh.storio.StorIOException) DeleteQuery(com.pushtorefresh.storio.sqlite.queries.DeleteQuery) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 18 with StorIOException

use of com.pushtorefresh.storio.StorIOException in project storio by pushtorefresh.

the class PreparedDeleteByQueryTest method shouldWrapExceptionIntoStorIOExceptionObservable.

@Test
public void shouldWrapExceptionIntoStorIOExceptionObservable() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    final StorIOSQLite.Internal internal = mock(StorIOSQLite.Internal.class);
    when(storIOSQLite.lowLevel()).thenReturn(internal);
    //noinspection unchecked
    final DeleteResolver<DeleteQuery> deleteResolver = mock(DeleteResolver.class);
    when(deleteResolver.performDelete(same(storIOSQLite), any(DeleteQuery.class))).thenThrow(new IllegalStateException("test exception"));
    final TestSubscriber<DeleteResult> testSubscriber = new TestSubscriber<DeleteResult>();
    new PreparedDeleteByQuery.Builder(storIOSQLite, DeleteQuery.builder().table("test_table").build()).withDeleteResolver(deleteResolver).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(deleteResolver).performDelete(same(storIOSQLite), any(DeleteQuery.class));
    verify(storIOSQLite).defaultScheduler();
    verifyNoMoreInteractions(storIOSQLite, internal, deleteResolver);
}
Also used : StorIOException(com.pushtorefresh.storio.StorIOException) TestSubscriber(rx.observers.TestSubscriber) DeleteQuery(com.pushtorefresh.storio.sqlite.queries.DeleteQuery) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 19 with StorIOException

use of com.pushtorefresh.storio.StorIOException in project storio by pushtorefresh.

the class PreparedDeleteByQueryTest method shouldWrapExceptionIntoStorIOExceptionSingle.

@Test
public void shouldWrapExceptionIntoStorIOExceptionSingle() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    final StorIOSQLite.Internal internal = mock(StorIOSQLite.Internal.class);
    when(storIOSQLite.lowLevel()).thenReturn(internal);
    //noinspection unchecked
    final DeleteResolver<DeleteQuery> deleteResolver = mock(DeleteResolver.class);
    when(deleteResolver.performDelete(same(storIOSQLite), any(DeleteQuery.class))).thenThrow(new IllegalStateException("test exception"));
    final TestSubscriber<DeleteResult> testSubscriber = new TestSubscriber<DeleteResult>();
    new PreparedDeleteByQuery.Builder(storIOSQLite, DeleteQuery.builder().table("test_table").build()).withDeleteResolver(deleteResolver).prepare().asRxSingle().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(deleteResolver).performDelete(same(storIOSQLite), any(DeleteQuery.class));
    verify(storIOSQLite).defaultScheduler();
    verifyNoMoreInteractions(storIOSQLite, internal, deleteResolver);
}
Also used : StorIOException(com.pushtorefresh.storio.StorIOException) TestSubscriber(rx.observers.TestSubscriber) DeleteQuery(com.pushtorefresh.storio.sqlite.queries.DeleteQuery) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 20 with StorIOException

use of com.pushtorefresh.storio.StorIOException in project storio by pushtorefresh.

the class PreparedGetCursorTest method shouldWrapExceptionIntoStorIOExceptionForObservable.

@Test
public void shouldWrapExceptionIntoStorIOExceptionForObservable() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    when(storIOSQLite.observeChangesInTables(eq(singleton("test_table")))).thenReturn(Observable.<Changes>empty());
    //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().asRxObservable().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");
    testSubscriber.unsubscribe();
}
Also used : Query(com.pushtorefresh.storio.sqlite.queries.Query) StorIOException(com.pushtorefresh.storio.StorIOException) TestSubscriber(rx.observers.TestSubscriber) Cursor(android.database.Cursor) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Aggregations

StorIOException (com.pushtorefresh.storio.StorIOException)40 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)24 Test (org.junit.Test)23 TestSubscriber (rx.observers.TestSubscriber)17 NonNull (android.support.annotation.NonNull)15 WorkerThread (android.support.annotation.WorkerThread)15 ContentValues (android.content.ContentValues)10 Cursor (android.database.Cursor)8 Query (com.pushtorefresh.storio.sqlite.queries.Query)6 HashMap (java.util.HashMap)6 StorIOContentResolver (com.pushtorefresh.storio.contentresolver.StorIOContentResolver)5 DeleteQuery (com.pushtorefresh.storio.sqlite.queries.DeleteQuery)4 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)4 Query (com.pushtorefresh.storio.contentresolver.queries.Query)3 HashSet (java.util.HashSet)3 Uri (android.net.Uri)2 CheckResult (android.support.annotation.CheckResult)2 Nullable (android.support.annotation.Nullable)2 ContentResolverTypeMapping (com.pushtorefresh.storio.contentresolver.ContentResolverTypeMapping)2 SQLiteTypeMapping (com.pushtorefresh.storio.sqlite.SQLiteTypeMapping)2