### Question:
PreparedDeleteByQuery extends PreparedDelete<DeleteResult, DeleteQuery> { @NonNull @CheckResult @Override public Single<DeleteResult> asRxSingle() { return RxJavaUtils.createSingle(storIOSQLite, this); } PreparedDeleteByQuery(@NonNull StorIOSQLite storIOSQLite, @NonNull DeleteQuery deleteQuery, @NonNull DeleteResolver<DeleteQuery> deleteResolver); @NonNull @Override Flowable<DeleteResult> asRxFlowable(@NonNull BackpressureStrategy backpressureStrategy); @NonNull @CheckResult @Override Single<DeleteResult> asRxSingle(); @NonNull @CheckResult @Override Completable asRxCompletable(); @NonNull @Override DeleteQuery getData();  }### Answer:
@Test public void shouldPerformDeletionByQuerySingle() { final DeleteByQueryStub stub = new DeleteByQueryStub(); final TestObserver<DeleteResult> testObserver = new TestObserver<DeleteResult>(); new PreparedDeleteByQuery.Builder(stub.storIOSQLite, stub.deleteQuery) .withDeleteResolver(stub.deleteResolver) .prepare() .asRxSingle() .subscribe(testObserver); testObserver.awaitTerminalEvent(); testObserver.assertNoErrors(); testObserver.assertValue(stub.expectedDeleteResult); verify(stub.storIOSQLite).defaultRxScheduler(); stub.verifyBehaviour(); }
@Test public void shouldWrapExceptionIntoStorIOExceptionSingle() { final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class); final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class); when(storIOSQLite.lowLevel()).thenReturn(lowLevel); 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); 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); }