RepositoriesPresenter extends BasePresenter<RepositoriesPresenter.ViewContract> implements Bundleable { public List<GithubRepo> getRepositories() { return repositories; } @Inject  RepositoriesPresenter(); boolean didDownloadAll(); List<GithubRepo> getRepositories(); void openRepository(GithubRepo githubRepo); void downloadMore(); @Override Bundle toBundle(); @Override void fromBundle(@Nullable Bundle bundle);  }
@Test public void initializeViewNoData() throws Exception { repositoriesPresenter.repositories = null; repositoriesPresenter.isDownloading = true; repositoriesPresenter.downloadedAll = false; repositoriesPresenter.currentPage = 1; repositoriesPresenter.getRepositoriesInteractor = getRepositoriesInteractor; repositoriesPresenter.githubRepoRepository = githubRepoRepository; Single<List<GithubRepo>> task = Mockito.mock(Single.class); Mockito.when(getRepositoriesInteractor.getRepositories(RepositoriesPresenter.REPO_NAME, 1)).thenReturn(task); repositoriesPresenter.attachView(viewContract); assertThat(repositoriesPresenter.isDownloading).isTrue(); Mockito.verify(getRepositoriesInteractor).getRepositories(RepositoriesPresenter.REPO_NAME, 1); }
@Test public void initializeViewWithData() throws Exception { List<GithubRepo> repositories = new ArrayList<GithubRepo>() {{ add(new GithubRepo()); }}; repositoriesPresenter.repositories = repositories; repositoriesPresenter.downloadedAll = true; repositoriesPresenter.isDownloading = false; repositoriesPresenter.currentPage = 2; repositoriesPresenter.getRepositoriesInteractor = getRepositoriesInteractor; repositoriesPresenter.githubRepoRepository = githubRepoRepository; repositoriesPresenter.attachView(viewContract); assertThat(repositoriesPresenter.isDownloading).isFalse(); Mockito.verify(getRepositoriesInteractor, Mockito.never()).getRepositories(RepositoriesPresenter.REPO_NAME, 2); Mockito.verify(viewContract).updateRepositories(repositories); }
@Test public void getRepositories() throws Exception { List<GithubRepo> repositories = new ArrayList<GithubRepo>() {{ add(new GithubRepo()); }}; repositoriesPresenter.repositories = repositories; List<GithubRepo> presenterRepos = repositoriesPresenter.getRepositories(); assertThat(repositories).isEqualTo(presenterRepos); }