### Question:
PreparedGetCursor extends PreparedGetMandatoryResult<Cursor> { @NonNull @CheckResult @Override public Single<Cursor> asRxSingle() { return RxJavaUtils.createSingle(storIOSQLite, this); } PreparedGetCursor(@NonNull StorIOSQLite storIOSQLite,
                      @NonNull Query query,
                      @NonNull GetResolver<Cursor> getResolver);   PreparedGetCursor(@NonNull StorIOSQLite storIOSQLite,
                      @NonNull RawQuery rawQuery,
                      @NonNull GetResolver<Cursor> getResolver); @NonNull @CheckResult @Override Flowable<Cursor> asRxFlowable(@NonNull BackpressureStrategy backpressureStrategy); @NonNull @CheckResult @Override Single<Cursor> asRxSingle();  }### Answer:
@Test public void shouldGetCursorWithQueryAsSingle() { final GetCursorStub getStub = GetCursorStub.newInstance(); final Single<Cursor> cursorSingle = getStub.storIOSQLite .get() .cursor() .withQuery(getStub.query) .withGetResolver(getStub.getResolverForCursor) .prepare() .asRxSingle(); verify(getStub.storIOSQLite).defaultRxScheduler(); getStub.verifyQueryBehaviorForCursor(cursorSingle); }
@Test public void shouldGetCursorWithRawQueryAsSingle() { final GetCursorStub getStub = GetCursorStub.newInstance(); final Single<Cursor> cursorSingle = getStub.storIOSQLite .get() .cursor() .withQuery(getStub.rawQuery) .withGetResolver(getStub.getResolverForCursor) .prepare() .asRxSingle(); verify(getStub.storIOSQLite).defaultRxScheduler(); getStub.verifyRawQueryBehaviorForCursor(cursorSingle); }
@Test public void shouldWrapExceptionIntoStorIOExceptionForSingle() { final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class); final GetResolver<Cursor> getResolver = mock(GetResolver.class); when(getResolver.performGet(eq(storIOSQLite), any(Query.class))) .thenThrow(new IllegalStateException("test exception")); final TestObserver<Cursor> testObserver = new TestObserver<Cursor>(); new PreparedGetCursor.Builder(storIOSQLite) .withQuery(Query.builder().table("test_table").build()) .withGetResolver(getResolver) .prepare() .asRxSingle() .subscribe(testObserver); testObserver.awaitTerminalEvent(60, SECONDS); testObserver.assertError(StorIOException.class); StorIOException storIOException = (StorIOException) testObserver.errors().get(0); IllegalStateException cause = (IllegalStateException) storIOException.getCause(); assertThat(cause).hasMessage("test exception"); }