Skip to content

Commit

Permalink
Remove conditional default name from coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Oct 15, 2024
1 parent 8a76ce5 commit d962e65
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/main/java/edu/hm/hafner/grading/CoverageConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public final class CoverageConfiguration extends Configuration {

private static final String COVERAGE_ID = "coverage";
private static final String[] MUTATION_IDS = {"pitest", "mutation", "pit"};
static final String CODE_COVERAGE = "Code Coverage";

/**
* Converts the specified JSON object to a list of {@link CoverageConfiguration} instances.
Expand All @@ -36,10 +37,10 @@ public static List<CoverageConfiguration> from(final String json) {
return extractConfigurations(json, COVERAGE_ID, CoverageConfiguration.class);
}

@SuppressWarnings("unused") // Json property
@SuppressWarnings("unused") // JSON property
private int coveredPercentageImpact;

@SuppressWarnings("unused") // Json property
@SuppressWarnings("unused") // JSON property
private int missedPercentageImpact;

private CoverageConfiguration() {
Expand All @@ -53,10 +54,7 @@ protected String getDefaultId() {

@Override
protected String getDefaultName() {
if (StringUtils.containsAnyIgnoreCase(getId(), MUTATION_IDS)) {
return "Mutation Coverage";
}
return "Code Coverage";
return CODE_COVERAGE;
}

@Override
Expand Down
50 changes: 50 additions & 0 deletions src/test/java/edu/hm/hafner/grading/CoverageConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ void shouldConvertObjectConfigurationFromJson() {
.hasMaxScore(50)
.hasName("JaCoCo and PIT")
.isPositive()
.hasImpact()
.hasOnlyTools(new ToolConfiguration("jacoco", "", "target/jacoco.xml", "", getMetricName(Metric.LINE)),
new ToolConfiguration("pit", "", "target/pit.xml", "", getMetricName(Metric.MUTATION))));
}
Expand Down Expand Up @@ -209,6 +210,7 @@ private void verifyFirstConfiguration(final CoverageConfiguration configuration)
.hasMissedPercentageImpact(2)
.hasMaxScore(50)
.isPositive()
.hasImpact()
.hasOnlyTools(new ToolConfiguration("jacoco", "", "target/jacoco.xml", "", getMetricName(Metric.LINE)),
new ToolConfiguration("pit", "", "target/pit.xml", "", getMetricName(Metric.MUTATION)));
}
Expand All @@ -223,10 +225,58 @@ private void verifyLastConfiguration(final CoverageConfiguration configuration)
.hasMissedPercentageImpact(-10)
.hasMaxScore(100)
.isNotPositive()
.hasImpact()
.hasOnlyTools(new ToolConfiguration("cobertura", "", "target/cobertura.xml",
"", getMetricName(Metric.BRANCH)));
}

@ParameterizedTest(name = "{index} => Positive configuration: {1}")
@MethodSource
@DisplayName("should identify positive configurations")
void shouldIdentifyPositiveValues(final String json, @SuppressWarnings("unused") final String displayName) {

Check notice

Code scanning / CodeQL

Useless parameter Note test

The parameter 'displayName' is never used.
var configurations = fromJson(json);

assertThat(configurations).hasSize(1).first().satisfies(configuration ->
assertThat(configuration).isNotPositive().hasName(CoverageConfiguration.CODE_COVERAGE));
}

public static Stream<Arguments> shouldIdentifyPositiveValues() {
return Stream.of(Arguments.of("""
{
"coverage":
{
"tools": [
{
"id": "jacoco",
"metric": "line"
}
],
"coveredPercentageImpact": 0,
"missedPercentageImpact": -1,
"maxScore": 50
}
}
""", "missed impact is negative"),
Arguments.of("""
{
"coverage":
{
"tools": [
{
"id": "jacoco",
"metric": "line",
"pattern": "target/jacoco.xml"
}
],
"coveredPercentageImpact": -1,
"missedPercentageImpact": 0,
"maxScore": 50
}
}
""", "covered impact is negative")
);
}

@Test
void shouldAdhereToEquals() {
EqualsVerifier.forClass(CoverageConfiguration.class)
Expand Down

0 comments on commit d962e65

Please sign in to comment.