Search in sources :

Example 11 with DeleteQuery

use of com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery in project storio by pushtorefresh.

the class PreparedDeleteByQueryTest method shouldWrapExceptionIntoStorIOExceptionCompletable.

@Test
public void shouldWrapExceptionIntoStorIOExceptionCompletable() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
    when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
    // noinspection unchecked
    final DeleteResolver<DeleteQuery> deleteResolver = mock(DeleteResolver.class);
    when(deleteResolver.performDelete(same(storIOSQLite), any(DeleteQuery.class))).thenThrow(new IllegalStateException("test exception"));
    final TestObserver<DeleteResult> testObserver = new TestObserver<DeleteResult>();
    new PreparedDeleteByQuery.Builder(storIOSQLite, DeleteQuery.builder().table("test_table").build()).withDeleteResolver(deleteResolver).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(storIOSQLite).defaultRxScheduler();
    verify(deleteResolver).performDelete(same(storIOSQLite), any(DeleteQuery.class));
    verify(storIOSQLite).interceptors();
    verifyNoMoreInteractions(storIOSQLite, lowLevel, deleteResolver);
}
Also used : StorIOException(com.pushtorefresh.storio3.StorIOException) DeleteQuery(com.pushtorefresh.storio3.sqlite.queries.DeleteQuery) StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 12 with DeleteQuery

use of com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery in project storio by pushtorefresh.

the class PreparedDeleteByQueryTest method shouldNotNotifyIfWasNotDeleted.

@Test
public void shouldNotNotifyIfWasNotDeleted() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
    when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
    final DeleteQuery deleteQuery = DeleteQuery.builder().table("test_table").where("column1 = ?").whereArgs(1).build();
    // noinspection unchecked
    final DeleteResolver<DeleteQuery> deleteResolver = mock(DeleteResolver.class);
    // No items were deleted
    final DeleteResult expectedDeleteResult = DeleteResult.newInstance(0, deleteQuery.table());
    when(deleteResolver.performDelete(same(storIOSQLite), same(deleteQuery))).thenReturn(expectedDeleteResult);
    final DeleteResult actualDeleteResult = new PreparedDeleteByQuery.Builder(storIOSQLite, deleteQuery).withDeleteResolver(deleteResolver).prepare().executeAsBlocking();
    assertThat(actualDeleteResult).isEqualTo(expectedDeleteResult);
    verify(deleteResolver).performDelete(same(storIOSQLite), same(deleteQuery));
    verify(lowLevel, never()).notifyAboutChanges(any(Changes.class));
    verify(storIOSQLite).interceptors();
    verifyNoMoreInteractions(storIOSQLite, lowLevel, deleteResolver);
}
Also used : Changes(com.pushtorefresh.storio3.sqlite.Changes) DeleteQuery(com.pushtorefresh.storio3.sqlite.queries.DeleteQuery) StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 13 with DeleteQuery

use of com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery in project storio by pushtorefresh.

the class PreparedDeleteByQueryTest method shouldWrapExceptionIntoStorIOExceptionBlocking.

@Test
public void shouldWrapExceptionIntoStorIOExceptionBlocking() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
    when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
    // 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));
        verify(storIOSQLite).interceptors();
        verifyNoMoreInteractions(storIOSQLite, lowLevel, deleteResolver);
    }
}
Also used : StorIOException(com.pushtorefresh.storio3.StorIOException) DeleteQuery(com.pushtorefresh.storio3.sqlite.queries.DeleteQuery) StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 DeleteQuery (com.pushtorefresh.storio3.sqlite.queries.DeleteQuery)7 DeleteQuery (com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery)6 StorIOSQLite (com.pushtorefresh.storio3.sqlite.StorIOSQLite)6 NonNull (android.support.annotation.NonNull)4 StorIOException (com.pushtorefresh.storio3.StorIOException)4 DeleteResult (com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult)3 TestObserver (io.reactivex.observers.TestObserver)2 Uri (android.net.Uri)1 StorIOContentResolver (com.pushtorefresh.storio3.contentresolver.StorIOContentResolver)1 Changes (com.pushtorefresh.storio3.sqlite.Changes)1 Completable (io.reactivex.Completable)1 TestSubscriber (io.reactivex.subscribers.TestSubscriber)1