### Question:
PreparedGetNumberOfResults extends PreparedGetMandatoryResult<Integer> { @NonNull @CheckResult @Override public Single<Integer> asRxSingle() { return RxJavaUtils.createSingle(storIOContentResolver, this); } 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 shouldGetNumberOfResultsWithQueryAsSingle() { final GetNumberOfResultsStub getStub = GetNumberOfResultsStub.newInstance(); final Single<Integer> numberOfResultsSingle = getStub.storIOContentResolver .get() .numberOfResults() .withQuery(getStub.query) .withGetResolver(getStub.getResolverForNumberOfResults) .prepare() .asRxSingle(); getStub.verifyQueryBehaviorForInteger(numberOfResultsSingle); }
@Test public void shouldWrapExceptionIntoStorIOExceptionForSingle() { final StorIOContentResolver storIOContentResolver = mock(StorIOContentResolver.class); Uri testUri = mock(Uri.class); final GetResolver<Integer> getResolver = mock(GetResolver.class); when(getResolver.performGet(eq(storIOContentResolver), any(Query.class))) .thenThrow(new IllegalStateException("test exception")); final TestObserver<Integer> testObserver = new TestObserver<Integer>(); new PreparedGetNumberOfResults.Builder(storIOContentResolver) .withQuery(Query.builder().uri(testUri).build()) .withGetResolver(getResolver) .prepare() .asRxSingle() .subscribe(testObserver); testObserver.awaitTerminalEvent(60, SECONDS); testObserver.assertError(StorIOException.class); assertThat(testObserver.errors()).hasSize(1); StorIOException storIOException = (StorIOException) testObserver.errors().get(0); IllegalStateException cause = (IllegalStateException) storIOException.getCause(); assertThat(cause).hasMessage("test exception"); testObserver.dispose(); }