AnnouncementPresenter extends BasePresenter<AnnouncementMvpView> { public void loadAllAnnouncement(int pageNumber) { checkViewAttached(); compositeDisposable.add(mDataManager.getAllAnnouncement( getAnnouncementQueryOptions(pageNumber)) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<Announcements>() { @Override public void onNext(Announcements announcements) { if (announcements.getAnnouncement() != null) { getMvpView().showAllAnnouncement(announcements); } else { getMvpView().showSnackBar(R.string.no_more_announcement_available); getMvpView().removeLoadMoreProgressBar(); } } @Override public void onError(Throwable e) { getMvpView().showProgressbar(false); getMvpView().showSnackBar(R.string.failed_to_fetch_announcement); } @Override public void onComplete() { getMvpView().showProgressbar(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 loadAllAnnouncement_validAnnouncementsData_ReturnsResults() { when(dataManager.getAllAnnouncement(option)).thenReturn( Observable.just(announcements)); announcementPresenter.loadAllAnnouncement(1); verify(announcementMvpView, never()).showSnackBar(R.string.no_more_announcement_available); verify(announcementMvpView, never()).removeLoadMoreProgressBar(); verify(announcementMvpView).showAllAnnouncement(announcements); verify(announcementMvpView, never()).showSnackBar(R.string.failed_to_fetch_announcement); }
@Test public void loadAllAnnouncement_NULLAnnouncementsData_RemoveLoadMore() { Announcements announcements = new Announcements(); when(dataManager.getAllAnnouncement(option)).thenReturn( Observable.just(announcements)); announcementPresenter.loadAllAnnouncement(1); verify(announcementMvpView).showSnackBar(R.string.no_more_announcement_available); verify(announcementMvpView).removeLoadMoreProgressBar(); verify(announcementMvpView, never()).showAllAnnouncement(announcements); verify(announcementMvpView, never()).showSnackBar(R.string.failed_to_fetch_announcement); }
@Test public void loadAllAnnouncement_RuntimeError_ShowError() { when(dataManager.getAllAnnouncement(option)).thenReturn( Observable.<Announcements>error(new RuntimeException())); announcementPresenter.loadAllAnnouncement(1); verify(announcementMvpView, never()).showSnackBar(R.string.no_more_announcement_available); verify(announcementMvpView, never()).removeLoadMoreProgressBar(); verify(announcementMvpView, never()).showAllAnnouncement(announcements); verify(announcementMvpView).showSnackBar(R.string.failed_to_fetch_announcement); }