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);
}
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);
}
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();
}
}
Aggregations