@Test public void successDataFetcher_showContent() { presenter = new BooksListPresenter(dataFetcher); presenter.attachView(view); boolean pullToRefresh = true; presenter.loadBooks(pullToRefresh); ArgumentCaptor<DataCallback> dataCallbackArg = ArgumentCaptor.forClass(DataCallback.class); verify(view).showLoading(pullToRefresh); verify(dataFetcher, times(1)).getBooks(dataCallbackArg.capture()); dataCallbackArg.getValue().onSuccess(data); verify(view).showLoading(pullToRefresh); ArgumentCaptor<Book[]> booksArgument = ArgumentCaptor.forClass(Book[].class); verify(view).setData(booksArgument.capture()); verify(view).showContent(); assertArrayEquals(data, booksArgument.getValue()); }
public void loadBooks(final boolean pullToRefresh) { if(isViewAttached()) { getView().showLoading(pullToRefresh); } dataFetcher.getBooks(new DataCallback<Book[]>() { @Override public void onSuccess(Book[] books) { if (isViewAttached()) { getView().setData(books); getView().showContent(); } } @Override public void onFailure(String reason) { if (isViewAttached()) { getView().showError(new Throwable(reason), pullToRefresh); } } }); }
BooksListPresenter extends MvpBasePresenter<BooksListView> { public void loadBooks(final boolean pullToRefresh) { if(isViewAttached()) { getView().showLoading(pullToRefresh); } dataFetcher.getBooks(new DataCallback<Book[]>() { @Override public void onSuccess(Book[] books) { if (isViewAttached()) { getView().setData(books); getView().showContent(); } } @Override public void onFailure(String reason) { if (isViewAttached()) { getView().showError(new Throwable(reason), pullToRefresh); } } }); } }
BooksListPresenter extends MvpBasePresenter<BooksListView> { public void loadBooks(final boolean pullToRefresh) { if(isViewAttached()) { getView().showLoading(pullToRefresh); } dataFetcher.getBooks(new DataCallback<Book[]>() { @Override public void onSuccess(Book[] books) { if (isViewAttached()) { getView().setData(books); getView().showContent(); } } @Override public void onFailure(String reason) { if (isViewAttached()) { getView().showError(new Throwable(reason), pullToRefresh); } } }); } BooksListPresenter(DataFetcher dataFetcher); }
BooksListPresenter extends MvpBasePresenter<BooksListView> { public void loadBooks(final boolean pullToRefresh) { if(isViewAttached()) { getView().showLoading(pullToRefresh); } dataFetcher.getBooks(new DataCallback<Book[]>() { @Override public void onSuccess(Book[] books) { if (isViewAttached()) { getView().setData(books); getView().showContent(); } } @Override public void onFailure(String reason) { if (isViewAttached()) { getView().showError(new Throwable(reason), pullToRefresh); } } }); } BooksListPresenter(DataFetcher dataFetcher); void loadBooks(final boolean pullToRefresh); }
BooksListPresenter extends MvpBasePresenter<BooksListView> { public void loadBooks(final boolean pullToRefresh) { if(isViewAttached()) { getView().showLoading(pullToRefresh); } dataFetcher.getBooks(new DataCallback<Book[]>() { @Override public void onSuccess(Book[] books) { if (isViewAttached()) { getView().setData(books); getView().showContent(); } } @Override public void onFailure(String reason) { if (isViewAttached()) { getView().showError(new Throwable(reason), pullToRefresh); } } }); } BooksListPresenter(DataFetcher dataFetcher); void loadBooks(final boolean pullToRefresh);  }