ForensicsModel extends DetailsTableModel { @Override public ForensicsRow getRow(final Issue issue) { ForensicsRow row = new ForensicsRow(getAgeBuilder(), getFileNameRenderer(), getDescriptionProvider(), issue, getJenkinsFacade()); if (statistics.contains(issue.getFileName())) { FileStatistics result = statistics.get(issue.getFileName()); row.setAuthorsSize(String.valueOf(result.getNumberOfAuthors())); row.setCommitsSize(String.valueOf(result.getNumberOfCommits())); row.setModifiedAt(result.getLastModificationTime()); row.setAddedAt(result.getCreationTime()); } else { row.setAuthorsSize(UNDEFINED); row.setCommitsSize(UNDEFINED); row.setModifiedAt(0); row.setAddedAt(0); } return row; } ForensicsModel(final Report report, final RepositoryStatistics statistics,
            final FileNameRenderer fileNameRenderer, final AgeBuilder ageBuilder,
            final DescriptionProvider labelProvider); @VisibleForTesting  ForensicsModel(final Report report, final RepositoryStatistics statistics,
            final FileNameRenderer fileNameRenderer, final AgeBuilder ageBuilder,
            final DescriptionProvider labelProvider, final JenkinsFacade jenkinsFacade); @Override String getId(); @Override List<TableColumn> getColumns(); @Override ForensicsRow getRow(final Issue issue);  }
@Test void shouldShowIssueWithForensics() { Report report = new Report(); Issue issue = createIssue(1); report.add(issue); RepositoryStatistics statistics = mock(RepositoryStatistics.class); FileStatistics fileStatistics = mock(FileStatistics.class); when(fileStatistics.getNumberOfAuthors()).thenReturn(15); when(fileStatistics.getNumberOfCommits()).thenReturn(20); when(fileStatistics.getLastModificationTime()).thenReturn(25); when(fileStatistics.getCreationTime()).thenReturn(30); when(statistics.get(FILE_NAME)).thenReturn(fileStatistics); when(statistics.contains(FILE_NAME)).thenReturn(true); ForensicsModel model = createModel(report, statistics); ForensicsRow actualRow = model.getRow(issue); assertThat(actualRow).hasDescription(EXPECTED_DESCRIPTION) .hasAge("1") .hasAuthorsSize("15") .hasCommitsSize("20") .hasModifiedAt(25) .hasAddedAt(30); assertThatDetailedColumnContains(actualRow.getFileName(), createExpectedFileName(issue), "/path/to/file-1:0000015"); }
@Test void shouldShowIssueWithoutForensics() { Report report = new Report(); Issue issue = createIssue(1); report.add(issue); RepositoryStatistics blames = mock(RepositoryStatistics.class); ForensicsModel model = createModel(report, blames); ForensicsRow actualRow = model.getRow(issue); assertThat(actualRow).hasDescription(EXPECTED_DESCRIPTION) .hasAge("1") .hasAuthorsSize(ForensicsModel.UNDEFINED) .hasCommitsSize(ForensicsModel.UNDEFINED); assertThatDetailedColumnContains(actualRow.getFileName(), createExpectedFileName(issue), "/path/to/file-1:0000015"); }