RepositoriesPresenter extends BasePresenter<RepositoriesView> { public void loadNextRepositories(int currentCount) { int page = currentCount / GithubApi.PAGE_SIZE + 1; loadData(page, true, false); } RepositoriesPresenter(); void loadNextRepositories(int currentCount); void loadRepositories(boolean isRefreshing); void onErrorCancel();  }
@Test public void repositories_shouldCorrectLoadNextRepositories() { List<Repository> repositories = repositores(); when(githubService.getUserRepos(anyString(), anyInt(), anyInt())).thenReturn(Observable.just(repositories)); presenter.loadNextRepositories(10); verify(repositoriesViewState).onStartLoading(); verify(repositoriesViewState, never()).showListProgress(); verify(repositoriesViewState, never()).hideListProgress(); verify(repositoriesViewState).onFinishLoading(); verify(repositoriesViewState).addRepositories(repositories, false); }
@Test public void repositories_shouldShowErrorIfSomeExceptionHappended() { RuntimeException someError = new RuntimeException(); when(githubService.getUserRepos(anyString(), anyInt(), anyInt())).thenReturn(Observable.error(someError)); presenter.loadNextRepositories(10); verify(repositoriesViewState).onStartLoading(); verify(repositoriesViewState).onFinishLoading(); verify(repositoriesViewState).showError(someError.toString()); }