CountCitiesInteractor implements FlowableTransformer<Integer, Disposable> { @Override public Publisher<Disposable> apply(Flowable<Integer> upstream) { return !progress.getValue() && citiesCount.getValue() == null ? Flowable.just(interact(upstream)) : Flowable.empty(); } CountCitiesInteractor(@NonNull BehaviorSubject<Boolean> progress,
                          @NonNull BehaviorSubject<Integer> citiesCount); @Override Publisher<Disposable> apply(Flowable<Integer> upstream);  }
@Test public void applyWithProgressingAsTrueThenDoNotUpdateCitiesCount() { BehaviorSubject<Boolean> progressing = BehaviorSubject.createDefault(true); BehaviorSubject<Integer> citiesCount = BehaviorSubject.create(); new CountCitiesInteractor(progressing, citiesCount).apply(Flowable.just(10)); assertTrue(citiesCount.getValue() == null); }
@Test public void applyWithProgressingAsFalseThenUpdateCitiesCount() { BehaviorSubject<Boolean> progressing = BehaviorSubject.createDefault(false); BehaviorSubject<Integer> citiesCount = BehaviorSubject.create(); new CountCitiesInteractor(progressing, citiesCount).apply(Flowable.just(10)); assertEquals(Integer.valueOf(10), citiesCount.getValue()); }
@Test public void applyWithProgressingAsFalseThenStopProgressOnFinish() { BehaviorSubject<Boolean> progressing = BehaviorSubject.createDefault(false); BehaviorSubject<Integer> citiesCount = BehaviorSubject.create(); new CountCitiesInteractor(progressing, citiesCount).apply(Flowable.just(10)); assertFalse(progressing.getValue()); }