Search in sources :

Example 21 with DeleteResult

use of com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult 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 22 with DeleteResult

use of com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult in project storio by pushtorefresh.

the class AutoParcelTest method deleteObject.

@Test
public void deleteObject() {
    final Book book = Book.builder().id(1).title("What a great book").author("Somebody").build();
    final PutResult putResult = storIOSQLite.put().object(book).prepare().executeAsBlocking();
    assertThat(putResult.wasInserted()).isTrue();
    final DeleteResult deleteResult = storIOSQLite.delete().object(book).prepare().executeAsBlocking();
    assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(1);
    final List<Book> storedBooks = storIOSQLite.get().listOfObjects(Book.class).withQuery(Query.builder().table(BookTableMeta.TABLE).build()).prepare().executeAsBlocking();
    assertThat(storedBooks).hasSize(0);
}
Also used : PutResult(com.pushtorefresh.storio3.sqlite.operations.put.PutResult) DeleteResult(com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult) Test(org.junit.Test)

Example 23 with DeleteResult

use of com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult in project storio by pushtorefresh.

the class PersonRelationsDeleteResolver method performDelete.

@Override
@NonNull
public DeleteResult performDelete(@NonNull StorIOSQLite storIOSQLite, @NonNull Person object) {
    final StorIOSQLite.LowLevel lowLevel = storIOSQLite.lowLevel();
    lowLevel.beginTransaction();
    try {
        final DeleteResult deleteResult = super.performDelete(storIOSQLite, object);
        storIOSQLite.delete().byQuery(DeleteQuery.builder().table(PersonCarRelationTable.TABLE).where(COLUMN_PERSON_ID + " = ?").whereArgs(object.id()).build()).prepare().executeAsBlocking();
        lowLevel.setTransactionSuccessful();
        return deleteResult;
    } finally {
        lowLevel.endTransaction();
    }
}
Also used : StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) DeleteResult(com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult) NonNull(android.support.annotation.NonNull)

Aggregations

Test (org.junit.Test)18 DeleteResult (com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult)10 NonNull (android.support.annotation.NonNull)7 StorIOSQLite (com.pushtorefresh.storio3.sqlite.StorIOSQLite)7 TestSubscriber (io.reactivex.subscribers.TestSubscriber)7 Cursor (android.database.Cursor)6 Changes (com.pushtorefresh.storio3.contentresolver.Changes)6 DeleteQuery (com.pushtorefresh.storio3.sqlite.queries.DeleteQuery)6 DeleteQuery (com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery)5 DeleteResult (com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult)5 StorIOException (com.pushtorefresh.storio3.StorIOException)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 PutResult (com.pushtorefresh.storio3.sqlite.operations.put.PutResult)1