TakeSnapshotTask implements Callable<Snapshot> { @SuppressWarnings("rawtypes") Collection<Language> collectLanguages(OrganizationWrapper organization) { logger.info("Started collecting languages for organization '{}'.", organisationName); Collection<Language> languages = new ArrayList<>(); Map<String, LongSummaryStatistics> stat = organization.listRepositories().stream() .map(RepositoryWrapper::listLanguages) .map(Map::entrySet) .flatMap(Set::stream) .collect(groupingBy(Map.Entry::getKey, summarizingLong(entry -> ((Number) ((Map.Entry) entry).getValue()).longValue()))); final long allLanguageSize = stat.entrySet().stream() .map(entry -> entry.getValue().getSum()) .reduce(0L, Long::sum); for (Map.Entry<String, LongSummaryStatistics> entry : stat.entrySet()) { Language language = new Language(); language.setName(entry.getKey()); language.setProjectsCount((int) entry.getValue().getCount()); language.setPercentage((int) (entry.getValue().getSum() * 100 / allLanguageSize)); languages.add(language); } logger.info("Finished collecting languages for organization '{}'.", organisationName); return languages; } TakeSnapshotTask(final GitHub gitHub, final String organisationName, Scorer scorer, Date snapshotDate); @Override Snapshot call();  }
@Test public void testCollectLanguages() throws Exception { List<RepositoryWrapper> repos = asList( repo("C", 30, "Go", 15, "Java", 4), repo("C", 30, "Go", 15, "Java", 4), repo("Java", 2)); List<Language> langs = new ArrayList<>(task.collectLanguages(org(repos))); assertThat(langs, hasSize(3)); sort(langs, (p1, p2) -> p1.getName().compareTo(p2.getName())); assertThat(langs.get(0).getName(), equalTo("C")); assertThat(langs.get(0).getProjectsCount(), equalTo(2)); assertThat(langs.get(0).getPercentage(), equalTo(60)); assertThat(langs.get(1).getName(), equalTo("Go")); assertThat(langs.get(1).getProjectsCount(), equalTo(2)); assertThat(langs.get(1).getPercentage(), equalTo(30)); assertThat(langs.get(2).getName(), equalTo("Java")); assertThat(langs.get(2).getProjectsCount(), equalTo(3)); assertThat(langs.get(2).getPercentage(), equalTo(10)); }