ListingPresenter extends BaseRxPresenter<ListingContract.View,
                                ListingContract.Interactor,
                                ListingContract.Routing> implements ListingContract.Presenter { @Override public void onViewCreated() { if (isViewAttached()) getView().showLoading(); getInteractor().getUserList() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( user -> { if (isViewAttached()) { getView().setUserList(user); getView().showContent(); } }, throwable -> { if (isViewAttached()) getView().showError(throwable); } ); }  @Override void onViewCreated(); @Override void onItemClicked(User user); @NonNull @Override ListingContract.Routing createRouting(); @NonNull @Override ListingContract.Interactor createInteractor();  }
@Test public void onViewCreatedUsersReceived() throws Exception { List<User> users = new ArrayList<>(); TestScheduler scheduler = new TestScheduler(); TestSubject<List<User>> subject = TestSubject.create(scheduler); when(mInteractor.getUserList()).thenReturn(subject); mPresenter.onViewCreated(); verify(mView).showLoading(); verify(mInteractor).getUserList(); subject.onNext(users); scheduler.triggerActions(); verify(mView).setUserList(users); verify(mView).showContent(); verify(mView, never()).showError(any()); }
@Test public void onViewCreatedFailed() throws Exception { TestScheduler scheduler = new TestScheduler(); TestSubject<List<User>> subject = TestSubject.create(scheduler); when(mInteractor.getUserList()).thenReturn(subject); mPresenter.onViewCreated(); verify(mView).showLoading(); verify(mInteractor).getUserList(); IOException e = new IOException(); subject.onError(e); scheduler.triggerActions(); verify(mView, never()).setUserList(any()); verify(mView, never()).showContent(); verify(mView).showError(e); }