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 11, 2024
1 parent f55e807 commit 478c294
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/main/java/edu/hm/hafner/grading/CoverageScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;
import java.util.Objects;

import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down Expand Up @@ -87,7 +86,7 @@ public String getMetricTagName() {

@JsonIgnore
public Node getReport() {
return ObjectUtils.defaultIfNull(report, new ModuleNode("empty"));
return report;
}

@Override
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/edu/hm/hafner/grading/ScoreMarkdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ abstract class ScoreMarkdown<S extends Score<S, C>, C extends Configuration> {
static final int MESSAGE_INITIAL_CAPACITY = 1024;
private static final int MAX_SIZE = 10_000; // limit the size of the output to this number of characters
private static final String TRUNCATION_TEXT = "\n\nToo many test failures. Grading output truncated.";
private static final int HUNDRED_PERCENT = 100;

private final String type;
private final String icon;
Expand All @@ -50,7 +51,7 @@ abstract class ScoreMarkdown<S extends Score<S, C>, C extends Configuration> {
* @return Markdown text
*/
public static String getPercentageImage(final String title, final int percentage) {
if (percentage < 0 || percentage > 100) {
if (percentage < 0 || percentage > HUNDRED_PERCENT) {
throw new IllegalArgumentException("Percentage must be between 0 and 100: " + percentage);
}
return String.format("""
Expand Down Expand Up @@ -150,8 +151,8 @@ static String createScoreTitleSuffix(final int maxScore, final int value, final
if (maxScore == 0) {
return StringUtils.EMPTY;
}
if (maxScore == 100) {
return String.format(" - %d of %d", value, maxScore);
if (maxScore == HUNDRED_PERCENT) {
return String.format(" - %d of %d", value, maxScore); // no need to show percentage for a score of 100
}
return String.format(" - %d of %d (%d%%)", value, maxScore, percentage);
}
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/edu/hm/hafner/grading/TestScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down Expand Up @@ -36,8 +35,7 @@ public final class TestScore extends Score<TestScore, TestConfiguration> {
private final int passedSize;
private final int failedSize;
private final int skippedSize;
@CheckForNull
private final transient Node report;
private transient Node report; // do not persist the tree of nodes

private TestScore(final String id, final String name, final TestConfiguration configuration,
final List<TestScore> scores) {
Expand All @@ -61,6 +59,18 @@ private TestScore(final String id, final String name, final TestConfiguration co
skippedSize = sum(report, TestResult.SKIPPED);
}

/**
* Restore an empty report after de-serialization.
*
* @return this
*/
@Serial @CanIgnoreReturnValue
private Object readResolve() {
report = new ModuleNode("empty");

return this;
}

private int aggregate(final List<TestScore> scores, final Function<TestScore, Integer> property) {
return scores.stream().reduce(0, (sum, score) -> sum + property.apply(score), Integer::sum);
}
Expand All @@ -75,7 +85,7 @@ private int sum(final Node testReport, final TestResult testResult) {

@JsonIgnore
public Node getReport() {
return ObjectUtils.defaultIfNull(report, new ModuleNode("empty"));
return report;
}

@Override
Expand Down

0 comments on commit 478c294

Please sign in to comment.