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 5be5ef73cd..8fc9cef3ac 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java @@ -423,7 +423,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 @@ -434,7 +434,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"); }