CountCitiesUseCase implements Callable<Flowable<Integer>> { @Override public Flowable<Integer> call() throws Exception { return domainRetriever.call() .compose(citiesQuery) .flatMapSingle(CitiesTable::queryCitiesCount) .toFlowable(); } CountCitiesUseCase(Application application); @RestrictTo(TESTS)  CountCitiesUseCase(Callable<Maybe<Domain>> domainRetriever,
                       MaybeTransformer<Domain, CitiesTable> citiesQuery); @Override Flowable<Integer> call();  }
@Test public void callThenReturnCitiesCount() throws Exception { final int[] result = {0}; TestScheduler scheduler = new TestScheduler(); Domain domain = new Domain(Maybe.just(new MockDatabaseGateway()), Maybe.empty()); Callable<Maybe<Domain>> domainRetriever = new MockDomainRetriever(domain); new CountCitiesUseCase(domainRetriever, new CitiesQuery(scheduler)) .call() .subscribe(value -> result[0] = value); scheduler.triggerActions(); assertEquals(MockCitiesTable.CITIES_COUNT, result[0]); }