### Question:
PreparedGetCursor extends PreparedGetMandatoryResult<Cursor> { @NonNull @CheckResult @Override public Flowable<Cursor> asRxFlowable(@NonNull BackpressureStrategy backpressureStrategy) { return RxJavaUtils.createGetFlowable(storIOSQLite, this, query, rawQuery, backpressureStrategy); } 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 shouldGetCursorWithRawQueryAsFlowable() { final GetCursorStub getStub = GetCursorStub.newInstance(); final Flowable<Cursor> cursorFlowable = getStub.storIOSQLite .get() .cursor() .withQuery(getStub.rawQuery) .withGetResolver(getStub.getResolverForCursor) .prepare() .asRxFlowable(LATEST) .take(1); verify(getStub.storIOSQLite).defaultRxScheduler(); getStub.verifyRawQueryBehaviorForCursor(cursorFlowable); }
@Test public void shouldWrapExceptionIntoStorIOExceptionForFlowable() { final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class); when(storIOSQLite.observeChanges(any(BackpressureStrategy.class))).thenReturn(Flowable.<Changes>empty()); final GetResolver<Cursor> getResolver = mock(GetResolver.class); when(getResolver.performGet(eq(storIOSQLite), any(Query.class))) .thenThrow(new IllegalStateException("test exception")); final TestSubscriber<Cursor> testSubscriber = new TestSubscriber<Cursor>(); new PreparedGetCursor.Builder(storIOSQLite) .withQuery(Query.builder().table("test_table").observesTags("test_tag").build()) .withGetResolver(getResolver) .prepare() .asRxFlowable(LATEST) .subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(60, SECONDS); testSubscriber.assertError(StorIOException.class); StorIOException storIOException = (StorIOException) testSubscriber.errors().get(0); IllegalStateException cause = (IllegalStateException) storIOException.getCause(); assertThat(cause).hasMessage("test exception"); testSubscriber.dispose(); }
@Test public void asRxFlowableShouldThrowExceptionIfNoQueryWasSet() { PreparedGetCursor preparedGetCursor = new PreparedGetCursor(mock(StorIOSQLite.class), (Query) null, (GetResolver<Cursor>) mock(GetResolver.class)); try { preparedGetCursor.asRxFlowable(LATEST); failBecauseExceptionWasNotThrown(StorIOException.class); } catch (IllegalStateException expected) { assertThat(expected).hasMessage("Please specify query"); } }