DownloadsPresenter extends BasePresenter<DownloadsContract.View> implements DownloadsContract.Presenter { public void loadListDownloads() { getView().showLoading(true); addSubscription(bookService.getDownloadedBooks().subscribeOn(ioScheduler).observeOn(mainScheduler) .subscribe(new Subscriber<List<FireBookDetails>>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { getView().showErrorScreen(true, e.getMessage(), true); getView().showLoading(false); } @Override public void onNext(List<FireBookDetails> books) { getView().showLoading(false); if (books.isEmpty() || books.size() == 0) { getView().showNoBooksDownloadedMessage(); return; } getView().showDownloadedBooks(books); } })); } DownloadsPresenter(BookService bookService, DownloadService downloadService, Analytics analytics, Scheduler io,
                       Scheduler main, Scheduler compScheduler); void loadListDownloads(); @Override void deleteDownload(final FireBookDetails bookDetail);  }
@Test public void loadListDownloads_NoDownloads_ShowsNoDownloadsMessage() { downloadsPresenter.attachView(downloadsView); when(bookService.getDownloadedBooks()).thenReturn(Observable.just(BOOKS)); downloadsPresenter.loadListDownloads(); verify(downloadsView).showLoading(true); verify(downloadsView).showLoading(false); verify(downloadsView).showNoBooksDownloadedMessage(); verify(downloadsView, never()).showDownloadedBooks(anyList()); }
@Test public void loadListDownloads_DownloadsAvailable_ShowsListDownloads() { downloadsPresenter.attachView(downloadsView); FireBookDetails sampleBook = new FireBookDetails("Test Book", "test_url", "cover_url_test", true, "description", language, System.currentTimeMillis()); BOOKS.add(sampleBook); when(bookService.getDownloadedBooks()).thenReturn(Observable.just(BOOKS)); downloadsPresenter.loadListDownloads(); verify(downloadsView).showLoading(true); verify(downloadsView).showLoading(false); verify(downloadsView).showDownloadedBooks(BOOKS); verify(downloadsView, never()).showNoBooksDownloadedMessage(); }
@Test public void loadListDownloads_DownloadException_ShowsErrorMessage() { downloadsPresenter.attachView(downloadsView); when(bookService.getDownloadedBooks()) .thenReturn(Observable.<List<FireBookDetails>>error(new Exception("Book Exception"))); downloadsPresenter.loadListDownloads(); verify(downloadsView).showLoading(true); verify(downloadsView).showLoading(false); verify(downloadsView, never()).showDownloadedBooks(BOOKS); verify(downloadsView, never()).showNoBooksDownloadedMessage(); verify(downloadsView).showErrorScreen(true, "Book Exception", true); }