FavouriteWorkflowsPresenter extends BasePresenter<FavouriteWorkflowsMvpView> { public void loadAllWorkflow() { checkViewAttached(); getMvpView().showProgressbar(true); compositeDisposable.add(mDataManager.getFavoriteWorkflowList() .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<List<Workflow>>() { @Override public void onComplete() { getMvpView().showProgressbar(false); } @Override public void onError(Throwable e) { getMvpView().showProgressbar(false); getMvpView().showErrorSnackBar(); } @Override public void onNext(List<Workflow> workflowList) { if (workflowList.size() != 0) { getMvpView().showWorkflows(workflowList); } else { getMvpView().showEmptyWorkflow(); } } })); } @Inject  FavouriteWorkflowsPresenter(DataManager dataManager); @Override void attachView(FavouriteWorkflowsMvpView mvpView); @Override void detachView(); void loadAllWorkflow(); void attachSearchHandler(SearchView searchView); final String LOG_TAG; }
@Test public void loadAllWorkflow_validWorkflowList_ReturnsResults() { when(dataManager.getFavoriteWorkflowList()).thenReturn( Observable.just(workflows.getWorkflowList())); favouriteWorkflowsPresenter.loadAllWorkflow(); verify(favouriteWorkflowsMvpView).showWorkflows(workflows.getWorkflowList()); verify(favouriteWorkflowsMvpView, never()).showEmptyWorkflow(); verify(favouriteWorkflowsMvpView, never()).showErrorSnackBar(); }
@Test public void loadAllWorkflow_EmptyWorkflowList_ReturnsNoWorkflowResults() { Workflows workflows = new Workflows(); workflows.setWorkflowList(new ArrayList<Workflow>()); when(dataManager.getFavoriteWorkflowList()).thenReturn( Observable.just(workflows.getWorkflowList())); favouriteWorkflowsPresenter.loadAllWorkflow(); verify(favouriteWorkflowsMvpView, never()).showWorkflows(workflows.getWorkflowList()); verify(favouriteWorkflowsMvpView).showEmptyWorkflow(); verify(favouriteWorkflowsMvpView, never()).showErrorSnackBar(); }
@Test public void loadAllWorkflow_RuntimeError_ShowError() { when(dataManager.getFavoriteWorkflowList()).thenReturn( Observable.<List<Workflow>>error(new RuntimeException())); favouriteWorkflowsPresenter.loadAllWorkflow(); verify(favouriteWorkflowsMvpView, never()).showWorkflows(workflows.getWorkflowList()); verify(favouriteWorkflowsMvpView, never()).showEmptyWorkflow(); verify(favouriteWorkflowsMvpView).showErrorSnackBar(); }