@Test public void openCityWithEmptyForecast() { when(mRepository.getForecast(54353, false)).thenReturn(Observable.just(new ArrayList<>())); when(mView.getResources()).thenReturn(mResources); when(mResources.getString(R.string.error)).thenReturn("Error"); mPresenter.openCity(54353); verify(mRepository).getForecast(54353, false); ArgumentCaptor<String> errorMessage = ArgumentCaptor.forClass(String.class); verify(mView).showError(errorMessage.capture()); verify(mView).showProgressBar(false); }
@Override public void openCity(int cityId) { mSubscriptions.clear(); Subscription subscription = mRepository .getForecast(cityId, mView.isNetworkAvailable()) .subscribeOn(mBackgroundScheduler) .observeOn(mMainScheduler) .subscribe( this::makeView, Throwable::printStackTrace, () -> mView.showProgressBar(false) ); mSubscriptions.add(subscription); }
CityDetailPresenter implements CityDetailContract.Presenter { @Override public void openCity(int cityId) { mSubscriptions.clear(); Subscription subscription = mRepository .getForecast(cityId, mView.isNetworkAvailable()) .subscribeOn(mBackgroundScheduler) .observeOn(mMainScheduler) .subscribe( this::makeView, Throwable::printStackTrace, () -> mView.showProgressBar(false) ); mSubscriptions.add(subscription); } }
CityDetailPresenter implements CityDetailContract.Presenter { @Override public void openCity(int cityId) { mSubscriptions.clear(); Subscription subscription = mRepository .getForecast(cityId, mView.isNetworkAvailable()) .subscribeOn(mBackgroundScheduler) .observeOn(mMainScheduler) .subscribe( this::makeView, Throwable::printStackTrace, () -> mView.showProgressBar(false) ); mSubscriptions.add(subscription); } CityDetailPresenter(CityDetailContract.View cityDetailView, RepositoryDataSource repository,
                               Scheduler background, Scheduler main); }
CityDetailPresenter implements CityDetailContract.Presenter { @Override public void openCity(int cityId) { mSubscriptions.clear(); Subscription subscription = mRepository .getForecast(cityId, mView.isNetworkAvailable()) .subscribeOn(mBackgroundScheduler) .observeOn(mMainScheduler) .subscribe( this::makeView, Throwable::printStackTrace, () -> mView.showProgressBar(false) ); mSubscriptions.add(subscription); } CityDetailPresenter(CityDetailContract.View cityDetailView, RepositoryDataSource repository,
                               Scheduler background, Scheduler main); @Override void subscribe(); @Override void unsubscribe(); @Override void openCity(int cityId); }
CityDetailPresenter implements CityDetailContract.Presenter { @Override public void openCity(int cityId) { mSubscriptions.clear(); Subscription subscription = mRepository .getForecast(cityId, mView.isNetworkAvailable()) .subscribeOn(mBackgroundScheduler) .observeOn(mMainScheduler) .subscribe( this::makeView, Throwable::printStackTrace, () -> mView.showProgressBar(false) ); mSubscriptions.add(subscription); } CityDetailPresenter(CityDetailContract.View cityDetailView, RepositoryDataSource repository,
                               Scheduler background, Scheduler main); @Override void subscribe(); @Override void unsubscribe(); @Override void openCity(int cityId);  }