### Question:
PreparedGetNumberOfResults extends PreparedGetMandatoryResult<Integer> { @NonNull @CheckResult @Override public Flowable<Integer> asRxFlowable(@NonNull BackpressureStrategy backpressureStrategy) { return RxJavaUtils.createGetFlowable(storIOContentResolver, this, query, backpressureStrategy); } PreparedGetNumberOfResults(@NonNull StorIOContentResolver storIOContentResolver, @NonNull Query query, @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.storIOContentResolver .get() .numberOfResults() .withQuery(getStub.query) .withGetResolver(getStub.getResolverForNumberOfResults) .prepare() .asRxFlowable(BackpressureStrategy.MISSING) .take(1); getStub.verifyQueryBehaviorForInteger(numberOfResultsFlowable); }
@Test public void shouldWrapExceptionIntoStorIOExceptionForFlowable() { final StorIOContentResolver storIOContentResolver = mock(StorIOContentResolver.class); Uri testUri = mock(Uri.class); when(storIOContentResolver.observeChangesOfUri(eq(testUri), eq(BackpressureStrategy.MISSING))) .thenReturn(Flowable.<Changes>empty()); final GetResolver<Integer> getResolver = mock(GetResolver.class); when(getResolver.performGet(eq(storIOContentResolver), any(Query.class))) .thenThrow(new IllegalStateException("test exception")); final TestSubscriber<Integer> testSubscriber = new TestSubscriber<Integer>(); new PreparedGetNumberOfResults.Builder(storIOContentResolver) .withQuery(Query.builder().uri(testUri).build()) .withGetResolver(getResolver) .prepare() .asRxFlowable(BackpressureStrategy.MISSING) .subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(60, SECONDS); testSubscriber.assertError(StorIOException.class); assertThat(testSubscriber.errors()).hasSize(1); StorIOException storIOException = (StorIOException) testSubscriber.errors().get(0); IllegalStateException cause = (IllegalStateException) storIOException.getCause(); assertThat(cause).hasMessage("test exception"); testSubscriber.dispose(); }