Skip to content

Commit

Permalink
Skip subreport messages when copying and merging reports.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Apr 25, 2024
1 parent 8817168 commit c872fdc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/main/java/edu/hm/hafner/analysis/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ public Report addAll(final Report... reports) {
}
else {
reportsToAdd.addAll(report.subReports);
infoMessages.addAll(report.getInfoMessages());
errorMessages.addAll(report.getErrorMessages());
infoMessages.addAll(report.infoMessages);
errorMessages.addAll(report.errorMessages);
}
}

Expand Down Expand Up @@ -870,8 +870,8 @@ private void copyProperties(final Report source, final Report destination) {
destination.name = source.getName();
destination.originReportFile = source.getOriginReportFile();
destination.duplicatesSize += source.duplicatesSize; // not recursively
destination.infoMessages.addAll(source.getInfoMessages());
destination.errorMessages.addAll(source.getErrorMessages());
destination.infoMessages.addAll(source.infoMessages);
destination.errorMessages.addAll(source.errorMessages);
destination.countersByKey = Stream.concat(
destination.countersByKey.entrySet().stream(), source.countersByKey.entrySet().stream())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, Integer::sum));
Expand Down
61 changes: 38 additions & 23 deletions src/test/java/edu/hm/hafner/analysis/ReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Set;
import java.util.UUID;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -44,34 +45,32 @@
* @author Marcel Binder
* @author Ullrich Hafner
*/
@SuppressWarnings({"PMD.GodClass", "PMD.ExcessiveImports", "PMD.ExcessiveClassLength", "checkstyle:ClassDataAbstractionCoupling"})
@SuppressWarnings({"PMD.GodClass", "PMD.ExcessiveImports", "PMD.ExcessiveClassLength", "checkstyle:ClassDataAbstractionCoupling", "checkstyle:ClassFanOutComplexity"})
class ReportTest extends SerializableTest<Report> {
private static final String SERIALIZATION_NAME = "report.ser";

private static final Issue HIGH = new IssueBuilder().setMessage("issue-1")
private static final Issue HIGH = build(b ->
b.setMessage("issue-1").setFileName("file-1").setSeverity(Severity.WARNING_HIGH));
private static final Issue NORMAL_1 = build(b ->
b.setMessage("issue-2")
.setFileName("file-1")
.setSeverity(Severity.WARNING_HIGH)
.build();
private static final Issue NORMAL_1 = new IssueBuilder().setMessage("issue-2")
.setSeverity(Severity.WARNING_NORMAL));
private static final Issue NORMAL_2 = build(b ->
b.setMessage("issue-3")
.setFileName("file-1")
.setSeverity(Severity.WARNING_NORMAL)
.build();
private static final Issue NORMAL_2 = new IssueBuilder().setMessage("issue-3")
.setFileName("file-1")
.setSeverity(Severity.WARNING_NORMAL)
.build();
private static final Issue LOW_2_A = new IssueBuilder().setMessage("issue-4")
.setSeverity(Severity.WARNING_NORMAL));
private static final Issue LOW_2_A = build(b ->
b.setMessage("issue-4")
.setFileName("file-2")
.setSeverity(Severity.WARNING_LOW)
.build();
private static final Issue LOW_2_B = new IssueBuilder().setMessage("issue-5")
.setSeverity(Severity.WARNING_LOW));
private static final Issue LOW_2_B = build(b ->
b.setMessage("issue-5")
.setFileName("file-2")
.setSeverity(Severity.WARNING_LOW)
.build();
private static final Issue LOW_FILE_3 = new IssueBuilder().setMessage("issue-6")
.setSeverity(Severity.WARNING_LOW));
private static final Issue LOW_FILE_3 = build(b ->
b.setMessage("issue-6")
.setFileName("file-3")
.setSeverity(Severity.WARNING_LOW)
.build();
.setSeverity(Severity.WARNING_LOW));
private static final int VALUE = 1234;
private static final String KEY = "key";

Expand All @@ -90,6 +89,14 @@ static void beforeAll() {
SLF4JBridgeHandler.install();
}

static Issue build(final Consumer<IssueBuilder> configuration) {
try (var issueBuilder = new IssueBuilder()) {
configuration.accept(issueBuilder);

return issueBuilder.build();
}
}

@Test
void shouldFindIssuesInModifiedCode() {
Report report = new Report();
Expand Down Expand Up @@ -986,13 +993,20 @@ void shouldCopyMessagesRecursively() {
assertThat(aggregated.getNameOfOrigin(CHECKSTYLE_ID)).isEqualTo(CHECKSTYLE_NAME);
assertThat(aggregated.getNameOfOrigin(SPOTBUGS_ID)).isEqualTo(SPOTBUGS_NAME);

assertThat(aggregated.getInfoMessages()).contains(
verifyAggregation(aggregated);

var copy = aggregated.copy();
verifyAggregation(copy);
}

private void verifyAggregation(final Report aggregated) {
assertThat(aggregated.getInfoMessages()).containsOnlyOnce(
"Info message from CheckStyle",
"Info message from SpotBugs",
"Info (Wrapped) message from CheckStyle",
"Info (Wrapped) message from SpotBugs",
"Info (Aggregated) message");
assertThat(aggregated.getErrorMessages()).contains(
assertThat(aggregated.getErrorMessages()).containsOnlyOnce(
"Error message from CheckStyle",
"Error message from SpotBugs",
"Error (Wrapped) message from CheckStyle",
Expand Down Expand Up @@ -1130,7 +1144,8 @@ void shouldObeyEqualsContract() {
.forClass(Report.class)
.withPrefabValues(Report.class, new Report("left", "Left"), new Report("right", "Right"))
.withPrefabValues(TreeString.class, TreeString.valueOf("One"), TreeString.valueOf("Two"))
.withPrefabValues(LineRangeList.class, new LineRangeList(new LineRange(2, 2)), new LineRangeList(new LineRange(1, 1)))
.withPrefabValues(LineRangeList.class, new LineRangeList(new LineRange(2, 2)),
new LineRangeList(new LineRange(1, 1)))
.verify();
}

Expand Down

0 comments on commit c872fdc

Please sign in to comment.