PostListPresenter implements BasePresenter<PostListPresenter.View> { @Override public void attachView(View view) { mMVPView = view; mSubscriptions.add( mDataController.getCombinedPosts() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(onNext -> mMVPView.onSubscribe(onNext), onError -> {})); } PostListPresenter(DataControllerInterface dataController); @Override void attachView(View view); @Override void detachView();  }
@Test public void givenCombinedPostsReturnsNoList_whenViewIsAttached_shouldNotPassToAdapter() throws Exception { when(mDataController.getCombinedPosts()).thenReturn(Observable.empty()); mPresenter = new PostListPresenter(mDataController); mPresenter.attachView(mView); verify(mView, never()).onSubscribe(anyList()); }
@Test public void givenCombinedPostsReturnsEmptyList_whenViewIsAttached_shouldPassItToAdapterWithoutError() throws Exception { mPostListObservable = Observable.just(getEmptyPostItems()); when(mDataController.getCombinedPosts()).thenReturn(mPostListObservable); mPresenter = new PostListPresenter(mDataController); mPresenter.attachView(mView); verify(mView, atLeastOnce()).onSubscribe(getEmptyPostItems()); }
@Test public void givenCombinedPostsReturnsValidList_whenViewIsAttached_shouldPassItToAdapterWithoutError() throws Exception { mPostListObservable = Observable.just(getValidPostItems()); when(mDataController.getCombinedPosts()).thenReturn(mPostListObservable); mPresenter = new PostListPresenter(mDataController); mPresenter.attachView(mView); verify(mView, atLeastOnce()).onSubscribe(getValidPostItems()); }