@Test public void loadCities() { when(mRepository.getCityList()).thenReturn(Observable.just(CITIES)); Observable<OrmWeather> oWeather = Observable.just(new OrmWeather()); when(mRepository.getSingleForecast(CITIES.get(0).get_id().intValue(), false)).thenReturn(oWeather); mPresenter.loadCities(); verify(mView).setRefreshing(true); verify(mRepository).getCityList(); ArgumentCaptor<CityWithWeather> showTasksArgumentCaptor = ArgumentCaptor.forClass(CityWithWeather.class); verify(mView).addCityToList(showTasksArgumentCaptor.capture()); verify(mView).setRefreshing(false); }
@Override public void loadCities() { EspressoIdlingResource.increment(); mView.setRefreshing(true); mSubscriptions.clear(); Subscription subscription = mRepository .getCityList() .flatMap(Observable::from) .toSortedList((city1, city2) -> city1.getCity_name().compareTo(city2.getCity_name())) .flatMap(Observable::from) .flatMap(CitiesPresenter.this::getCityWithWeather) .subscribeOn(mBackgroundScheduler) .observeOn(mMainScheduler) .subscribe( city -> mView.addCityToList(city), throwable -> { EspressoIdlingResource.decrement(); mView.setRefreshing(false); throwable.printStackTrace(); }, () -> { EspressoIdlingResource.decrement(); mView.setRefreshing(false); } ); mSubscriptions.add(subscription); }
CitiesPresenter implements CitiesContract.Presenter { @Override public void loadCities() { EspressoIdlingResource.increment(); mView.setRefreshing(true); mSubscriptions.clear(); Subscription subscription = mRepository .getCityList() .flatMap(Observable::from) .toSortedList((city1, city2) -> city1.getCity_name().compareTo(city2.getCity_name())) .flatMap(Observable::from) .flatMap(CitiesPresenter.this::getCityWithWeather) .subscribeOn(mBackgroundScheduler) .observeOn(mMainScheduler) .subscribe( city -> mView.addCityToList(city), throwable -> { EspressoIdlingResource.decrement(); mView.setRefreshing(false); throwable.printStackTrace(); }, () -> { EspressoIdlingResource.decrement(); mView.setRefreshing(false); } ); mSubscriptions.add(subscription); } }
CitiesPresenter implements CitiesContract.Presenter { @Override public void loadCities() { EspressoIdlingResource.increment(); mView.setRefreshing(true); mSubscriptions.clear(); Subscription subscription = mRepository .getCityList() .flatMap(Observable::from) .toSortedList((city1, city2) -> city1.getCity_name().compareTo(city2.getCity_name())) .flatMap(Observable::from) .flatMap(CitiesPresenter.this::getCityWithWeather) .subscribeOn(mBackgroundScheduler) .observeOn(mMainScheduler) .subscribe( city -> mView.addCityToList(city), throwable -> { EspressoIdlingResource.decrement(); mView.setRefreshing(false); throwable.printStackTrace(); }, () -> { EspressoIdlingResource.decrement(); mView.setRefreshing(false); } ); mSubscriptions.add(subscription); } CitiesPresenter(@NonNull CitiesContract.View view,
                           @NonNull RepositoryDataSource repository,
                           @NonNull Scheduler background, Scheduler main); }
CitiesPresenter implements CitiesContract.Presenter { @Override public void loadCities() { EspressoIdlingResource.increment(); mView.setRefreshing(true); mSubscriptions.clear(); Subscription subscription = mRepository .getCityList() .flatMap(Observable::from) .toSortedList((city1, city2) -> city1.getCity_name().compareTo(city2.getCity_name())) .flatMap(Observable::from) .flatMap(CitiesPresenter.this::getCityWithWeather) .subscribeOn(mBackgroundScheduler) .observeOn(mMainScheduler) .subscribe( city -> mView.addCityToList(city), throwable -> { EspressoIdlingResource.decrement(); mView.setRefreshing(false); throwable.printStackTrace(); }, () -> { EspressoIdlingResource.decrement(); mView.setRefreshing(false); } ); mSubscriptions.add(subscription); } CitiesPresenter(@NonNull CitiesContract.View view,
                           @NonNull RepositoryDataSource repository,
                           @NonNull Scheduler background, Scheduler main); @Override void subscribe(); @Override void unsubscribe(); @Override void loadCities(); @Override void removeCity(@NonNull OrmCity city); @Override void removeWeather(int cityId); }
CitiesPresenter implements CitiesContract.Presenter { @Override public void loadCities() { EspressoIdlingResource.increment(); mView.setRefreshing(true); mSubscriptions.clear(); Subscription subscription = mRepository .getCityList() .flatMap(Observable::from) .toSortedList((city1, city2) -> city1.getCity_name().compareTo(city2.getCity_name())) .flatMap(Observable::from) .flatMap(CitiesPresenter.this::getCityWithWeather) .subscribeOn(mBackgroundScheduler) .observeOn(mMainScheduler) .subscribe( city -> mView.addCityToList(city), throwable -> { EspressoIdlingResource.decrement(); mView.setRefreshing(false); throwable.printStackTrace(); }, () -> { EspressoIdlingResource.decrement(); mView.setRefreshing(false); } ); mSubscriptions.add(subscription); } CitiesPresenter(@NonNull CitiesContract.View view,
                           @NonNull RepositoryDataSource repository,
                           @NonNull Scheduler background, Scheduler main); @Override void subscribe(); @Override void unsubscribe(); @Override void loadCities(); @Override void removeCity(@NonNull OrmCity city); @Override void removeWeather(int cityId);  }