TakeSnapshotTask implements Callable<Snapshot> { @SuppressWarnings("unchecked") Collection<Contributor> collectContributors(OrganizationWrapper organization) throws IOException, URISyntaxException { logger.info("Started collecting contributors for organization '{}'.", organisationName); Collection<Contributor> contributors = new ArrayList<>(); Collection<GHRepository.Contributor> ghContributors = organization.listRepositories().stream() .map(RepositoryWrapper::listContributors) .flatMap(List::stream) .collect(toList()); Map<Integer, IntSummaryStatistics> idStatisticsMap = ghContributors.stream() .collect(groupingBy(GHObject::getId, summarizingInt(GHRepository.Contributor::getContributions))); ghContributors = ghContributors.stream() .collect(collectingAndThen(toCollection(() -> new TreeSet<>(Comparator.comparingInt(GHObject::getId))), ArrayList::new)); for (GHRepository.Contributor ghContributor : ghContributors) { Contributor contributor = new Contributor(ghContributor.getId(), organization.getId(), snapshotDate); contributor.setName(ghContributor.getName()); contributor.setUrl(ghContributor.getHtmlUrl().toURI().toString()); contributor.setOrganizationalCommitsCount((int) idStatisticsMap.get(ghContributor.getId()).getSum()); contributor.setOrganizationalProjectsCount((int) idStatisticsMap.get(ghContributor.getId()).getCount()); contributor.setPersonalProjectsCount(ghContributor.getPublicRepoCount()); contributor.setOrganizationName(organisationName); contributors.add(contributor); } logger.info("Finished collecting contributors for organization '{}'.", organisationName); return contributors; } TakeSnapshotTask(final GitHub gitHub, final String organisationName, Scorer scorer, Date snapshotDate); @Override Snapshot call();  }
@Test public void testCollectContributors() throws Exception { RepositoryWrapper repo1 = mock(RepositoryWrapper.class); Contributor c1 = newContributor(11, 22, "http: when(repo1.listContributors()).thenReturn(asList(c1)); RepositoryWrapper repo2 = mock(RepositoryWrapper.class); Contributor c2 = newContributor(44, 55, "http: when(repo2.listContributors()).thenReturn(asList(c2)); List<org.zalando.catwatch.backend.model.Contributor> contributors = new ArrayList<>( task.collectContributors(org(asList(repo1, repo2)))); assertThat(contributors, hasSize(2)); org.zalando.catwatch.backend.model.Contributor c1_ = contributors.get(0); assertThat(c1_.getId(), equalTo(11L)); assertThat(c1_.getOrganizationalCommitsCount(), equalTo(22)); assertThat(c1_.getUrl(), equalTo("http: org.zalando.catwatch.backend.model.Contributor c2_ = contributors.get(1); assertThat(c2_.getId(), equalTo(44L)); assertThat(c2_.getOrganizationalCommitsCount(), equalTo(55)); assertThat(c2_.getUrl(), equalTo("http: }