From e37a0ceefbb62dd3c88196412e94fc7eb40f0d30 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Fri, 28 Jun 2002 18:05:57 +0000 Subject: [PATCH] moving stuff out of FunctionalTest git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@134 51baf565-9d33-0410-a72c-fc3788e3496d --- .../net/sourceforge/pmd/FunctionalTest.java | 17 --------- .../pmd/rules/EmptyCatchBlockRuleTest.java | 37 +++++++++++++++++++ .../net/sourceforge/pmd/rules/RuleTst.java | 13 +++++++ .../pmd/rules/UnusedLocalVariableTest.java | 33 ++++++----------- 4 files changed, 61 insertions(+), 39 deletions(-) create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/EmptyCatchBlockRuleTest.java diff --git a/pmd/regress/test/net/sourceforge/pmd/FunctionalTest.java b/pmd/regress/test/net/sourceforge/pmd/FunctionalTest.java index e4b64694c3..a9d9488b73 100644 --- a/pmd/regress/test/net/sourceforge/pmd/FunctionalTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/FunctionalTest.java @@ -23,23 +23,6 @@ public class FunctionalTest extends TestCase{ /* - public void testEmptyCatchBlock() { - Report report = process("EmptyCatchBlock.java"); - assertEquals(1, report.countViolationsInCurrentFile()); - assertEquals(new EmptyCatchBlockRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule()); - } - - public void testEmptyCatchBlock2() { - Report report = process("EmptyCatchBlock2.java"); - assertTrue(report.currentFileHasNoViolations()); - } - - public void testEmptyCatchBlock3() { - Report report = process("EmptyCatchBlock3.java"); - assertEquals(1, report.countViolationsInCurrentFile()); - assertEquals(new EmptyCatchBlockRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule()); - } - public void testUnnecessaryTemporaries() { Report report = process("UnnecessaryTemporary.java"); assertEquals(6, report.countViolationsInCurrentFile()); diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/EmptyCatchBlockRuleTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/EmptyCatchBlockRuleTest.java new file mode 100644 index 0000000000..a983461200 --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/EmptyCatchBlockRuleTest.java @@ -0,0 +1,37 @@ +/* + * User: tom + * Date: Jun 28, 2002 + * Time: 1:56:19 PM + */ +package test.net.sourceforge.pmd.rules; + +import junit.framework.TestCase; +import net.sourceforge.pmd.Report; +import net.sourceforge.pmd.RuleViolation; +import net.sourceforge.pmd.rules.EmptyCatchBlockRule; + +public class EmptyCatchBlockRuleTest extends RuleTst { + + public EmptyCatchBlockRuleTest(String name) { + super(name); + } + + public void testEmptyCatchBlock() { + Report report = process2("EmptyCatchBlock.java", new EmptyCatchBlockRule()); + assertEquals(1, report.countViolationsInCurrentFile()); + assertEquals(new EmptyCatchBlockRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule()); + } + + public void testEmptyCatchBlock2() { + Report report = process2("EmptyCatchBlock2.java", new EmptyCatchBlockRule()); + assertTrue(report.currentFileHasNoViolations()); + } + + public void testEmptyCatchBlock3() { + Report report = process2("EmptyCatchBlock3.java", new EmptyCatchBlockRule()); + assertEquals(1, report.countViolationsInCurrentFile()); + assertEquals(new EmptyCatchBlockRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule()); + } + + +} diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/RuleTst.java b/pmd/regress/test/net/sourceforge/pmd/rules/RuleTst.java index 0fb6420be6..e9794b6e7b 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/RuleTst.java +++ b/pmd/regress/test/net/sourceforge/pmd/rules/RuleTst.java @@ -8,6 +8,7 @@ package test.net.sourceforge.pmd.rules; */ import java.io.InputStream; +import java.io.FileNotFoundException; import java.util.List; import java.util.ArrayList; @@ -15,6 +16,7 @@ import java.util.ArrayList; import junit.framework.TestCase; import net.sourceforge.pmd.*; +import net.sourceforge.pmd.rules.UnusedLocalVariableRule; import net.sourceforge.pmd.ast.*; public class RuleTst @@ -50,4 +52,15 @@ public class RuleTst } + public Report process2(String file, Rule rule) { + try { + PMD p = new PMD(); + RuleContext ctx = new RuleContext(); + ctx.setReport(new Report("xml", file)); + p.processFile(file, getClass().getClassLoader().getResourceAsStream(file), rule, ctx); + return ctx.getReport(); + } catch (FileNotFoundException fnfe) { + throw new RuntimeException("File " + file + " not found"); + } + } } diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/UnusedLocalVariableTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/UnusedLocalVariableTest.java index f29734269a..159f08f13c 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/UnusedLocalVariableTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/rules/UnusedLocalVariableTest.java @@ -15,57 +15,57 @@ import java.util.ArrayList; import java.util.List; import java.io.FileNotFoundException; -public class UnusedLocalVariableTest extends TestCase { +public class UnusedLocalVariableTest extends RuleTst { public UnusedLocalVariableTest(String name) { super(name); } public void testUnusedLocal1() { - Report report = process("Unused1.java"); + Report report = process2("Unused1.java", new UnusedLocalVariableRule()); assertEquals(1, report.countViolationsInCurrentFile()); assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule()); } public void testUnusedLocal2() { - Report report = process("Unused2.java"); + Report report = process2("Unused2.java", new UnusedLocalVariableRule()); assertEquals(1, report.countViolationsInCurrentFile()); assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule()); } public void testUnusedLocal3() { - Report report = process("Unused3.java"); + Report report = process2("Unused3.java", new UnusedLocalVariableRule()); assertEquals(1, report.countViolationsInCurrentFile()); assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule()); } public void testUnusedLocal4() { - Report report = process("Unused4.java"); + Report report = process2("Unused4.java", new UnusedLocalVariableRule()); assertTrue(report.currentFileHasNoViolations()); } public void testUnusedLocal5() { - Report report = process("Unused5.java"); + Report report = process2("Unused5.java", new UnusedLocalVariableRule()); assertEquals(1, report.countViolationsInCurrentFile()); assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule()); } public void testUnusedLocal6() { - Report report = process("Unused6.java"); + Report report = process2("Unused6.java", new UnusedLocalVariableRule()); assertTrue(report.currentFileHasNoViolations()); } public void testUnusedLocal7() { - Report report = process("Unused7.java"); + Report report = process2("Unused7.java", new UnusedLocalVariableRule()); assertTrue(report.currentFileHasNoViolations()); } public void testUnusedLocal8() { - Report report = process("Unused8.java"); + Report report = process2("Unused8.java", new UnusedLocalVariableRule()); assertTrue(report.currentFileHasNoViolations()); } public void testUnusedLocal9() { - Report report = process("Unused9.java"); + Report report = process2("Unused9.java", new UnusedLocalVariableRule()); assertEquals(2, report.countViolationsInCurrentFile()); Iterator i = report.violationsInCurrentFile(); assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)i.next()).getRule()); @@ -73,19 +73,8 @@ public class UnusedLocalVariableTest extends TestCase { } public void testUnusedLocal10() { - Report report = process("Unused10.java"); + Report report = process2("Unused10.java", new UnusedLocalVariableRule()); assertTrue(report.currentFileHasNoViolations()); } - private Report process(String file) { - try { - PMD p = new PMD(); - RuleContext ctx = new RuleContext(); - ctx.setReport(new Report("xml", file)); - p.processFile(file, getClass().getClassLoader().getResourceAsStream(file), new UnusedLocalVariableRule(), ctx); - return ctx.getReport(); - } catch (FileNotFoundException fnfe) { - throw new RuntimeException("File " + file + " not found"); - } - } }