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

Report a 100% coverage in case all set targets are met #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -44,18 +44,18 @@ public HealthReport getBuildHealth() {
ProjectCoverage projectCoverage = getResult();
Map<CoverageMetric, Integer> scores = healthyTarget.getRangeScores(unhealthyTarget, projectCoverage);
int minValue = 100;
CoverageMetric minKey = null;
CoverageMetric minKey = CoverageMetric.STATEMENT;
for (Map.Entry<CoverageMetric, Integer> e : scores.entrySet()) {
if (e.getValue() < minValue) {
minKey = e.getKey();
minValue = e.getValue();
}
}
if (minKey == null) {
return null;
}

Localizable description;
// we must set a default value here to make the compiler happy,
// but minKey cannot have a null value at this point
// (EnumMap does not allow null keys, and the minKey has a default value)
Localizable description = null;
switch (minKey) {
case METHOD:
description = Messages._CloverBuildAction_MethodCoverage(
Expand All @@ -77,8 +77,6 @@ public HealthReport getBuildHealth() {
this.healthyTarget.getStatementCoverage()).getPercentage(),
projectCoverage.getElementCoverage().toString());
break;
default:
return null;
}
return new HealthReport(minValue, description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import org.jenkinsci.plugins.cloverphp.results.AbstractClassMetrics;

import java.io.Serializable;
import java.util.EnumMap;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
import java.util.HashSet;

/**
Expand Down Expand Up @@ -65,14 +65,15 @@ public Set<CoverageMetric> getFailingMetrics(AbstractClassMetrics coverage) {

public Map<CoverageMetric, Integer> getRangeScores(CoverageTarget min, AbstractClassMetrics coverage) {
Integer j;
Map<CoverageMetric, Integer> result = new HashMap<CoverageMetric, Integer>();
Map<CoverageMetric, Integer> result = new EnumMap<CoverageMetric, Integer>(CoverageMetric.class);

j = calcRangeScore(methodCoverage, min.methodCoverage, coverage.getMethodCoverage().getPercentage());
result.put(CoverageMetric.METHOD, j);
j = calcRangeScore(statementCoverage, min.statementCoverage, coverage.getStatementCoverage().getPercentage());
result.put(CoverageMetric.STATEMENT, j);
j = calcRangeScore(elementCoverage, min.elementCoverage, coverage.getElementCoverage().getPercentage());
result.put(CoverageMetric.ELEMENT, j);

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,39 @@ public void testPreviousResult() {
assertNull(action.getPreviousResult());
}

@Test
public void testAllTargetsReached() {
// GIVEN a build with some coverage metrics
AbstractBuild<?, ?> build = mock(AbstractBuild.class);
String workspacePath = "/tmp/workpath";
ProjectCoverage prjCoverage = new ProjectCoverage();
CoverageTarget healthyTarget = new CoverageTarget();
CoverageTarget unhealthyTarget = new CoverageTarget();

prjCoverage.setCoveredelements(100);
prjCoverage.setElements(100);
healthyTarget.setElementCoverage(100);

prjCoverage.setCoveredstatements(100);
prjCoverage.setStatements(100);
healthyTarget.setStatementCoverage(100);

prjCoverage.setCoveredmethods(100);
prjCoverage.setMethods(100);
healthyTarget.setMethodCoverage(100);

CloverBuildAction action = new CloverBuildAction(build, workspacePath, prjCoverage, healthyTarget, unhealthyTarget);

// WHEN calculating the health report
HealthReport healthReport = action.getBuildHealth();

// IT shoud
assertNotNull(healthReport);
assertEquals(100, healthReport.getScore());

}


@Test
public void testHealthReportAmplification() {
// GIVEN a build with some coverage metrics
Expand Down