Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Nov 16, 2023
1 parent aac84dd commit fd623ff
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CodeDeltaCalculator {
"Unexpected behavior detected when comparing coverage data with the code delta "
+ "- there are ambiguous paths when comparing new with former file paths: ";

static final String EMPTY_OLD_PATHS_WARNING = "File renamings have been detected for files which have not been "
static final String EMPTY_OLD_PATHS_WARNING = "File renaming has been detected for files which have not been "
+ "part of the reference coverage report. These files are skipped when calculating the coverage deltas:";

private final Run<?, ?> build;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import io.jenkins.plugins.util.AbstractXmlStream;
import io.jenkins.plugins.util.BuildAction;
import io.jenkins.plugins.util.JenkinsFacade;
import io.jenkins.plugins.util.JobAction;
import io.jenkins.plugins.util.QualityGateResult;

import static hudson.model.Run.*;
Expand Down Expand Up @@ -601,7 +602,7 @@ protected AbstractXmlStream<Node> createXmlStream() {
}

@Override
protected CoverageJobAction createProjectAction() {
protected JobAction<? extends BuildAction<Node>> createProjectAction() {
return new CoverageJobAction(getOwner().getParent(), getUrlName(), name, icon);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@ private List<Baseline> getBaselines() {
}

private String getOverallCoverageSummary() {
if (rootNode.hasModifiedLines()) {
return createDeltaBaselinesOverview();
}
else {
return createProjectOverview();
}
}

private String createDeltaBaselinesOverview() {
StringBuilder description = new StringBuilder(getSectionHeader(TITLE_HEADER_LEVEL, "Overview by baseline"));

for (Baseline baseline : getBaselines()) {
Expand All @@ -375,6 +384,18 @@ private String getOverallCoverageSummary() {
return description.toString();
}

private String createProjectOverview() {
StringBuilder description = new StringBuilder(getSectionHeader(TITLE_HEADER_LEVEL, "Project Overview")
+ "No changes detected, that affect the code coverage.\n");

for (Value value : action.getValues(Baseline.PROJECT)) {
description.append(getBulletListItem(1, FORMATTER.formatDetailedValueWithMetric(value)));
}

description.append(NEW_LINE);
return description.toString();
}

/**
* Checks overview regarding the quality gate status.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@ void shouldShowQualityGateDetails() {
ChecksAnnotationScope.SKIP, createJenkins());

var checkDetails = publisher.extractChecksDetails();
var expectedSummary = toString("coverage-publisher-quality-gate.checks-expected-result");

var expectedQualityGateSummary = toString("coverage-publisher-quality-gate.checks-expected-result");
assertThat(checkDetails.getOutput()).isPresent().get().satisfies(output -> {
assertThat(output.getSummary()).isPresent()
.get()
.asString()
.containsIgnoringWhitespaces(expectedQualityGateSummary);
});

var expectedOverview = toString("coverage-publisher-overview.checks-expected-result");
assertThat(checkDetails.getOutput()).isPresent().get().satisfies(output -> {
assertThat(output.getSummary()).isPresent()
.get()
.asString()
.containsIgnoringWhitespaces(expectedSummary);
.containsIgnoringWhitespaces(expectedOverview);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ void shouldPassForTooLowThresholds() {
"-> [Overall project (difference to reference job) - Line Coverage]: ≪Success≫ - (Actual value: +5.00%, Quality gate: -10.00)",
"-> [Modified code lines (difference to modified files) - File Coverage]: ≪Success≫ - (Actual value: -10.00%, Quality gate: -10.00)",
"-> [Modified code lines (difference to modified files) - Line Coverage]: ≪Success≫ - (Actual value: +5.00%, Quality gate: -10.00)",
"-> [Modified files (difference to overall project) - File Coverage]: ≪Success≫ - (Actual value: -10.00%, Quality gate: -10.00)",
"-> [Modified files (difference to overall project) - Line Coverage]: ≪Success≫ - (Actual value: +5.00%, Quality gate: -10.00)");
"-> [Modified files (difference to reference job) - File Coverage]: ≪Success≫ - (Actual value: -10.00%, Quality gate: -10.00)",
"-> [Modified files (difference to reference job) - Line Coverage]: ≪Success≫ - (Actual value: +5.00%, Quality gate: -10.00)");
}

@Test
Expand All @@ -89,7 +89,7 @@ void shouldSkipIfValueNotDefined() {
"-> [Modified files - File Coverage]: ≪Not built≫ - (Actual value: n/a, Quality gate: 0.00)",
"-> [Overall project (difference to reference job) - Line Coverage]: ≪Not built≫ - (Actual value: n/a, Quality gate: 0.00)",
"-> [Modified code lines (difference to modified files) - File Coverage]: ≪Not built≫ - (Actual value: n/a, Quality gate: 0.00)",
"-> [Modified files (difference to overall project) - Line Coverage]: ≪Not built≫ - (Actual value: n/a, Quality gate: 0.00)");
"-> [Modified files (difference to reference job) - Line Coverage]: ≪Not built≫ - (Actual value: n/a, Quality gate: 0.00)");
}

@Test
Expand Down Expand Up @@ -135,8 +135,8 @@ void shouldReportUnstableIfWorseAndSuccessIfBetter() {
"-> [Overall project (difference to reference job) - Line Coverage]: ≪Success≫ - (Actual value: +5.00%, Quality gate: 0.00)",
"-> [Modified code lines (difference to modified files) - File Coverage]: ≪Unstable≫ - (Actual value: -10.00%, Quality gate: 0.00)",
"-> [Modified code lines (difference to modified files) - Line Coverage]: ≪Success≫ - (Actual value: +5.00%, Quality gate: 0.00)",
"-> [Modified files (difference to overall project) - File Coverage]: ≪Unstable≫ - (Actual value: -10.00%, Quality gate: 0.00)",
"-> [Modified files (difference to overall project) - Line Coverage]: ≪Success≫ - (Actual value: +5.00%, Quality gate: 0.00)");
"-> [Modified files (difference to reference job) - File Coverage]: ≪Unstable≫ - (Actual value: -10.00%, Quality gate: 0.00)",
"-> [Modified files (difference to reference job) - Line Coverage]: ≪Success≫ - (Actual value: +5.00%, Quality gate: 0.00)");
}

@ParameterizedTest(name = "A quality gate of {0} should not be passed if the coverage drops by 10%")
Expand Down Expand Up @@ -232,8 +232,8 @@ void shouldReportFailureIfBelowThreshold() {
"-> [Overall project (difference to reference job) - Line Coverage]: ≪Failed≫ - (Actual value: +5.00%, Quality gate: 10.00)",
"-> [Modified code lines (difference to modified files) - File Coverage]: ≪Failed≫ - (Actual value: -10.00%, Quality gate: 10.00)",
"-> [Modified code lines (difference to modified files) - Line Coverage]: ≪Failed≫ - (Actual value: +5.00%, Quality gate: 10.00)",
"-> [Modified files (difference to overall project) - File Coverage]: ≪Failed≫ - (Actual value: -10.00%, Quality gate: 10.00)",
"-> [Modified files (difference to overall project) - Line Coverage]: ≪Failed≫ - (Actual value: +5.00%, Quality gate: 10.00)");
"-> [Modified files (difference to reference job) - File Coverage]: ≪Failed≫ - (Actual value: -10.00%, Quality gate: 10.00)",
"-> [Modified files (difference to reference job) - Line Coverage]: ≪Failed≫ - (Actual value: +5.00%, Quality gate: 10.00)");
}

static QualityGateResult createQualityGateResult() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,6 @@ void shouldSaveAndRestoreTree() {
Assertions.assertThat(restored).usingRecursiveComparison().isEqualTo(convertedNode);

var xml = Input.from(saved);
assertThat(xml).nodesByXPath("//module/values/*")
.hasSize(4).extractingText()
.containsExactly("INSTRUCTION: 1260/1350",
"BRANCH: 109/116",
"LINE: 294/323",
"COMPLEXITY: 160");
assertThat(xml).nodesByXPath("//module/values/*")
.hasSize(4).extractingText()
.containsExactly("INSTRUCTION: 1260/1350",
"BRANCH: 109/116",
"LINE: 294/323",
"COMPLEXITY: 160");
assertThat(xml).nodesByXPath("//file[./name = 'TreeStringBuilder.java']/values/*")
.hasSize(4).extractingText()
.containsExactly("INSTRUCTION: 229/233", "BRANCH: 17/18", "LINE: 51/53", "COMPLEXITY: 23");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:feet: **Overall project**|100.00% (1/1)|100.00% (4/4)|70.00% (7/10)|83.33% (15/18)|95.10% (97/102)|91.02% (294/323)|93.97% (109/116)|93.33% (1260/1350)
:chart_with_upwards_trend: **Overall project (difference to reference job)**|+0.00%|-50.00% :arrow_down:|n/a|n/a|n/a|+50.00% :arrow_up:|n/a|n/a
:feet: **Modified files**|n/a|n/a|n/a|n/a|n/a|50.00% (1/2)|n/a|n/a
:chart_with_upwards_trend: **Modified files (difference to overall project)**|n/a|n/a|n/a|n/a|n/a|+50.00% :arrow_up:|n/a|n/a
:chart_with_upwards_trend: **Modified files (difference to reference job)**|n/a|n/a|n/a|n/a|n/a|+50.00% :arrow_up:|n/a|n/a
:feet: **Modified code lines**|n/a|n/a|n/a|n/a|n/a|50.00% (1/2)|n/a|n/a
:chart_with_upwards_trend: **Modified code lines (difference to modified files)**|n/a|n/a|n/a|n/a|n/a|+50.00% :arrow_up:|n/a|n/a
:feet: **Indirect changes**|n/a|n/a|n/a|n/a|n/a|50.00% (1/2)|n/a|n/a
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#### Project Overview

No changes detected, that affect the code coverage.
* Line Coverage: 91.02% (294/323)
* Branch Coverage: 93.97% (109/116)
* Complexity Density: 0.50%
* Lines of Code: 323
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ Overall result: Failed
- Overall project (difference to reference job) - Line Coverage: ≪Failed≫ - (Actual value: +5.00%, Quality gate: 10.00)
- Modified code lines (difference to modified files) - File Coverage: ≪Failed≫ - (Actual value: -10.00%, Quality gate: 10.00)
- Modified code lines (difference to modified files) - Line Coverage: ≪Failed≫ - (Actual value: +5.00%, Quality gate: 10.00)
- Modified files (difference to overall project) - File Coverage: ≪Failed≫ - (Actual value: -10.00%, Quality gate: 10.00)
- Modified files (difference to overall project) - Line Coverage: ≪Failed≫ - (Actual value: +5.00%, Quality gate: 10.00)
- Modified files (difference to reference job) - File Coverage: ≪Failed≫ - (Actual value: -10.00%, Quality gate: 10.00)
- Modified files (difference to reference job) - Line Coverage: ≪Failed≫ - (Actual value: +5.00%, Quality gate: 10.00)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Branch Coverage: 93.97% (109/116)
* Complexity Density: 0.50%
* Lines of Code: 323
* **[Modified files (difference to overall project)](http://127.0.0.1:8080/job/pipeline-coding-style/job/5/coverage#modifiedFilesCoverage)**
* **[Modified files (difference to reference job)](http://127.0.0.1:8080/job/pipeline-coding-style/job/5/coverage#modifiedFilesCoverage)**
* Line Coverage: 50.00% (1/2) - Delta: +50.00%
* **[Modified code lines (difference to modified files)](http://127.0.0.1:8080/job/pipeline-coding-style/job/5/coverage#modifiedLinesCoverage)**
* Line Coverage: 50.00% (1/2) - Delta: +50.00%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Line Coverage: 93.84% (198/211) - Delta: +50.00%
* Mutation Coverage: 90.24% (222/246)
* Lines of Code: 211
* **[Modified files (difference to overall project)](http://127.0.0.1:8080/job/pipeline-coding-style/job/5/coverage#modifiedFilesCoverage)**
* **[Modified files (difference to reference job)](http://127.0.0.1:8080/job/pipeline-coding-style/job/5/coverage#modifiedFilesCoverage)**
* Line Coverage: 50.00% (1/2) - Delta: +50.00%
* **[Modified code lines (difference to modified files)](http://127.0.0.1:8080/job/pipeline-coding-style/job/5/coverage#modifiedLinesCoverage)**
* Line Coverage: 50.00% (1/2) - Delta: +50.00%
Expand Down

0 comments on commit fd623ff

Please sign in to comment.