Skip to content

Commit

Permalink
Add a flag to hide the descriptions.
Browse files Browse the repository at this point in the history
When students create a lot of issues, it makes sense to hide the
descriptions.

Will fix #365
  • Loading branch information
uhafner committed Sep 22, 2024
1 parent 4ab486e commit 2ca7f65
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 deletions.
1 change: 0 additions & 1 deletion .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
-Pconsume-incrementals
-Pmight-produce-incrementals

Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
27 changes: 23 additions & 4 deletions src/main/java/edu/hm/hafner/grading/CommentBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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<String> prefixes;

CommentBuilder() {
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/test/java/edu/hm/hafner/grading/AnalysisScoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
37 changes: 33 additions & 4 deletions src/test/java/edu/hm/hafner/grading/CommentBuilderTest.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -34,7 +38,7 @@ class CommentBuilderTest {
void shouldCreateCoverageComments() {
var aggregation = createCoverageAggregation();

CommentBuilder builder = spy(CommentBuilder.class);
var builder = spy(CommentBuilder.class);

builder.createAnnotations(aggregation);

Expand All @@ -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);
Expand All @@ -61,7 +65,7 @@ void shouldLimitCoverageComments() {
void shouldCreateWarningComments() {
var aggregation = createWarningsAggregation();

CommentBuilder builder = spy(CommentBuilder.class);
var builder = spy(CommentBuilder.class);

builder.createAnnotations(aggregation);

Expand All @@ -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);
Expand All @@ -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<String> 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("<p>Since Checkstyle 3.1</p>");
}
}

private AggregatedScore createWarningsAggregation() {
var aggregation = new AggregatedScore("""
{
Expand Down

0 comments on commit 2ca7f65

Please sign in to comment.