WorkflowPresenter extends BasePresenter<WorkflowMvpView> { public void loadAllWorkflow(final int pageNumber) { checkViewAttached(); getMvpView().showProgressbar(true); compositeDisposable.add(mDataManager.getAllWorkflow(getQueryOptions(pageNumber)) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<Workflows>() { @Override public void onNext(Workflows workflows) { if (workflows.getWorkflowList() != null) { getMvpView().showProgressbar(false); getMvpView().removeLoadMoreProgressbar(); getMvpView().showWorkflows(workflows); } else { if (pageNumber == 1) { getMvpView().showSnackBar(R.string.no_workflows_found); } else { getMvpView().showSnackBar(R.string.no_more_workflows_avialable); } getMvpView().removeLoadMoreProgressbar(); } } @Override public void onError(Throwable e) { getMvpView().showProgressbar(false); getMvpView().showSnackBar(R.string.error_failed_to_fetch_workflow); getMvpView().removeLoadMoreProgressbar(); } @Override public void onComplete() { } })); } @Inject  WorkflowPresenter(DataManager dataManager); @Override void attachView(WorkflowMvpView mvpView); @Override void detachView(); void loadAllWorkflow(final int pageNumber); void attachSearchHandler(final SearchView searchView); void detachSearchHandler(); void searchWorkflow(int pageNumber, String query); final String LOG_TAG; }
@Test public void loadAllWorkflow_page2_EmptyWorkflow_ReturnNoMoreWorkflowResults() { Workflows workflows = new Workflows(); when(dataManager.getAllWorkflow(optionPage2)).thenReturn( Observable.just(workflows)); workflowPresenter.loadAllWorkflow(2); verify(workflowMvpView).showProgressbar(true); verify(workflowMvpView).removeLoadMoreProgressbar(); verify(workflowMvpView).showSnackBar(R.string.no_more_workflows_avialable); verify(workflowMvpView, never()).showWorkflows(workflows); verify(workflowMvpView, never()).showSnackBar(R.string.no_workflows_found); verify(workflowMvpView, never()).showSnackBar(R.string.error_failed_to_fetch_workflow); }
@Test public void loadAllWorkflow_RuntimeError_showError() { when(dataManager.getAllWorkflow(optionPage1)).thenReturn( Observable.<Workflows>error(new RuntimeException())); workflowPresenter.loadAllWorkflow(1); verify(workflowMvpView).showProgressbar(false); verify(workflowMvpView).removeLoadMoreProgressbar(); verify(workflowMvpView, never()).showWorkflows(workflows); verify(workflowMvpView).showSnackBar(R.string.error_failed_to_fetch_workflow); }
@Test public void loadAllWorkflow_validWorkflowList_ReturnsResults() { when(dataManager.getAllWorkflow(optionPage1)).thenReturn( Observable.just(workflows)); workflowPresenter.loadAllWorkflow(1); verify(workflowMvpView).showProgressbar(true); verify(workflowMvpView).removeLoadMoreProgressbar(); verify(workflowMvpView).showWorkflows(workflows); verify(workflowMvpView, never()).showSnackBar(R.string.error_failed_to_fetch_workflow); }
@Test public void loadAllWorkflow_EmptyWorkflow_ReturnNoWorkflowResults() { Workflows workflows = new Workflows(); when(dataManager.getAllWorkflow(optionPage1)).thenReturn( Observable.just(workflows)); workflowPresenter.loadAllWorkflow(1); verify(workflowMvpView).showProgressbar(true); verify(workflowMvpView).removeLoadMoreProgressbar(); verify(workflowMvpView).showSnackBar(R.string.no_workflows_found); verify(workflowMvpView, never()).showWorkflows(workflows); verify(workflowMvpView, never()).showSnackBar(R.string.error_failed_to_fetch_workflow); }