@Test public void testCollectContributors() throws Exception { // given RepositoryWrapper repo1 = mock(RepositoryWrapper.class); Contributor c1 = newContributor(11, 22, "http://a.com", 33); when(repo1.listContributors()).thenReturn(asList(c1)); RepositoryWrapper repo2 = mock(RepositoryWrapper.class); Contributor c2 = newContributor(44, 55, "http://b.com", 66); when(repo2.listContributors()).thenReturn(asList(c2)); // when List<org.zalando.catwatch.backend.model.Contributor> contributors = // new ArrayList<org.zalando.catwatch.backend.model.Contributor>( // task.collectContributors(org(asList(repo1, repo2)))); // then 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://a.com")); 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://b.com")); }
private RepositoryWrapper repo(Object... keyAndValuePairs) { RepositoryWrapper repo = mock(RepositoryWrapper.class); when(repo.listLanguages()).thenReturn(toMap(keyAndValuePairs)); return repo; }
@Test public void testCollectProjects() throws Exception { // given RepositoryWrapper repo = mock(RepositoryWrapper.class); when(repo.getId()).thenReturn(123); when(repo.getName()).thenReturn("awesome"); when(repo.getUrl()).thenReturn(new URL("http://a.com/b.html")); 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(scorer.score(any(Project.class))).thenReturn(55); // when List<Project> projects = new ArrayList<>(task.collectProjects(org(singletonList(repo)))); // then 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://a.com/b.html")); 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)); }