use of com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery in project storio by pushtorefresh.
the class DeleteOperationDesignTest method deleteByQuerySingle.
@Test
public void deleteByQuerySingle() {
final DeleteQuery deleteQuery = DeleteQuery.builder().uri(mock(Uri.class)).where("some_field = ?").whereArgs("someValue").build();
Single<DeleteResult> deleteResultSingle = storIOContentResolver().delete().byQuery(deleteQuery).prepare().asRxSingle();
}
use of com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery in project storio by pushtorefresh.
the class DeleteOperationDesignTest method deleteByQueryCompletable.
@Test
public void deleteByQueryCompletable() {
final DeleteQuery deleteQuery = DeleteQuery.builder().uri(mock(Uri.class)).where("some_field = ?").whereArgs("someValue").build();
Completable completable = storIOContentResolver().delete().byQuery(deleteQuery).prepare().asRxCompletable();
}
use of com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery in project storio by pushtorefresh.
the class DeleteOperationDesignTest method deleteByQueryBlocking.
@Test
public void deleteByQueryBlocking() {
final DeleteQuery deleteQuery = DeleteQuery.builder().uri(mock(Uri.class)).where("some_field = ?").whereArgs("someValue").build();
DeleteResult deleteResult = storIOContentResolver().delete().byQuery(deleteQuery).prepare().executeAsBlocking();
}
use of com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery in project storio by pushtorefresh.
the class DefaultDeleteResolverTest method performDelete.
@Test
public void performDelete() {
final StorIOContentResolver storIOContentResolver = mock(StorIOContentResolver.class);
final StorIOContentResolver.LowLevel lowLevel = mock(StorIOContentResolver.LowLevel.class);
when(storIOContentResolver.lowLevel()).thenReturn(lowLevel);
final int expectedNumberOfRowsDeleted = 1;
when(lowLevel.delete(any(DeleteQuery.class))).thenReturn(expectedNumberOfRowsDeleted);
final Uri expectedUri = mock(Uri.class);
final DeleteQuery expectedDeleteQuery = DeleteQuery.builder().uri(expectedUri).where("test where clause").whereArgs("test").build();
final TestItem testItem = TestItem.newInstance();
final DefaultDeleteResolver<TestItem> defaultDeleteResolver = new DefaultDeleteResolver<TestItem>() {
@NonNull
@Override
protected DeleteQuery mapToDeleteQuery(@NonNull TestItem object) {
assertThat(object).isSameAs(testItem);
return expectedDeleteQuery;
}
};
// Performing Delete Operation
final DeleteResult deleteResult = defaultDeleteResolver.performDelete(storIOContentResolver, testItem);
// checks that required delete was performed
verify(lowLevel, times(1)).delete(expectedDeleteQuery);
// only one delete should be performed
verify(lowLevel, times(1)).delete(any(DeleteQuery.class));
// delete result checks
assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(expectedNumberOfRowsDeleted);
assertThat(deleteResult.affectedUris()).hasSize(1);
assertThat(deleteResult.affectedUris()).contains(expectedUri);
}
use of com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery in project storio by pushtorefresh.
the class PreparedDeleteByQueryTest method shouldWrapExceptionIntoStorIOExceptionFlowable.
@Test
public void shouldWrapExceptionIntoStorIOExceptionFlowable() {
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 TestSubscriber<DeleteResult> testSubscriber = new TestSubscriber<DeleteResult>();
new PreparedDeleteByQuery.Builder(storIOSQLite, DeleteQuery.builder().table("test_table").build()).withDeleteResolver(deleteResolver).prepare().asRxFlowable(MISSING).subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
testSubscriber.assertNoValues();
testSubscriber.assertError(StorIOException.class);
// noinspection ThrowableResultOfMethodCallIgnored
StorIOException expected = (StorIOException) testSubscriber.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);
}
Aggregations