From f6e293896293b1198d9775208f516d262e22c933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Dec 2021 13:27:34 +0100 Subject: [PATCH] Cleanups --- .../net/sourceforge/pmd/RuleContextTest.java | 17 ++--------------- .../java/net/sourceforge/pmd/RuleSetTest.java | 4 ++-- .../sourceforge/pmd/cpd/FileReporterTest.java | 4 ++-- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleContextTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleContextTest.java index bcf485503e..c9674af4fc 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleContextTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleContextTest.java @@ -5,31 +5,18 @@ package net.sourceforge.pmd; import java.util.function.BiConsumer; -import java.util.function.Consumer; import org.junit.Assert; import org.junit.Test; -import net.sourceforge.pmd.Report.ReportBuilderListener; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.ast.impl.DummyTreeUtil; -import net.sourceforge.pmd.reporting.FileAnalysisListener; public class RuleContextTest { - public static Report getReport(Consumer sideEffects) { - ReportBuilderListener listener = new ReportBuilderListener(); - try { - sideEffects.accept(listener); - } finally { - listener.close(); - } - return listener.getResult(); - } - public static Report getReport(Rule rule, BiConsumer sideEffects) throws Exception { - return getReport(listener -> sideEffects.accept(rule, RuleContext.create(listener, rule))); + return Report.buildReport(listener -> sideEffects.accept(rule, RuleContext.create(listener, rule))); } public static Report getReportForRuleApply(Rule rule, Node node) throws Exception { @@ -37,7 +24,7 @@ public class RuleContextTest { } public static Report getReportForRuleSetApply(RuleSet ruleset, RootNode node) throws Exception { - return getReport(listener -> new RuleSets(ruleset).apply(node, listener)); + return Report.buildReport(listener -> new RuleSets(ruleset).apply(node, listener)); } @Test diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java index a6c09a5671..e8ad99795a 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java @@ -421,7 +421,7 @@ public class RuleSetTest { RuleSets ruleSets = new RuleSets(listOf(ruleSet1, ruleSet2)); // Two violations - Report report = RuleContextTest.getReport(ctx -> ruleSets.apply(makeCompilationUnits(), ctx)); + Report report = Report.buildReport(ctx1 -> ruleSets.apply(makeCompilationUnits(), ctx1)); assertEquals("Violations", 2, report.getViolations().size()); // One violation @@ -432,7 +432,7 @@ public class RuleSetTest { RuleSets ruleSets2 = new RuleSets(listOf(ruleSet1, ruleSet2)); - report = RuleContextTest.getReport(ctx -> ruleSets2.apply(makeCompilationUnits("C:\\package\\RandomClass.java"), ctx)); + report = Report.buildReport(ctx -> ruleSets2.apply(makeCompilationUnits("C:\\package\\RandomClass.java"), ctx)); assertEquals("Violations", 1, report.getViolations().size()); } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/FileReporterTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/FileReporterTest.java index f5e94f8fbc..69768f7ecb 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/FileReporterTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/FileReporterTest.java @@ -7,10 +7,10 @@ package net.sourceforge.pmd.cpd; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.io.Reader; import org.apache.commons.io.IOUtils; import org.junit.Test; @@ -55,7 +55,7 @@ public class FileReporterTest { } private String readFile(File file) throws IOException { - try (BufferedReader reader = new BufferedReader(new FileReader(file))) { + try (Reader reader = new FileReader(file)) { String text = IOUtils.toString(reader); return text.replaceAll("\\R", "\n"); }