### Question:
RepoMVPPresenter extends BasePresenter<RepoMVPView> implements RepoPresenter { @Override public void getRepo(@NonNull String owner, @NonNull String repo) { checkViewAttached(); getMvpView().showMessageView(false); getMvpView().showProgress(true); getDataManager().getRepo(owner, repo) .observeOn(schedulerProvider.ui()) .subscribeOn(schedulerProvider.io()) .subscribe(new SingleObserver<Response<Repo>>() { @Override public void onSubscribe(Disposable d) { getCompositeDisposable().add(d); } @Override public void onSuccess(Response<Repo> response) { getMvpView().showProgress(false); if (response.isSuccessful() && response.code() == 200) { final Repo repo = response.body(); if (repo != null) { getMvpView().showRepo(repo); } else { getMvpView().showMessageView(true); getMvpView().showEmpty(); } } else if (response.code() == 404) { ResponseBody errorBody = response.errorBody(); if (errorBody != null) { APIError apiError = getDataManager().convertToError(errorBody); getMvpView().showMessageView(true); getMvpView().showMessage(apiError.message, true); } } } @Override public void onError(Throwable e) { Timber.e(e, "Error retrieving repo"); getMvpView().showProgress(false); getMvpView().showMessageView(true); getMvpView().showMessage(R.string.err_repo, true); } }); } @Inject  RepoMVPPresenter(@NonNull DataManager dataManager,
                            @NonNull SchedulerProvider schedulerProvider,
                            @NonNull CompositeDisposable compositeDisposable); @Override void getRepo(@NonNull String owner, @NonNull String repo);  }### Answer:
@Test public void getRepoSuccess() throws Exception { String owner = TestDataFactory.repoDataFactory.createOwner().login; String repoName = TestDataFactory.repoDataFactory.createRepoName(); Repo repo = TestDataFactory.repoDataFactory.createRepo(); stubDataManagerGetRepo(owner, repoName, Single.just(Response.success(repo))); repoPresenter.getRepo(owner, repoName); testScheduler.triggerActions(); verify(mockRepoMVPView).showMessageView(false); verify(mockRepoMVPView).showProgress(true); verify(mockRepoMVPView).showProgress(false); verify(mockRepoMVPView).showRepo(repo); }
@Test public void getRepoFailure() throws Exception { String owner = TestDataFactory.repoDataFactory.createOwner().login; String repoName = TestDataFactory.repoDataFactory.createRepoName(); ResponseBody errorbody = ResponseBody.create(null, TestDataFactory.getRandomUUID()); APIError apiError = TestDataFactory.createApiError(); stubDataManagerGetRepo(owner, repoName, Single.just(Response.error(404, errorbody))); stubDataManagerConvertToError(errorbody, apiError); repoPresenter.getRepo(owner, repoName); testScheduler.triggerActions(); verify(mockRepoMVPView).showMessageView(false); verify(mockRepoMVPView).showProgress(true); verify(mockRepoMVPView).showProgress(false); verify(mockRepoMVPView).showMessageView(true); verify(mockRepoMVPView).showMessage(apiError.message, true); }
@Test public void getRepoError() throws Exception { String owner = TestDataFactory.repoDataFactory.createOwner().login; String repoName = TestDataFactory.repoDataFactory.createRepoName(); stubDataManagerGetRepo(owner, repoName, Single.error(new RuntimeException(""))); repoPresenter.getRepo(owner, repoName); testScheduler.triggerActions(); verify(mockRepoMVPView).showMessageView(false); verify(mockRepoMVPView).showProgress(true); verify(mockRepoMVPView).showProgress(false); verify(mockRepoMVPView).showMessageView(false); verify(mockRepoMVPView).showMessage(R.string.err_repo, true); }