TakeSnapshotTask implements Callable<Snapshot> { Collection<Project> collectProjects(OrganizationWrapper organization) throws IOException, URISyntaxException { logger.info("Started collecting projects for organization '{}'.", organisationName); List<Project> projects = new ArrayList<>(); for (RepositoryWrapper repository : organization.listRepositories()) { Project project = new Project(); project.setGitHubProjectId(repository.getId()); project.setSnapshotDate(snapshotDate); project.setName(repository.getName()); project.setUrl(repository.getUrl().toURI().toString()); project.setDescription(repository.getDescription()); project.setStarsCount(repository.getStarsCount()); project.setForksCount(repository.getForksCount()); project.setLastPushed(repository.getLastPushed().toString()); project.setPrimaryLanguage(repository.getPrimaryLanguage()); project.setLanguageList(new ArrayList<>(repository.listLanguages().keySet())); project.setOrganizationName(organization.getLogin()); project.setCommitsCount(repository.listCommits().size()); project.setContributorsCount(repository.listContributors().size()); project.setExternalContributorsCount((int) repository.listContributors().stream() .filter(contributor -> !organization.contributorIsMember(contributor)) .map(GHRepository.Contributor::getId) .distinct() .count()); project.setScore(scorer.score(project)); project.setMaintainers(getProjectMaintainers(repository)); readCatwatchYaml(repository, project); projects.add(project); } logger.info("Finished collecting projects for organization '{}'.", organisationName); return projects; } TakeSnapshotTask(final GitHub gitHub, final String organisationName, Scorer scorer, Date snapshotDate); @Override Snapshot call();  }
@Test public void testCollectProjects() throws Exception { RepositoryWrapper repo = mock(RepositoryWrapper.class); when(repo.getId()).thenReturn(123); when(repo.getName()).thenReturn("awesome"); when(repo.getUrl()).thenReturn(new URL("http: when(repo.getDescription()).thenReturn("cool"); when(repo.getStarsCount()).thenReturn(11); when(repo.getForksCount()).thenReturn(22); when(repo.getLastPushed()).thenReturn(date); when(repo.getPrimaryLanguage()).thenReturn("Go"); when(repo.listLanguages()).thenReturn(toMap("C", 30, "Go", 15, "Java", 4)); when(repo.listCommits()).thenReturn(mockList(GHCommit.class, 2)); when(repo.listContributors()).thenReturn(mockList(Contributor.class, 2)); when(repo.getFileContent("MAINTAINERS")).thenReturn(new ByteArrayInputStream("foo\nbar".getBytes())); when(repo.getFileContent(".catwatch.yaml")).thenReturn(new ByteArrayInputStream("image: test\n".getBytes())); when(scorer.score(any(Project.class))).thenReturn(55); List<Project> projects = new ArrayList<>(task.collectProjects(org(singletonList(repo)))); assertThat(projects, hasSize(1)); Project project = projects.get(0); assertThat(project.getGitHubProjectId(), equalTo(123L)); assertThat(project.getSnapshotDate().getTime(), equalTo(((Date)ReflectionTestUtils.getField(task, "snapshotDate")).getTime())); assertThat(project.getName(), equalTo("awesome")); assertThat(project.getUrl(), equalTo("http: assertThat(project.getDescription(), equalTo("cool")); assertThat(project.getStarsCount(), equalTo(11)); assertThat(project.getForksCount(), equalTo(22)); assertThat(project.getLastPushed(), equalTo(date.toString())); assertThat(project.getPrimaryLanguage(), equalTo("Go")); assertThat(project.getLanguageList(), containsInAnyOrder("C", "Go", "Java")); assertThat(project.getCommitsCount(), equalTo(2)); assertThat(project.getContributorsCount(), equalTo(2)); assertThat(project.getScore(), equalTo(55)); assertThat(project.getMaintainers(), containsInAnyOrder("foo", "bar")); assertThat(project.getImage(), equalTo("test")); }