DetailFactory { @SuppressWarnings({"PMD.CyclomaticComplexity", "checkstyle:ParameterNumber"}) Object createTrendDetails(final String link, final Run<?, ?> owner, final AnalysisResult result, final Report allIssues, final Report newIssues, final Report outstandingIssues, final Report fixedIssues, final Charset sourceEncoding, final IssuesDetail parent) { StaticAnalysisLabelProvider labelProvider = parent.getLabelProvider(); if (link.contains(LINK_SEPARATOR)) { return createFilteredView(link, owner, result, allIssues, newIssues, outstandingIssues, fixedIssues, sourceEncoding, parent, labelProvider); } else { return createNewDetailView(link, owner, result, allIssues, newIssues, outstandingIssues, fixedIssues, sourceEncoding, parent, labelProvider); } } DetailFactory(); @VisibleForTesting  DetailFactory(final JenkinsFacade jenkinsFacade, final BuildFolderFacade buildFolder);   }
@Test void shouldThrowExceptionIfLinkIsNotFound() { assertThatExceptionOfType(NoSuchElementException.class) .isThrownBy(() -> new DetailFactory().createTrendDetails("broken", RUN, createResult(), ALL_ISSUES, NEW_ISSUES, OUTSTANDING_ISSUES, FIXED_ISSUES, ENCODING, createParent())); }
@Test void shouldReturnFixedWarningsDetailWhenCalledWithFixedLink() { FixedWarningsDetail details = createTrendDetails("fixed", RUN, createResult(), ALL_ISSUES, NEW_ISSUES, OUTSTANDING_ISSUES, FIXED_ISSUES, ENCODING, createParent(), FixedWarningsDetail.class); assertThat(details).hasIssues(FIXED_ISSUES); assertThat(details).hasFixedIssues(FIXED_ISSUES); assertThat(details).hasNewIssues(NO_ISSUES); assertThat(details).hasOutstandingIssues(NO_ISSUES); }
@Test void shouldReturnAllIssues() { IssuesDetail details = createTrendDetails("all", RUN, createResult(), ALL_ISSUES, NEW_ISSUES, OUTSTANDING_ISSUES, FIXED_ISSUES, ENCODING, createParent(), IssuesDetail.class); assertThat(details).hasIssues(ALL_ISSUES); assertThat(details).hasFixedIssues(FIXED_ISSUES); assertThat(details).hasNewIssues(NEW_ISSUES); assertThat(details).hasOutstandingIssues(OUTSTANDING_ISSUES); }
@Test void shouldReturnLabelProviderNameOnOrigin() { JenkinsFacade jenkins = mock(JenkinsFacade.class); when(jenkins.getDescriptorsFor(Tool.class)).thenReturn( DescriptorExtensionList.createDescriptorList((Jenkins)null, Tool.class)); BuildFolderFacade buildFolder = mock(BuildFolderFacade.class); DetailFactory detailFactory = new DetailFactory(jenkins, buildFolder); Object details = detailFactory.createTrendDetails("origin." + TOOL_ID.hashCode(), RUN, createResult(), ALL_ISSUES, NEW_ISSUES, OUTSTANDING_ISSUES, FIXED_ISSUES, ENCODING, createParent()); assertThat(details).isInstanceOfSatisfying(IssuesDetail.class, d -> assertThat(d.getDisplayName()).isEqualTo("Static Analysis")); }
@Test void shouldReturnIssuesDetailWithNewIssuesWhenCalledWithNewLink() { IssuesDetail details = createTrendDetails("new", RUN, createResult(), ALL_ISSUES, NEW_ISSUES, OUTSTANDING_ISSUES, FIXED_ISSUES, ENCODING, createParent(), IssuesDetail.class); assertThat(details).hasIssues(NEW_ISSUES); assertThat(details).hasFixedIssues(NO_ISSUES); assertThat(details).hasNewIssues(NEW_ISSUES); assertThat(details).hasOutstandingIssues(NO_ISSUES); }
@Test void shouldReturnIssuesDetailWithOutstandingIssuesWhenCalledWithOutstandingLink() { IssuesDetail details = createTrendDetails("outstanding", RUN, createResult(), ALL_ISSUES, NEW_ISSUES, OUTSTANDING_ISSUES, FIXED_ISSUES, ENCODING, createParent(), IssuesDetail.class); assertThat(details).hasIssues(OUTSTANDING_ISSUES); assertThat(details).hasFixedIssues(NO_ISSUES); assertThat(details).hasNewIssues(NO_ISSUES); assertThat(details).hasOutstandingIssues(OUTSTANDING_ISSUES); }
@Test void shouldReturnPriorityDetailWithHighPriorityIssuesWhenCalledWithHighLink() { IssuesDetail details = createTrendDetails("HIGH", RUN, createResult(), ALL_ISSUES, NEW_ISSUES, OUTSTANDING_ISSUES, FIXED_ISSUES, ENCODING, createParent(), IssuesDetail.class); assertThatPrioritiesAreFiltered(details, Severity.WARNING_HIGH); assertThatPrioritiesAreCorrectlySet(details, 3, 0, 0); }
@Test void shouldReturnPriorityDetailWithNormalPriorityIssuesWhenCalledWithNormalLink() { IssuesDetail details = createTrendDetails("NORMAL", RUN, createResult(), ALL_ISSUES, NEW_ISSUES, OUTSTANDING_ISSUES, FIXED_ISSUES, ENCODING, createParent(), IssuesDetail.class); assertThatPrioritiesAreFiltered(details, Severity.WARNING_NORMAL); assertThatPrioritiesAreCorrectlySet(details, 0, 2, 0); }
@Test void shouldReturnPriorityDetailWithLowPriorityIssuesWhenCalledWithLowLink() { IssuesDetail details = createTrendDetails("LOW", RUN, createResult(), ALL_ISSUES, NEW_ISSUES, OUTSTANDING_ISSUES, FIXED_ISSUES, ENCODING, createParent(), IssuesDetail.class); assertThatPrioritiesAreFiltered(details, Severity.WARNING_LOW); assertThatPrioritiesAreCorrectlySet(details, 0, 0, 1); }
@Test void shouldReturnInfoErrorDetailWhenCalledWithInfoLink() { InfoErrorDetail details = createTrendDetails("info", RUN, createResult(), ALL_ISSUES, NEW_ISSUES, OUTSTANDING_ISSUES, FIXED_ISSUES, ENCODING, createParent(), InfoErrorDetail.class); assertThat(details.getErrorMessages()).containsExactly(ERROR_MESSAGES); assertThat(details.getDisplayName()).contains(PARENT_NAME); }
@Test void shouldCreateConsoleDetailForSourceLinksIfFileNameIsSelf() { JenkinsFacade jenkins = mock(JenkinsFacade.class); BuildFolderFacade buildFolder = mock(BuildFolderFacade.class); when(buildFolder.readConsoleLog(any())).thenReturn(createLines()); DetailFactory detailFactory = new DetailFactory(jenkins, buildFolder); Report report = new Report(); IssueBuilder issueBuilder = new IssueBuilder(); issueBuilder.setFileName(ConsoleLogHandler.JENKINS_CONSOLE_LOG_FILE_NAME_ID); Issue issue = issueBuilder.build(); report.add(issue); Object details = detailFactory.createTrendDetails("source." + issue.getId().toString(), RUN, createResult(), report, NEW_ISSUES, OUTSTANDING_ISSUES, FIXED_ISSUES, ENCODING, createParent()); assertThat(details).isInstanceOf(ConsoleDetail.class); assertThat(((ConsoleDetail) details).getSourceCode()).contains(AFFECTED_FILE_CONTENT); }
@Test void shouldShowExceptionMessageIfAffectedFileIsNotReadable() throws IOException { JenkinsFacade jenkins = mock(JenkinsFacade.class); BuildFolderFacade buildFolder = mock(BuildFolderFacade.class); when(buildFolder.readFile(any(), anyString(), any())).thenThrow(new IOException("file error")); DetailFactory detailFactory = new DetailFactory(jenkins, buildFolder); Report report = new Report(); IssueBuilder issueBuilder = new IssueBuilder(); issueBuilder.setFileName("a-file"); Issue issue = issueBuilder.build(); report.add(issue); Object details = detailFactory.createTrendDetails("source." + issue.getId().toString(), RUN, createResult(), report, NEW_ISSUES, OUTSTANDING_ISSUES, FIXED_ISSUES, ENCODING, createParent()); assertThat(details).isInstanceOf(SourceDetail.class); assertThat(((SourceDetail) details).getSourceCode()).contains("IOException: file error"); }
@Test void shouldReturnSourceDetailWhenCalledWithSourceLinkAndIssueNotInConsoleLog() throws IOException { JenkinsFacade jenkins = mock(JenkinsFacade.class); BuildFolderFacade buildFolder = mock(BuildFolderFacade.class); when(buildFolder.readFile(any(), anyString(), any())).thenReturn(new StringReader(AFFECTED_FILE_CONTENT)); DetailFactory detailFactory = new DetailFactory(jenkins, buildFolder); Report report = new Report(); IssueBuilder issueBuilder = new IssueBuilder(); issueBuilder.setFileName("a-file"); Issue issue = issueBuilder.build(); report.add(issue); Object details = detailFactory.createTrendDetails("source." + issue.getId().toString(), RUN, createResult(), report, NEW_ISSUES, OUTSTANDING_ISSUES, FIXED_ISSUES, ENCODING, createParent()); assertThat(details).isInstanceOf(SourceDetail.class); assertThat(((SourceDetail) details).getSourceCode()).contains(AFFECTED_FILE_CONTENT); }
@SuppressWarnings("unchecked") @Test void shouldReturnIssueDetailFiltered() { DetailFactory detailFactory = new DetailFactory(); AnalysisResult result = mock(AnalysisResult.class); Object details = detailFactory.createTrendDetails("category." + "CATEGORY2".hashCode(), RUN, result, ALL_ISSUES, NEW_ISSUES, OUTSTANDING_ISSUES, FIXED_ISSUES, ENCODING, createParent()); assertThat(details).isInstanceOf(IssuesDetail.class); Report filtered = ((IssuesDetail) details).getIssues(); assertThat(filtered).hasSize(1); assertThat(filtered.get(0)).hasCategory("CATEGORY2").hasSeverity(Severity.WARNING_HIGH); }