Skip to content

Commit

Permalink
Fix broken default configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Feb 26, 2025
1 parent 8adf12e commit 3b82bf1
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* @author Tobias Effner
* @author Ullrich Hafner
*/
// FIXME: This class is not used and can be removed?
public class CodeCoverageMarkdown extends CoverageMarkdown {
static final String TYPE = "Code Coverage Score";

Expand Down
37 changes: 28 additions & 9 deletions src/main/java/edu/hm/hafner/grading/GradingReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.commons.lang3.exception.ExceptionUtils;

import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -80,7 +81,8 @@ public String getMarkdownSummary(final AggregatedScore score, final String title
* @param title
* the title of the summary
* @param showHeaders
* determines whether headers should be shown for the subsections or not
* determines whether headers should be shown for the subsections or not
*
* @return Markdown text
*/
public String getMarkdownSummary(final AggregatedScore score, final String title, final boolean showHeaders) {
Expand Down Expand Up @@ -115,23 +117,39 @@ public StringBuilder getSubScoreDetails(final AggregatedScore score) {
* @param score
* the aggregated score
* @param showHeaders
* determines whether headers should be shown for the subsections or not
* determines whether headers should be shown for the subsections or not
*
* @return Markdown text
*/
public StringBuilder getSubScoreDetails(final AggregatedScore score, final boolean showHeaders) {
var summary = new StringBuilder();

summary.append(createPercentage(score))
.append(TEST_MARKDOWN.createSummary(score, showHeaders))
.append(CODE_COVERAGE_MARKDOWN.createSummary(score, showHeaders))
.append(MUTATION_COVERAGE_MARKDOWN.createSummary(score, showHeaders))
.append(ANALYSIS_MARKDOWN.createSummary(score, showHeaders))
.append(METRIC_MARKDOWN.createSummary(score, showHeaders));
summary.append(createPercentage(score));
summary.append(joinSummaries(score, showHeaders));

return summary;
}

private String joinSummaries(final AggregatedScore score, final boolean showHeaders) {
var joiner = new StringJoiner(showHeaders ? ScoreMarkdown.PARAGRAPH : ScoreMarkdown.LINE_BREAK_PARAGRAPH);

add(score, showHeaders, joiner, TEST_MARKDOWN);
add(score, showHeaders, joiner, CODE_COVERAGE_MARKDOWN);
add(score, showHeaders, joiner, MUTATION_COVERAGE_MARKDOWN);
add(score, showHeaders, joiner, ANALYSIS_MARKDOWN);
add(score, showHeaders, joiner, METRIC_MARKDOWN);

return joiner.toString();
}

private void add(final AggregatedScore score, final boolean showHeaders, final StringJoiner joiner,
final ScoreMarkdown<?, ?> markdown) {
var summary = markdown.createSummary(score, showHeaders);
if (!summary.isBlank()) {
joiner.add(summary);
}
}

/**
* Creates a detailed description of the grading results in Markdown.
*
Expand Down Expand Up @@ -166,7 +184,8 @@ public String getMarkdownDetails(final AggregatedScore score, final String title
* @param title
* the title of the details
* @param showDisabled
* determines whether disabled scores should be shown or skipped
* determines whether disabled scores should be shown or skipped
*
* @return Markdown text
*/
public String getMarkdownDetails(final AggregatedScore score, final String title, final boolean showDisabled) {
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/edu/hm/hafner/grading/ScoreMarkdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import edu.hm.hafner.grading.TruncatedString.TruncatedStringBuilder;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -42,6 +43,7 @@ abstract class ScoreMarkdown<S extends Score<S, C>, C extends Configuration> {
private static final String TRUNCATION_TEXT = "\n\nToo many test failures. Grading output truncated.\n\n";
private static final int HUNDRED_PERCENT = 100;

// FIXME: type is not used, Should we remove default name from score?
private final String type;
private final String icon;

Expand Down Expand Up @@ -166,15 +168,20 @@ public String createSummary(final AggregatedScore aggregation) {
* @return returns the summary in Markdown
*/
public String createSummary(final AggregatedScore aggregation, final boolean showHeaders) {
var summaries = new StringBuilder(1024);
var summaries = new ArrayList<String>();
for (S score : createScores(aggregation)) {
var builder = new StringBuilder();
if (showHeaders) {
summaries.append(getTitle(score, 3)).append(PARAGRAPH);
builder.append(getTitle(score, 3)).append(PARAGRAPH);
}
var subScores = createSummaryOfSubScores(score);
summaries.append(String.join(LINE_BREAK_PARAGRAPH, subScores));
builder.append(String.join(LINE_BREAK_PARAGRAPH, subScores));
summaries.add(builder.toString());
}
return summaries.toString();
if (showHeaders) {
return String.join(PARAGRAPH, summaries);
}
return String.join(LINE_BREAK_PARAGRAPH, summaries);
}

private List<String> createSummaryOfSubScores(final S score) {
Expand Down
21 changes: 10 additions & 11 deletions src/main/resources/default-config.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"tests": {
"name": "Tests",
"id": "tests",
"tools": [
{
"id": "test",
"name": "Tests",
"id": "junit",
"name": "JUnit Tests",
"pattern": "**/target/*-reports/TEST*.xml"
}
],
"passedImpact": 0,
"skippedImpact": -1,
"failureImpact": -5,
"failureRateImpact": -1,
"maxScore": 100
},
"analysis": [
Expand All @@ -20,12 +19,10 @@
"tools": [
{
"id": "checkstyle",
"name": "CheckStyle",
"pattern": "**/target/**checkstyle-result.xml"
},
{
"id": "pmd",
"name": "PMD",
"pattern": "**/target/**pmd.xml"
}
],
Expand All @@ -42,7 +39,6 @@
"tools": [
{
"id": "spotbugs",
"name": "SpotBugs",
"sourcePath": "src/main/java",
"pattern": "**/target/spotbugsXml.xml"
}
Expand All @@ -60,14 +56,12 @@
"tools": [
{
"id": "jacoco",
"name": "Line Coverage",
"metric": "line",
"sourcePath": "src/main/java",
"pattern": "**/target/site/jacoco/jacoco.xml"
},
{
"id": "jacoco",
"name": "Branch Coverage",
"metric": "branch",
"sourcePath": "src/main/java",
"pattern": "**/target/site/jacoco/jacoco.xml"
Expand All @@ -81,10 +75,15 @@
"tools": [
{
"id": "pit",
"name": "Mutation Coverage",
"metric": "mutation",
"sourcePath": "src/main/java",
"pattern": "**/target/pit-reports/mutations.xml"
},
{
"id": "pit",
"metric": "test-strength",
"sourcePath": "src/main/java",
"pattern": "**/target/pit-reports/mutations.xml"
}
],
"maxScore": 100,
Expand Down
21 changes: 12 additions & 9 deletions src/main/resources/default-no-score-config.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"tests": {
"name": "Tests",
"id": "tests",
"tools": [
{
"id": "test",
"name": "Tests",
"id": "junit",
"name": "JUnit Tests",
"pattern": "**/target/*-reports/TEST*.xml"
}
],
"name": "Tests"
]
},
"analysis": [
{
Expand All @@ -16,12 +17,10 @@
"tools": [
{
"id": "checkstyle",
"name": "CheckStyle",
"pattern": "**/target/**checkstyle-result.xml"
},
{
"id": "pmd",
"name": "PMD",
"pattern": "**/target/**pmd.xml"
}
]
Expand All @@ -33,7 +32,6 @@
"tools": [
{
"id": "spotbugs",
"name": "SpotBugs",
"sourcePath": "src/main/java",
"pattern": "**/target/spotbugsXml.xml"
}
Expand All @@ -46,14 +44,12 @@
"tools": [
{
"id": "jacoco",
"name": "Line Coverage",
"metric": "line",
"sourcePath": "src/main/java",
"pattern": "**/target/site/jacoco/jacoco.xml"
},
{
"id": "jacoco",
"name": "Branch Coverage",
"metric": "branch",
"sourcePath": "src/main/java",
"pattern": "**/target/site/jacoco/jacoco.xml"
Expand All @@ -69,6 +65,13 @@
"metric": "mutation",
"sourcePath": "src/main/java",
"pattern": "**/target/pit-reports/mutations.xml"
},
{
"id": "pit",
"name": "Test Strength",
"metric": "test-strength",
"sourcePath": "src/main/java",
"pattern": "**/target/pit-reports/mutations.xml"
}
]
}
Expand Down
38 changes: 21 additions & 17 deletions src/test/java/edu/hm/hafner/grading/AggregatedScoreTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package edu.hm.hafner.grading;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Objects;

import org.junit.jupiter.api.Test;

import com.google.errorprone.annotations.MustBeClosed;
Expand All @@ -26,6 +18,14 @@
import edu.hm.hafner.util.SerializableTest;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Objects;

import static edu.hm.hafner.grading.assertions.Assertions.*;

class AggregatedScoreTest extends SerializableTest<AggregatedScore> {
Expand Down Expand Up @@ -242,19 +242,22 @@ class AggregatedScoreTest extends SerializableTest<AggregatedScore> {
private static final String QUALITY_CONFIGURATION = """
{
"tests": [{
"name": "JUnit Tests",
"icon": "construction",
"tools": [
{
"id": "itest",
{
"icon": "vertical_traffic_light",
"id": "junit",
"name": "Integrationstests",
"pattern": "target/i-junit.xml"
},
{
"id": "mtest",
"icon": "vertical_traffic_light",
"id": "junit",
"name": "Modultests",
"pattern": "target/u-junit.xml"
}
],
"name": "JUnit"
]
}],
"analysis": [
{
Expand Down Expand Up @@ -283,6 +286,7 @@ class AggregatedScoreTest extends SerializableTest<AggregatedScore> {
],
"coverage": [
{
"name": "Code Coverage",
"tools": [
{
"id": "jacoco",
Expand All @@ -296,19 +300,19 @@ class AggregatedScoreTest extends SerializableTest<AggregatedScore> {
"metric": "branch",
"pattern": "target/jacoco.xml"
}
],
"name": "JaCoCo"
]
},
{
"name": "Mutation Coverage",
"icon": "microscope",
"tools": [
{
"id": "pit",
"name": "Mutation Coverage",
"metric": "mutation",
"pattern": "target/pit.xml"
}
],
"name": "PIT"
]
}
]
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/edu/hm/hafner/grading/GradingReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ void shouldCreateAllGradingResults() {
"Cognitive Complexity: 100",
"N-Path Complexity: <n/a>",
"Non Commenting Source Statements: <n/a>");
assertThat(results.getMarkdownSummary(score, "Summary"))
.isEqualTo("Strange");

assertThat(results.getTextSummary(score)).isEqualTo(
"Autograding score - 167 of 500 (33%)");
assertThat(results.getMarkdownDetails(score)).contains(
Expand All @@ -157,6 +160,12 @@ void shouldCreateAllQualityResults() {
var results = new GradingReport();

var score = AggregatedScoreTest.createQualityAggregation();

assertThat(results.getMarkdownSummary(score, "Summary", true))
.contains("JUnit Tests", "Code Coverage", "Mutation Coverage", "Style");
assertThat(results.getMarkdownSummary(score, "Summary"))
.doesNotContain("JUnit Tests", "Code Coverage", "Style");

assertThat(results.getMarkdownSummary(score, "Summary")).contains(
"Integrationstests: 42% successful", "4 failed", "5 passed", "3 skipped",
"Modultests: 0% successful", "10 failed",
Expand Down

0 comments on commit 3b82bf1

Please sign in to comment.