Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
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 @@ -6,11 +6,13 @@
import java.util.List;
import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.Optional;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.Fraction;

import edu.hm.hafner.coverage.Coverage;
Expand Down Expand Up @@ -97,32 +99,36 @@ ChecksDetails extractChecksDetails() {
}

private String getChecksTitle() {
Baseline baseline = selectBaseline();
return getMetricsForTitle().stream()
.filter(metric -> action.hasValue(baseline, metric))
.map(metric -> format(baseline, metric))
.map(this::format)
.flatMap(Optional::stream)
.collect(Collectors.joining(", ", "", "."));
}

private Optional<String> format(final Metric metric) {
var baseline = selectBaseline();
return action.getValueForMetric(baseline, metric)
.map(value -> formatValue(baseline, metric, value));

}

private Baseline selectBaseline() {
if (action.hasBaselineResult(Baseline.MODIFIED_LINES)) {
return Baseline.MODIFIED_LINES;
}
else {
return Baseline.PROJECT;
}
return Baseline.PROJECT;
}

private String format(final Baseline baseline, final Metric metric) {
String suffix;
private String formatValue(final Baseline baseline, final Metric metric, final Value value) {
return String.format("%s: %s%s",
FORMATTER.getDisplayName(metric), FORMATTER.format(value), getDeltaDetails(baseline, metric));
}

private String getDeltaDetails(final Baseline baseline, final Metric metric) {
if (action.hasDelta(baseline, metric)) {
suffix = String.format(" (%s)", action.formatDelta(baseline, metric));
return String.format(" (%s)", action.formatDelta(baseline, metric));
}
else {
suffix = "";
}
return String.format("%s: %s%s",
FORMATTER.getDisplayName(metric), action.formatValue(baseline, metric), suffix);
return StringUtils.EMPTY;
}

private NavigableSet<Metric> getMetricsForTitle() {
Expand All @@ -131,35 +137,34 @@ private NavigableSet<Metric> getMetricsForTitle() {
}

private String getSummary() {
var root = rootNode;
return getOverallCoverageSummary() + "\n\n"
+ getQualityGatesSummary() + "\n\n"
+ getProjectMetricsSummary(root);
+ getProjectMetricsSummary(rootNode);
}

private List<ChecksAnnotation> getAnnotations() {
if (annotationScope == ChecksAnnotationScope.SKIP) {
return List.of();
}

var tree = rootNode;
Node filtered;
if (annotationScope == ChecksAnnotationScope.ALL_LINES) {
filtered = tree;
}
else {
filtered = tree.filterByModifiedLines();
}

var annotations = new ArrayList<ChecksAnnotation>();
for (var fileNode : filtered.getAllFileNodes()) {
for (var fileNode : filterAnnotations().getAllFileNodes()) {
annotations.addAll(getMissingLines(fileNode));
annotations.addAll(getPartiallyCoveredLines(fileNode));
annotations.addAll(getSurvivedMutations(fileNode));
}
return annotations;
}

private Node filterAnnotations() {
if (annotationScope == ChecksAnnotationScope.ALL_LINES) {
return rootNode;
}
else {
return rootNode.filterByModifiedLines();
}
}

private Collection<? extends ChecksAnnotation> getMissingLines(final FileNode fileNode) {
var builder = createAnnotationBuilder(fileNode).withTitle("Not covered line");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void shouldShowProjectBaselineForJaCoCo() {
var publisher = new CoverageChecksPublisher(createActionWithoutDelta(result), result, REPORT_NAME,
ChecksAnnotationScope.SKIP, createJenkins());

assertThatTitleIs(publisher, "Line Coverage: 91.02% (294/323), Branch Coverage: 93.97% (109/116).");
assertThatTitleIs(publisher, "Line Coverage: 91.02%, Branch Coverage: 93.97%.");
}

@Test
Expand All @@ -58,7 +58,7 @@ void shouldShowProjectBaselineForPit() {
var publisher = new CoverageChecksPublisher(createActionWithoutDelta(result), result, REPORT_NAME,
ChecksAnnotationScope.SKIP, createJenkins());

assertThatTitleIs(publisher, "Line Coverage: 93.84% (198/211), Mutation Coverage: 90.24% (222/246).");
assertThatTitleIs(publisher, "Line Coverage: 93.84%, Mutation Coverage: 90.24%.");
}

private void assertThatTitleIs(final CoverageChecksPublisher publisher, final String expectedTitle) {
Expand Down Expand Up @@ -92,7 +92,7 @@ private void assertThatDetailsAreCorrect(final ChecksDetails checkDetails, final
assertThat(checkDetails.getOutput()).isPresent().get().satisfies(output -> {
assertThat(output.getTitle()).isPresent()
.get()
.isEqualTo("Line Coverage: 50.00% (1/2) (+50.00%).");
.isEqualTo("Line Coverage: 50.00% (+50.00%).");
assertThat(output.getText()).isEmpty();
assertChecksAnnotations(output, expectedAnnotations);
assertSummary(output);
Expand Down