Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Revert "Use new delta values for branch coverage in checks title."
Browse files Browse the repository at this point in the history
This reverts commit 5a27390
  • Loading branch information
uhafner committed May 25, 2021
1 parent 5a27390 commit f52a516
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ private String extractChecksTitle(final CoverageResult result) {

if (result.getCoverage(CoverageElement.CONDITIONAL) != null) {
float branchCoverage = result.getCoverage(CoverageElement.CONDITIONAL).getPercentageFloat();
if (result.getReferenceBuildUrl() != null) {
title.append(extractChecksTitle("Branch", "target branch", branchCoverage,
result.getCoverageDelta(CoverageElement.CONDITIONAL)));
} else if (lastRatios.containsKey(CoverageElement.CONDITIONAL)) {
if (lastRatios.containsKey(CoverageElement.CONDITIONAL)) {
title.append(extractChecksTitle("Branch", "last successful build", branchCoverage,
branchCoverage - lastRatios.get(CoverageElement.CONDITIONAL).getPercentageFloat()));
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package io.jenkins.plugins.coverage;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;

import org.junit.BeforeClass;
import org.junit.Test;

import org.jvnet.localizer.Localizable;
Expand Down Expand Up @@ -33,11 +31,6 @@ public class CoverageChecksPublisherTest {
private static final String LAST_SUCCESSFUL_BUILD_LINK = "http://127.0.0.1:8080/job/pipeline-coding-style/view/change-requests/job/PR-3/110/";
private static final String HEALTH_REPORT = "Coverage Healthy score is 100%";

@BeforeClass
public static void enforceEnglishLocale() {
Locale.setDefault(Locale.ENGLISH);
}

@Test
public void shouldConstructChecksDetailsWithLineAndMethodCoverage() {
ChecksDetails expectedDetails = new ChecksDetailsBuilder()
Expand Down Expand Up @@ -79,7 +72,7 @@ public void shouldConstructChecksDetailsWithIncreasedLineCoverageAndConditionalC
.withDetailsURL(JENKINS_BASE_URL + "/" + BUILD_LINK + COVERAGE_URL_NAME)
.withOutput(new ChecksOutputBuilder()
.withTitle("Line: 50.00% (+10.00% against target branch). " +
"Branch: 50.00% (+15.00% against target branch).")
"Branch: 50.00% (+20.00% against last successful build).")
.withSummary("* ### [Target branch build](" + JENKINS_BASE_URL + "/" + TARGET_BUILD_LINK + ")\n"
+ "* ### [Last successful build](" + JENKINS_BASE_URL + "/" + LAST_SUCCESSFUL_BUILD_LINK + ")\n"
+ "## " + HEALTH_REPORT + ".")
Expand All @@ -92,8 +85,7 @@ public void shouldConstructChecksDetailsWithIncreasedLineCoverageAndConditionalC
.build())
.build();

CoverageResult result = createCoverageResult((float)0.4, (float)0.3, (float)0.5, (float)0.5, TARGET_BUILD_LINK,
+10, +15);
CoverageResult result = createCoverageResult((float)0.4, (float)0.3, (float)0.5, (float)0.5, TARGET_BUILD_LINK, +10);
CoverageAction action = new CoverageAction(result);

Localizable localizable = mock(Localizable.class);
Expand All @@ -115,11 +107,11 @@ public void shouldConstructChecksDetailsWithDecreasedLineCoverageAndConditionalC
.withDetailsURL(JENKINS_BASE_URL + "/job/pipeline-coding-style/job/PR-3/49/coverage")
.withOutput(new ChecksOutputBuilder()
.withTitle("Line: 50.00% (-10.00% against target branch). " +
"Branch: 50.00% (-15.00% against target branch).")
"Branch: 50.00% (-20.00% against last successful build).")
.withSummary("* ### [Target branch build](" + JENKINS_BASE_URL + "/" + TARGET_BUILD_LINK + ")\n"
+ "* ### [Last successful build](" + JENKINS_BASE_URL + "/" + LAST_SUCCESSFUL_BUILD_LINK + ")\n"
+ "## " + HEALTH_REPORT + ".")
.withText("## Conditional\n* :white_check_mark: Coverage: 50%\n* :arrow_down: Trend: 15%\n"
.withText("## Conditional\n* :white_check_mark: Coverage: 50%\n* :arrow_down: Trend: 20%\n"
+ "## Line\n* :white_check_mark: Coverage: 50%\n* :arrow_down: Trend: 10%\n")
.withText("||Conditional|Line|\n" +
"|:-:|:-:|:-:|\n" +
Expand All @@ -128,8 +120,7 @@ public void shouldConstructChecksDetailsWithDecreasedLineCoverageAndConditionalC
.build())
.build();

CoverageResult result = createCoverageResult((float)0.6, (float)0.7, (float)0.5, (float)0.5, TARGET_BUILD_LINK,
-10, -15);
CoverageResult result = createCoverageResult((float)0.6, (float)0.7, (float)0.5, (float)0.5, TARGET_BUILD_LINK, -10);
CoverageAction action = new CoverageAction(result);

Localizable localizable = mock(Localizable.class);
Expand All @@ -151,7 +142,7 @@ public void shouldConstructChecksDetailsWithUnchangedLineAndConditionalCoverage(
.withDetailsURL(JENKINS_BASE_URL + "/job/pipeline-coding-style/job/PR-3/49/coverage")
.withOutput(new ChecksOutputBuilder()
.withTitle("Line: 60.00% (+0.00% against target branch). " +
"Branch: 40.00% (+0.00% against target branch).")
"Branch: 40.00% (+0.00% against last successful build).")
.withSummary("* ### [Target branch build](" + JENKINS_BASE_URL + "/" + TARGET_BUILD_LINK + ")\n"
+ "* ### [Last successful build](" + JENKINS_BASE_URL + "/" + LAST_SUCCESSFUL_BUILD_LINK + ")\n"
+ "## " + HEALTH_REPORT + ".")
Expand All @@ -162,8 +153,7 @@ public void shouldConstructChecksDetailsWithUnchangedLineAndConditionalCoverage(
.build())
.build();

CoverageResult result = createCoverageResult((float)0.6, (float)0.4, (float)0.6, (float)0.4, TARGET_BUILD_LINK, 0,
0);
CoverageResult result = createCoverageResult((float)0.6, (float)0.4, (float)0.6, (float)0.4, TARGET_BUILD_LINK, 0);
CoverageAction action = new CoverageAction(result);

Localizable localizable = mock(Localizable.class);
Expand Down Expand Up @@ -197,7 +187,7 @@ public void shouldUseLastSuccessfulBuildForLineCoverageIfNoTargetBranchIsCompare
.build())
.build();

CoverageResult result = createCoverageResult((float)0.5, (float)0.3, (float)0.6, (float)0.4, null, 0, -10);
CoverageResult result = createCoverageResult((float)0.5, (float)0.3, (float)0.6, (float)0.4, null, 0);
CoverageAction action = new CoverageAction(result);

Localizable localizable = mock(Localizable.class);
Expand Down Expand Up @@ -277,17 +267,16 @@ public void shouldReportNoLineOrBranchCoverageInChecksTitle() {
}

private CoverageResult createCoverageResult(final float lastLineCoverage, final float lastConditionCoverage,
final float lineCoverage, final float conditionCoverage,
final String targetBuildLink, final float targetLineDiff, final float targetBranchDiff) {
final float lineCoverage, final float conditionCoverage,
final String targetBuildLink, final float targetBuildDiff) {
Run build = mock(Run.class);
Run lastBuild = mock(Run.class);
CoverageResult lastResult = createCoverageResult(lastLineCoverage, lastConditionCoverage);
CoverageResult result = createCoverageResult(lineCoverage, conditionCoverage);

when(result.getPreviousResult()).thenReturn(lastResult);
when(result.getReferenceBuildUrl()).thenReturn(targetBuildLink);
when(result.getCoverageDelta(CoverageElement.LINE)).thenReturn(targetLineDiff);
when(result.getCoverageDelta(CoverageElement.CONDITIONAL)).thenReturn(targetBranchDiff);
when(result.getCoverageDelta(CoverageElement.LINE)).thenReturn(targetBuildDiff);
when(result.getOwner()).thenReturn(build);
when(build.getUrl()).thenReturn(BUILD_LINK);
when(build.getPreviousSuccessfulBuild()).thenReturn(lastBuild);
Expand Down

0 comments on commit f52a516

Please sign in to comment.