AnnouncementPresenter extends BasePresenter<AnnouncementMvpView> { public void loadAnnouncementDetails(String id) { checkViewAttached(); compositeDisposable.add(mDataManager.getAnnouncementDetail(id) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<DetailAnnouncement>() { @Override public void onNext(DetailAnnouncement detailAnnouncement) { getMvpView().showAnnouncementDetail(detailAnnouncement); } @Override public void onError(Throwable e) { Log.d(LOG_TAG, e.getMessage()); getMvpView().showWaitProgress(false); getMvpView().showSnackBar(R.string.failed_to_fetch_announcement); } @Override public void onComplete() { getMvpView().showWaitProgress(false); } })); } @Inject  AnnouncementPresenter(DataManager dataManager); @Override void attachView(AnnouncementMvpView mvpView); @Override void detachView(); void loadAllAnnouncement(int pageNumber); void loadAnnouncementDetails(String id); final String LOG_TAG; }
@Test public void loadAnnouncementDetails_validAnnouncementData_ReturnsResults() { when(dataManager.getAnnouncementDetail("1")).thenReturn(Observable.just(announcement)); announcementPresenter.loadAnnouncementDetails("1"); verify(announcementMvpView).showAnnouncementDetail(announcement); verify(announcementMvpView, never()).showSnackBar(R.string.failed_to_fetch_announcement); }
@Test public void loadAnnouncementDetails_RuntimeError_ShowError() { DetailAnnouncement detailAnnouncement = new DetailAnnouncement(); when(dataManager.getAnnouncementDetail("1")).thenReturn(Observable .<DetailAnnouncement>error(new RuntimeException())); announcementPresenter.loadAnnouncementDetails("1"); verify(announcementMvpView, never()).showAnnouncementDetail(detailAnnouncement); verify(announcementMvpView).showSnackBar(R.string.failed_to_fetch_announcement); }