Search in sources :

Example 6 with DeleteQuery

use of com.pushtorefresh.storio.sqlite.queries.DeleteQuery 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 7 with DeleteQuery

use of com.pushtorefresh.storio.sqlite.queries.DeleteQuery in project storio by pushtorefresh.

the class PreparedDeleteByQueryTest method shouldWrapExceptionIntoStorIOExceptionCompletable.

@Test
public void shouldWrapExceptionIntoStorIOExceptionCompletable() {
    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().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(storIOSQLite).defaultScheduler();
    verify(deleteResolver).performDelete(same(storIOSQLite), any(DeleteQuery.class));
    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)

Aggregations

DeleteQuery (com.pushtorefresh.storio.sqlite.queries.DeleteQuery)7 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)6 Test (org.junit.Test)6 StorIOException (com.pushtorefresh.storio.StorIOException)4 TestSubscriber (rx.observers.TestSubscriber)3 NonNull (android.support.annotation.NonNull)2 Changes (com.pushtorefresh.storio.sqlite.Changes)1