@Test public void automaticLocation() { when(mHiddenPreferences.getLocationDistanceLimit()) .thenReturn(5000L); when(mLocationPreferences.isUsingAutomaticLocation()) .thenReturn(true); when(mPrayerDownloader.getPrayerTimes(eq(mLocation))) .thenReturn(Observable.just(mPrayerContext1)); when(mLocationRepository.getLocation(anyBoolean())) .thenReturn(Observable.just(mLocation)); PrayerManager prayerManager = new PrayerManager( mPrayerDownloader, mLocationRepository, mPrayerBroadcaster, mHiddenPreferences, mLocationPreferences ); TestSubscriber<PrayerContext> testSubscriber = new TestSubscriber<>(); prayerManager.getPrayerContext(false).subscribe(testSubscriber); testSubscriber.assertNoErrors(); List<PrayerContext> prayers = testSubscriber.getOnNextEvents(); assertThat(prayers).hasSize(1); assertThat(prayers.get(0)).isEqualTo(mPrayerContext1); }
public Observable<PrayerContext> getPrayerContext(final boolean refresh) { checkPrayerStream(); if (isLoading() && !refresh) { return mPrayerStream.asObservable(); } Observable<PrayerContext> data; if (!useAutomaticLocation()) { data = getPreferredPrayerContext(refresh); } else { data = getAutomaticPrayerContext(refresh); } data.subscribe(new Action1<PrayerContext>() { @Override public void call(PrayerContext prayer) { mIsError.set(false); mPrayerStream.onNext(prayer); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { mIsError.set(true); mPrayerStream.onError(throwable); } }); return mPrayerStream.asObservable(); }
PrayerManager { public Observable<PrayerContext> getPrayerContext(final boolean refresh) { checkPrayerStream(); if (isLoading() && !refresh) { return mPrayerStream.asObservable(); } Observable<PrayerContext> data; if (!useAutomaticLocation()) { data = getPreferredPrayerContext(refresh); } else { data = getAutomaticPrayerContext(refresh); } data.subscribe(new Action1<PrayerContext>() { @Override public void call(PrayerContext prayer) { mIsError.set(false); mPrayerStream.onNext(prayer); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { mIsError.set(true); mPrayerStream.onError(throwable); } }); return mPrayerStream.asObservable(); } }
PrayerManager { public Observable<PrayerContext> getPrayerContext(final boolean refresh) { checkPrayerStream(); if (isLoading() && !refresh) { return mPrayerStream.asObservable(); } Observable<PrayerContext> data; if (!useAutomaticLocation()) { data = getPreferredPrayerContext(refresh); } else { data = getAutomaticPrayerContext(refresh); } data.subscribe(new Action1<PrayerContext>() { @Override public void call(PrayerContext prayer) { mIsError.set(false); mPrayerStream.onNext(prayer); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { mIsError.set(true); mPrayerStream.onError(throwable); } }); return mPrayerStream.asObservable(); } @Inject  PrayerManager(PrayerDownloader downloader,
                         LocationRepository location,
                         PrayerBroadcaster broadcaster,
                         HiddenPreferences hprefs,
                         LocationPreferences lprefs); }
PrayerManager { public Observable<PrayerContext> getPrayerContext(final boolean refresh) { checkPrayerStream(); if (isLoading() && !refresh) { return mPrayerStream.asObservable(); } Observable<PrayerContext> data; if (!useAutomaticLocation()) { data = getPreferredPrayerContext(refresh); } else { data = getAutomaticPrayerContext(refresh); } data.subscribe(new Action1<PrayerContext>() { @Override public void call(PrayerContext prayer) { mIsError.set(false); mPrayerStream.onNext(prayer); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { mIsError.set(true); mPrayerStream.onError(throwable); } }); return mPrayerStream.asObservable(); } @Inject  PrayerManager(PrayerDownloader downloader,
                         LocationRepository location,
                         PrayerBroadcaster broadcaster,
                         HiddenPreferences hprefs,
                         LocationPreferences lprefs); Observable<PrayerContext> getPrayerContext(final boolean refresh); Observable<PrayerContext> refreshPrayerContext(Location location); void notifyPreferenceChanged(); boolean hasError(); boolean isLoading(); }
PrayerManager { public Observable<PrayerContext> getPrayerContext(final boolean refresh) { checkPrayerStream(); if (isLoading() && !refresh) { return mPrayerStream.asObservable(); } Observable<PrayerContext> data; if (!useAutomaticLocation()) { data = getPreferredPrayerContext(refresh); } else { data = getAutomaticPrayerContext(refresh); } data.subscribe(new Action1<PrayerContext>() { @Override public void call(PrayerContext prayer) { mIsError.set(false); mPrayerStream.onNext(prayer); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { mIsError.set(true); mPrayerStream.onError(throwable); } }); return mPrayerStream.asObservable(); } @Inject  PrayerManager(PrayerDownloader downloader,
                         LocationRepository location,
                         PrayerBroadcaster broadcaster,
                         HiddenPreferences hprefs,
                         LocationPreferences lprefs); Observable<PrayerContext> getPrayerContext(final boolean refresh); Observable<PrayerContext> refreshPrayerContext(Location location); void notifyPreferenceChanged(); boolean hasError(); boolean isLoading();  }