Skip to content

Commit

Permalink
Fix some warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Mar 23, 2024
1 parent 8f54da1 commit d23ac7e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/main/java/edu/hm/hafner/grading/AggregatedScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @author Eva-Maria Zeintl
* @author Ullrich Hafner
*/
@SuppressWarnings({"PMD.GodClass", "PMD.CyclomaticComplexity", "PMD.ExcessivePublicCount"})
@SuppressWarnings({"PMD.GodClass", "PMD.CyclomaticComplexity", "PMD.ExcessivePublicCount", "PMD.CouplingBetweenObjects"})
public final class AggregatedScore implements Serializable {
@Serial
private static final long serialVersionUID = 3L;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/edu/hm/hafner/grading/AutoGradingRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
public class AutoGradingRunner {
private static final String SINGLE_LINE = "--------------------------------------------------------------------------------";
private static final String DOUBLE_LINE = "================================================================================";
private static final int ERROR_CAPACITY = 1024;

private final PrintStream outputStream;

/**
Expand Down Expand Up @@ -154,7 +156,7 @@ protected void publishError(final AggregatedScore score, final FilteredLog log,
*/
protected String createErrorMessageMarkdown(final FilteredLog log) {
if (log.hasErrors()) {
var errors = new StringBuilder();
var errors = new StringBuilder(ERROR_CAPACITY);

errors.append("## :construction: Error Messages\n```\n");
var messages = new StringJoiner("\n");
Expand Down Expand Up @@ -184,7 +186,7 @@ private String readDefaultConfiguration() {
var name = getDefaultConfigurationPath();
try (var defaultConfig = AutoGradingRunner.class.getResourceAsStream(name)) {
if (defaultConfig == null) {
throw new IOException("Can't find configuration in class path: " + name);
throw new IllegalStateException("Can't find configuration in class path: " + name);
}
return new String(defaultConfig.readAllBytes(), StandardCharsets.UTF_8);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public int getMissedPercentageImpact() {
* code coverage
*/
public boolean isMutationCoverage() {
return StringUtils.containsAnyIgnoreCase(getId() + getName(), CoverageConfiguration.MUTATION_IDS);
return StringUtils.containsAnyIgnoreCase(getId() + getName(), MUTATION_IDS);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/grading/CoverageMarkdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ protected void createSpecificDetails(final AggregatedScore aggregation, final Li

private String getImageForScoreOrCoverage(final CoverageScore score) {
if (score.hasMaxScore()) { // show the score percentage
return ScoreMarkdown.getPercentageImage(score.getDisplayName(), score.getPercentage());
return getPercentageImage(score.getDisplayName(), score.getPercentage());
}
return ScoreMarkdown.getPercentageImage(score.getDisplayName(), score.getCoveredPercentage());
return getPercentageImage(score.getDisplayName(), score.getCoveredPercentage());
}
}
30 changes: 13 additions & 17 deletions src/test/java/edu/hm/hafner/grading/AnalysisScoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,7 @@ void shouldCalculateImpactAndScoreWithNegativeValues() {
}
""");

var analysisScore = new AnalysisScoreBuilder()
.withId(ID)
.withName(NAME)
.withConfiguration(configuration)
.withReport(createReportWith(Severity.ERROR, Severity.ERROR,
Severity.WARNING_HIGH, Severity.WARNING_HIGH,
Severity.WARNING_NORMAL, Severity.WARNING_NORMAL,
Severity.WARNING_LOW, Severity.WARNING_LOW))
.build();
var analysisScore = createScore(configuration);
assertThat(analysisScore)
.hasId(ID).hasName(NAME).hasConfiguration(configuration)
.hasErrorSize(2).hasHighSeveritySize(2).hasNormalSeveritySize(2).hasLowSeveritySize(2)
Expand Down Expand Up @@ -76,7 +68,18 @@ void shouldCalculateImpactAndScoreWithPositiveValues() {
}
""");

var analysisScore = new AnalysisScoreBuilder()
var analysisScore = createScore(configuration);
assertThat(analysisScore)
.hasId(ID).hasName(NAME).hasConfiguration(configuration)
.hasErrorSize(2).hasHighSeveritySize(2).hasNormalSeveritySize(2).hasLowSeveritySize(2)
.hasMaxScore(25)
.hasTotalSize(2 + 2 + 2 + 2)
.hasImpact(2 * 4 + 2 * 3 + 2 * 2 + 2)
.hasValue(20);
}

private AnalysisScore createScore(final AnalysisConfiguration configuration) {
return new AnalysisScoreBuilder()
.withId(ID)
.withName(NAME)
.withConfiguration(configuration)
Expand All @@ -85,13 +88,6 @@ void shouldCalculateImpactAndScoreWithPositiveValues() {
Severity.WARNING_NORMAL, Severity.WARNING_NORMAL,
Severity.WARNING_LOW, Severity.WARNING_LOW))
.build();
assertThat(analysisScore)
.hasId(ID).hasName(NAME).hasConfiguration(configuration)
.hasErrorSize(2).hasHighSeveritySize(2).hasNormalSeveritySize(2).hasLowSeveritySize(2)
.hasMaxScore(25)
.hasTotalSize(2 + 2 + 2 + 2)
.hasImpact(2 * 4 + 2 * 3 + 2 * 2 + 2)
.hasValue(20);
}

@Test
Expand Down

0 comments on commit d23ac7e

Please sign in to comment.