### Question:
PreparedGetNumberOfResults extends PreparedGetMandatoryResult<Integer> { @NonNull @CheckResult @Override public Flowable<Integer> asRxFlowable(@NonNull BackpressureStrategy backpressureStrategy) { return RxJavaUtils.createGetFlowable(storIOSQLite, this, query, rawQuery, backpressureStrategy); } PreparedGetNumberOfResults(@NonNull StorIOSQLite storIOSQLite, @NonNull Query query, @NonNull GetResolver<Integer> getResolver);   PreparedGetNumberOfResults(@NonNull StorIOSQLite storIOSQLite, @NonNull RawQuery rawQuery, @NonNull GetResolver<Integer> getResolver); @NonNull @CheckResult @Override Flowable<Integer> asRxFlowable(@NonNull BackpressureStrategy backpressureStrategy); @NonNull @CheckResult @Override Single<Integer> asRxSingle();  }### Answer:
@Test public void shouldGetNumberOfResultsWithQueryAsFlowable() { final GetNumberOfResultsStub getStub = GetNumberOfResultsStub.newInstance(); final Flowable<Integer> numberOfResultsFlowable = getStub.storIOSQLite .get() .numberOfResults() .withQuery(getStub.query) .withGetResolver(getStub.getResolverForNumberOfResults) .prepare() .asRxFlowable(LATEST) .take(1); getStub.verifyQueryBehaviorForInteger(numberOfResultsFlowable); }
@Test public void shouldGetNumberOfResultsWithRawQueryAsFlowable() { final GetNumberOfResultsStub getStub = GetNumberOfResultsStub.newInstance(); final Flowable<Integer> numberOfResultsFlowable = getStub.storIOSQLite .get() .numberOfResults() .withQuery(getStub.rawQuery) .withGetResolver(getStub.getResolverForNumberOfResults) .prepare() .asRxFlowable(LATEST) .take(1); getStub.verifyRawQueryBehaviorForInteger(numberOfResultsFlowable); }
@Test public void shouldWrapExceptionIntoStorIOExceptionForFlowable() { final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class); when(storIOSQLite.observeChanges(any(BackpressureStrategy.class))).thenReturn(Flowable.<Changes>empty()); final GetResolver<Integer> getResolver = mock(GetResolver.class); when(getResolver.performGet(eq(storIOSQLite), any(Query.class))) .thenThrow(new IllegalStateException("test exception")); final TestSubscriber<Integer> testSubscriber = new TestSubscriber<Integer>(); new PreparedGetNumberOfResults.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); assertThat(testSubscriber.errorCount()).isEqualTo(1); StorIOException storIOException = (StorIOException) testSubscriber.errors().get(0); IllegalStateException cause = (IllegalStateException) storIOException.getCause(); assertThat(cause).hasMessage("test exception"); testSubscriber.dispose(); }
@Test public void asRxFlowableShouldThrowExceptionIfNoQueryWasSet() { PreparedGetNumberOfResults preparedGetNumberOfResults = new PreparedGetNumberOfResults(mock(StorIOSQLite.class), (Query) null, (GetResolver<Integer>) mock(GetResolver.class)); try { preparedGetNumberOfResults.asRxFlowable(LATEST); failBecauseExceptionWasNotThrown(StorIOException.class); } catch (IllegalStateException expected) { assertThat(expected).hasMessage("Please specify query"); } }