diff --git a/.mvn/maven.config b/.mvn/maven.config index 51c71c0e..0ee86867 100644 --- a/.mvn/maven.config +++ b/.mvn/maven.config @@ -1,3 +1,2 @@ --Pconsume-incrementals -Pmight-produce-incrementals diff --git a/src/main/java/edu/hm/hafner/grading/AnalysisConfiguration.java b/src/main/java/edu/hm/hafner/grading/AnalysisConfiguration.java index 88208d0d..4a213f74 100644 --- a/src/main/java/edu/hm/hafner/grading/AnalysisConfiguration.java +++ b/src/main/java/edu/hm/hafner/grading/AnalysisConfiguration.java @@ -22,7 +22,7 @@ public final class AnalysisConfiguration extends Configuration { * Converts the specified JSON object to a list of {@link AnalysisConfiguration} instances. * * @param json - * the json object to convert + * the JSON object to convert * * @return the corresponding {@link AnalysisConfiguration} instances */ diff --git a/src/main/java/edu/hm/hafner/grading/CommentBuilder.java b/src/main/java/edu/hm/hafner/grading/CommentBuilder.java index e244d0ac..c496209e 100644 --- a/src/main/java/edu/hm/hafner/grading/CommentBuilder.java +++ b/src/main/java/edu/hm/hafner/grading/CommentBuilder.java @@ -26,9 +26,6 @@ * @author Ullrich Hafner */ public abstract class CommentBuilder { - private int warningComments; - private int coverageComments; - /** * Describes the type of the comment. Is the comment for a warning, a missed line, a partially covered line, or a * survived mutation? @@ -44,6 +41,9 @@ public enum CommentType { private static final String NO_ADDITIONAL_DETAILS = StringUtils.EMPTY; private static final PathUtil PATH_UTIL = new PathUtil(); + private int warningComments; + private int coverageComments; + private final List prefixes; CommentBuilder() { @@ -157,17 +157,36 @@ private void createWarningComment(final Issue issue, final String relativePath, } } + /** + * Returns the maximum number of warning comments to create. + * + * @return the maximum number of warning comments + */ protected int getMaxWarningComments() { return Integer.MAX_VALUE; } + /** + * Returns whether the description of the warning will be hidden. By default, the description will be shown. + * + * @return {@code true} if the description will be hidden, {@code false} if the description will be shown + */ + protected boolean isWarningDescriptionHidden() { + return false; + } + + /** + * Returns the maximum number of coverage comments to create. + * + * @return the maximum number of coverage comments + */ protected int getMaxCoverageComments() { return Integer.MAX_VALUE; } private String getDescription(final Issue issue) { var parserRegistry = new ParserRegistry(); - if (parserRegistry.contains(issue.getOrigin())) { + if (!isWarningDescriptionHidden() && parserRegistry.contains(issue.getOrigin())) { return parserRegistry.get(issue.getOrigin()).getDescription(issue); } return issue.getDescription(); diff --git a/src/test/java/edu/hm/hafner/grading/AnalysisScoreTest.java b/src/test/java/edu/hm/hafner/grading/AnalysisScoreTest.java index 62644e77..4df40116 100644 --- a/src/test/java/edu/hm/hafner/grading/AnalysisScoreTest.java +++ b/src/test/java/edu/hm/hafner/grading/AnalysisScoreTest.java @@ -300,6 +300,7 @@ static Report createReportWith(final String name, final Severity... severities) var text = severity.toString() + "-" + i; report.add(builder.setMessage(text) .setFileName(text) + .setType("DesignForExtensionCheck") .setSeverity(severity).build()); } } diff --git a/src/test/java/edu/hm/hafner/grading/CommentBuilderTest.java b/src/test/java/edu/hm/hafner/grading/CommentBuilderTest.java index bd2827d6..38f4aeb5 100644 --- a/src/test/java/edu/hm/hafner/grading/CommentBuilderTest.java +++ b/src/test/java/edu/hm/hafner/grading/CommentBuilderTest.java @@ -1,11 +1,15 @@ package edu.hm.hafner.grading; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.mockito.ArgumentCaptor; import edu.hm.hafner.coverage.registry.ParserRegistry.CoverageParserType; import edu.hm.hafner.util.FilteredLog; import static edu.hm.hafner.grading.AnalysisMarkdownTest.*; +import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; class CommentBuilderTest { @@ -34,7 +38,7 @@ class CommentBuilderTest { void shouldCreateCoverageComments() { var aggregation = createCoverageAggregation(); - CommentBuilder builder = spy(CommentBuilder.class); + var builder = spy(CommentBuilder.class); builder.createAnnotations(aggregation); @@ -47,7 +51,7 @@ void shouldCreateCoverageComments() { void shouldLimitCoverageComments() { var aggregation = createCoverageAggregation(); - CommentBuilder builder = spy(CommentBuilder.class); + var builder = spy(CommentBuilder.class); when(builder.getMaxCoverageComments()).thenReturn(5); builder.createAnnotations(aggregation); @@ -61,7 +65,7 @@ void shouldLimitCoverageComments() { void shouldCreateWarningComments() { var aggregation = createWarningsAggregation(); - CommentBuilder builder = spy(CommentBuilder.class); + var builder = spy(CommentBuilder.class); builder.createAnnotations(aggregation); @@ -74,7 +78,7 @@ void shouldCreateWarningComments() { void shouldLimitWarningComments() { var aggregation = createWarningsAggregation(); - CommentBuilder builder = spy(CommentBuilder.class); + var builder = spy(CommentBuilder.class); when(builder.getMaxWarningComments()).thenReturn(5); builder.createAnnotations(aggregation); @@ -84,6 +88,31 @@ void shouldLimitWarningComments() { anyInt(), anyInt(), anyString(), anyString()); } + @ParameterizedTest(name = "Should show description: {0}") + @ValueSource(booleans = {true, false}) + void shouldShowOrHideDescription(final boolean hideDescription) { + var aggregation = createWarningsAggregation(); + + var builder = spy(CommentBuilder.class); + when(builder.getMaxWarningComments()).thenReturn(1); + when(builder.isWarningDescriptionHidden()).thenReturn(hideDescription); + + builder.createAnnotations(aggregation); + + ArgumentCaptor description = ArgumentCaptor.forClass(String.class); + + verify(builder, times(1)) + .createComment(any(), anyString(), anyInt(), anyInt(), anyString(), anyString(), + anyInt(), anyInt(), anyString(), description.capture()); + + if (hideDescription) { + assertThat(description.getValue()).isEmpty(); + } + else { + assertThat(description.getValue()).contains("

Since Checkstyle 3.1

"); + } + } + private AggregatedScore createWarningsAggregation() { var aggregation = new AggregatedScore(""" {