use of com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery in project storio by pushtorefresh.
the class PreparedDeleteByQueryTest method shouldWrapExceptionIntoStorIOExceptionSingle.
@Test
public void shouldWrapExceptionIntoStorIOExceptionSingle() {
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().asRxSingle().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(deleteResolver).performDelete(same(storIOSQLite), any(DeleteQuery.class));
verify(storIOSQLite).defaultRxScheduler();
verify(storIOSQLite).interceptors();
verifyNoMoreInteractions(storIOSQLite, lowLevel, deleteResolver);
}
use of com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery in project storio by pushtorefresh.
the class DefaultDeleteResolver method performDelete.
/**
* {@inheritDoc}
*/
@NonNull
@Override
public DeleteResult performDelete(@NonNull StorIOContentResolver storIOContentResolver, @NonNull T object) {
final DeleteQuery deleteQuery = mapToDeleteQuery(object);
final int numberOfRowsDeleted = storIOContentResolver.lowLevel().delete(deleteQuery);
return DeleteResult.newInstance(numberOfRowsDeleted, deleteQuery.uri());
}
use of com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery in project storio by pushtorefresh.
the class DefaultDeleteResolver method performDelete.
/**
* {@inheritDoc}
*/
@NonNull
@Override
public DeleteResult performDelete(@NonNull StorIOSQLite storIOSQLite, @NonNull T object) {
final DeleteQuery deleteQuery = mapToDeleteQuery(object);
final int numberOfRowsDeleted = storIOSQLite.lowLevel().delete(deleteQuery);
return DeleteResult.newInstance(numberOfRowsDeleted, deleteQuery.table(), deleteQuery.affectsTags());
}
use of com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery in project storio by pushtorefresh.
the class DeleteOperationDesignTest method deleteByQueryFlowable.
@Test
public void deleteByQueryFlowable() {
final DeleteQuery deleteQuery = DeleteQuery.builder().uri(mock(Uri.class)).where("some_field = ?").whereArgs("someValue").build();
Flowable<DeleteResult> deleteResultFlowable = storIOContentResolver().delete().byQuery(deleteQuery).prepare().asRxFlowable(BackpressureStrategy.MISSING);
}
use of com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery in project storio by pushtorefresh.
the class DefaultDeleteResolverTest method performDelete.
@Test
public void performDelete() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
final String testTable = "test_table";
final Set<String> testTags = singleton("test_tag");
final DeleteQuery deleteQuery = DeleteQuery.builder().table(testTable).affectsTags(testTags).build();
when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
when(lowLevel.delete(deleteQuery)).thenReturn(1);
final TestItem testItem = new TestItem();
final DefaultDeleteResolver<TestItem> defaultDeleteResolver = new DefaultDeleteResolver<TestItem>() {
@NonNull
@Override
public DeleteQuery mapToDeleteQuery(@NonNull TestItem testItem) {
return deleteQuery;
}
};
final DeleteResult deleteResult = defaultDeleteResolver.performDelete(storIOSQLite, testItem);
verify(lowLevel).delete(any(DeleteQuery.class));
verify(lowLevel).delete(deleteQuery);
assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(1);
assertThat(deleteResult.affectedTables()).isEqualTo(singleton(testTable));
assertThat(deleteResult.affectedTags()).isEqualTo(testTags);
}
Aggregations