BookInfoPresenter extends BasePresenter<BookInfoContract.View> implements BookInfoContract.Presenter { @Override public void loadContributorInformation(FireBookDetails bookDetailId) { addSubscription( bookService.getContributorsForBook(bookDetailId).subscribeOn(ioScheduler).observeOn(mainScheduler) .subscribe(new Subscriber<List<FireContributor>>() { @Override public void onCompleted() { } @Override public void onError(final Throwable e) { getView().showSnackBarMessage(R.string.error_getting_contributors); } @Override public void onNext(final List<FireContributor> fireContributors) { getView().showContributors(fireContributors); } })); } BookInfoPresenter(@NonNull BookService bookService, @NonNull DownloadService downloadService,
                      @NonNull Analytics analytics, Scheduler ioScheduler, Scheduler mainScheduler); @Override void loadContributorInformation(FireBookDetails bookDetailId); @Override void downloadBook(final FireBookDetails bookInfo); @Override void shareBookClicked(FireBookDetails bookInfo);  }
@Test public void loadContributorInformation_ShowsContributors() { CONTRIBUTORS = new ArrayList<>(); FireContributor fireContributor = new FireContributor("Rebecca Franks", "avatar_url", "123"); CONTRIBUTORS.add(fireContributor); when(bookService.getContributorsForBook(BOOK_DETAIL)) .thenReturn(Observable.<List<FireContributor>>just(CONTRIBUTORS)); bookInfoPresenter.loadContributorInformation(BOOK_DETAIL); bookInfoView.showContributors(CONTRIBUTORS); }
@Test public void loadContributorInformation_ErrorThrown_ShowsSnackbarError() { when(bookService.getContributorsForBook(BOOK_DETAIL)) .thenReturn(Observable.<List<FireContributor>>error(new Exception("Error Downloading Books"))); bookInfoPresenter.loadContributorInformation(BOOK_DETAIL); bookInfoView.showSnackBarMessage(R.string.error_getting_contributors); }