Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#715: Handle duplication information not being present #943

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public String format(FormatterFactory formatterFactory) {
new Text(Optional.ofNullable(getNewDuplications())
.map(decimalFormat::format)
.map(i -> i + "% Duplicated Code")
.orElse("No duplication information") + " (" + decimalFormat.format(getDuplications()) + "% Estimated after merge)"))),
.orElse("No duplication information") + " (" + decimalFormat.format(Optional.ofNullable(getDuplications()).orElse(BigDecimal.ZERO)) + "% Estimated after merge)"))),
new Paragraph(new Text(String.format("**Project ID:** %s", getProjectKey()))),
new Paragraph(new Link(getDashboardUrl(), new Text("View in SonarQube"))));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void testCreateAnalysisSummary() {
.withVulnerabilityImageUrl("vulnerabilityImageUrl")
.build();

Formatter<Document> formatter = mock(Formatter.class);
Formatter<Document> formatter = mock();
doReturn("formatted content").when(formatter).format(any());
FormatterFactory formatterFactory = mock(FormatterFactory.class);
doReturn(formatter).when(formatterFactory).documentFormatter();
Expand Down Expand Up @@ -118,4 +118,82 @@ void testCreateAnalysisSummary() {

}


@Test
void shouldReturn0ForTotalDuplicationsWhereValueIsNull() {
AnalysisSummary underTest = AnalysisSummary.builder()
.withNewDuplications(BigDecimal.valueOf(199))
.withSummaryImageUrl("summaryImageUrl")
.withProjectKey("projectKey")
.withBugCount(911)
.withBugUrl("bugUrl")
.withBugImageUrl("bugImageUrl")
.withCodeSmellCount(1)
.withCoverage(BigDecimal.valueOf(303))
.withCodeSmellUrl("codeSmellUrl")
.withCodeSmellImageUrl("codeSmellImageUrl")
.withCoverageUrl("codeCoverageUrl")
.withCoverageImageUrl("codeCoverageImageUrl")
.withDashboardUrl("dashboardUrl")
.withDuplications(null)
.withDuplicationsUrl("duplicationsUrl")
.withDuplicationsImageUrl("duplicationsImageUrl")
.withFailedQualityGateConditions(java.util.List.of("issuea", "issueb", "issuec"))
.withNewCoverage(BigDecimal.valueOf(99))
.withSecurityHotspotCount(69)
.withStatusDescription("status description")
.withStatusImageUrl("statusImageUrl")
.withTotalIssueCount(666)
.withVulnerabilityCount(96)
.withVulnerabilityUrl("vulnerabilityUrl")
.withVulnerabilityImageUrl("vulnerabilityImageUrl")
.build();

Formatter<Document> formatter = mock();
doReturn("formatted content").when(formatter).format(any());
FormatterFactory formatterFactory = mock(FormatterFactory.class);
doReturn(formatter).when(formatterFactory).documentFormatter();

assertThat(underTest.format(formatterFactory)).isEqualTo("formatted content");

ArgumentCaptor<Document> documentArgumentCaptor = ArgumentCaptor.forClass(Document.class);
verify(formatter).format(documentArgumentCaptor.capture());

Document expectedDocument = new Document(new Paragraph(new Image("status description", "statusImageUrl")),
new List(List.Style.BULLET,
new ListItem(new Text("issuea")),
new ListItem(new Text("issueb")),
new ListItem(new Text("issuec"))),
new Heading(1, new Text("Analysis Details")),
new Heading(2, new Text("666 Issues")),
new List(List.Style.BULLET,
new ListItem(
new Link("bugUrl", new Image("Bug","bugImageUrl")),
new Text(" "),
new Text("911 Bugs")),
new ListItem(
new Link("vulnerabilityUrl", new Image("Vulnerability","vulnerabilityImageUrl")),
new Text(" "),
new Text("165 Vulnerabilities")),
new ListItem(
new Link("codeSmellUrl", new Image("Code Smell", "codeSmellImageUrl")),
new Text(" "),
new Text("1 Code Smell"))),
new Heading(2, new Text("Coverage and Duplications")),
new List(List.Style.BULLET,
new ListItem(
new Link("codeCoverageUrl", new Image("Coverage", "codeCoverageImageUrl")),
new Text(" "),
new Text("99.00% Coverage (303.00% Estimated after merge)")),
new ListItem(
new Link("duplicationsUrl", new Image("Duplications", "duplicationsImageUrl")),
new Text(" "),
new Text("199.00% Duplicated Code (0.00% Estimated after merge)"))),
new Paragraph(new Text("**Project ID:** projectKey")),
new Paragraph(new Link("dashboardUrl", new Text("View in SonarQube"))));

assertThat(documentArgumentCaptor.getValue()).usingRecursiveComparison().isEqualTo(expectedDocument);

}

}
Loading