From 255fdcc8d4c132fceab4d28ae9145fecaddaa8a5 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Mon, 28 Apr 2003 21:24:55 +0000 Subject: [PATCH] test cleanup git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1872 51baf565-9d33-0410-a72c-fc3788e3496d --- .../pmd/rules/UnusedLocalVariableTest.java | 135 +++++++----------- 1 file changed, 51 insertions(+), 84 deletions(-) diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/UnusedLocalVariableTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/UnusedLocalVariableTest.java index cd9712827d..0d233c65e8 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/UnusedLocalVariableTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/rules/UnusedLocalVariableTest.java @@ -3,20 +3,43 @@ package test.net.sourceforge.pmd.rules; import net.sourceforge.pmd.cpd.CPD; import net.sourceforge.pmd.rules.UnusedLocalVariableRule; -public class UnusedLocalVariableTest extends RuleTst { +public class UnusedLocalVariableTest extends SimpleAggregatorTst { + + private UnusedLocalVariableRule rule; + + public void setUp() { + rule = new UnusedLocalVariableRule(); + rule.setMessage("Avoid this stuff -> ''{0}''"); + } + + public void testAll() { + runTests(new TestDescriptor[] { + new TestDescriptor(TEST1, "unused local with assignment", 1, rule), + new TestDescriptor(TEST2, "unused local w/o assignment", 1, rule), + new TestDescriptor(TEST3, "unused local in constructor", 1, rule), + new TestDescriptor(TEST4, "local used on rhs", 0, rule), + new TestDescriptor(TEST5, "unused local in static initializer", 1, rule), + new TestDescriptor(TEST6, "unused field", 0, rule), + new TestDescriptor(TEST7, "loop indexes are not unused locals", 0, rule), + new TestDescriptor(TEST8, "", 0, rule), + new TestDescriptor(TEST9, "", 0, rule), + new TestDescriptor(TEST10, "", 2, rule), + new TestDescriptor(TEST11, "", 0, rule), + new TestDescriptor(TEST12, "", 0, rule), + new TestDescriptor(TEST13, "", 2, rule), + new TestDescriptor(TEST14, "", 0, rule) + }); + } private static final String TEST1 = - "import java.io.*;" + CPD.EOL + - "public class UnusedLocal1 {" + CPD.EOL + + "public class Foo {" + CPD.EOL + " public foo() {" + CPD.EOL + - " try {" + CPD.EOL + - " FileReader fr = new FileReader(\"/dev/null\");" + CPD.EOL + - " } catch (Exception e) {}" + CPD.EOL + + " String fr = new String();" + CPD.EOL + " }" + CPD.EOL + "}"; private static final String TEST2 = - "public class UnusedLocal2 {" + CPD.EOL + + "public class Foo {" + CPD.EOL + " public void method() {" + CPD.EOL + " int x;" + CPD.EOL + " }" + CPD.EOL + @@ -25,8 +48,8 @@ public class UnusedLocalVariableTest extends RuleTst { private static final String TEST3 = "import java.util.*;" + CPD.EOL + - "public class UnusedLocal3 {" + CPD.EOL + - " public UnusedLocal3() {" + CPD.EOL + + "public class Foo {" + CPD.EOL + + " public Foo() {" + CPD.EOL + " List a = new ArrayList();" + CPD.EOL + " }" + CPD.EOL + "}" + CPD.EOL + @@ -34,8 +57,8 @@ public class UnusedLocalVariableTest extends RuleTst { private static final String TEST4 = "import java.util.*;" + CPD.EOL + - "public class UnusedLocal4 {" + CPD.EOL + - " public UnusedLocal4() {" + CPD.EOL + + "public class Foo {" + CPD.EOL + + " public Foo() {" + CPD.EOL + " List a = new ArrayList();" + CPD.EOL + " if (true == true) {" + CPD.EOL + " a.size();" + CPD.EOL + @@ -46,7 +69,7 @@ public class UnusedLocalVariableTest extends RuleTst { private static final String TEST5 = "import java.util.*;" + CPD.EOL + - "public class UnusedLocal5 {" + CPD.EOL + + "public class Foo {" + CPD.EOL + "static {" + CPD.EOL + " String x;" + CPD.EOL + "}" + CPD.EOL + @@ -54,25 +77,21 @@ public class UnusedLocalVariableTest extends RuleTst { ""; private static final String TEST6 = - "public class UnusedLocal6 {" + CPD.EOL + + "public class Foo {" + CPD.EOL + " public int x;" + CPD.EOL + "}"; private static final String TEST7 = - "public class UnusedLocal7 {" + CPD.EOL + + "public class Foo {" + CPD.EOL + " public void foo() {" + CPD.EOL + " for (int i=0;i<10; i++);" + CPD.EOL + " for (int i=0;i<10; i++);" + CPD.EOL + " }" + CPD.EOL + "}"; - private static final String TEST8 = - "public class UnusedLocal8 {" + CPD.EOL + - " String foo = System.getProperty(\"line.separator\", \"\\n\");" + CPD.EOL + - "}"; - private static final String TEST9 = - "public class UnusedLocal9 {" + CPD.EOL + + private static final String TEST8 = + "public class Foo {" + CPD.EOL + " public void foo() {" + CPD.EOL + " final String x = \"baf\";" + CPD.EOL + " new Runnable() {" + CPD.EOL + @@ -83,14 +102,14 @@ public class UnusedLocalVariableTest extends RuleTst { " }" + CPD.EOL + "}"; - private static final String TEST10 = - "public interface UnusedLocal10 {" + CPD.EOL + + private static final String TEST9 = + "public interface Foo {" + CPD.EOL + " public void foo();" + CPD.EOL + " public String bar();" + CPD.EOL + "}"; - private static final String TEST11 = - "public class UnusedLocal11 {" + CPD.EOL + + private static final String TEST10 = + "public class Foo {" + CPD.EOL + " public void foo() {" + CPD.EOL + " String x = \"hi\";" + CPD.EOL + " class Bar {" + CPD.EOL + @@ -101,8 +120,8 @@ public class UnusedLocalVariableTest extends RuleTst { " }" + CPD.EOL + "}"; - private static final String TEST12 = - "public class UnusedLocal12 {" + CPD.EOL + + private static final String TEST11 = + "public class Foo {" + CPD.EOL + " public void foo() {" + CPD.EOL + " for (int x = 0; ; ) { // USED" + CPD.EOL + " x++;" + CPD.EOL + @@ -110,8 +129,8 @@ public class UnusedLocalVariableTest extends RuleTst { " }" + CPD.EOL + "}"; - private static final String TEST13 = - "public class UnusedLocal13 {" + CPD.EOL + + private static final String TEST12 = + "public class Foo {" + CPD.EOL + " public void foo() {" + CPD.EOL + " final String x = \"hi\";" + CPD.EOL + " new Runnable() {" + CPD.EOL + @@ -122,15 +141,15 @@ public class UnusedLocalVariableTest extends RuleTst { " }" + CPD.EOL + "}"; - private static final String TEST14 = - "public class UnusedLocal14 {" + CPD.EOL + + private static final String TEST13 = + "public class Foo {" + CPD.EOL + " public void foo() {" + CPD.EOL + " int x,y=0;" + CPD.EOL + " }" + CPD.EOL + "}"; - private static final String TEST15 = - "public class UnusedLocal15 {" + CPD.EOL + + private static final String TEST14 = + "public class Foo {" + CPD.EOL + " public void bar() {" + CPD.EOL + " try {" + CPD.EOL + " //int x =2;" + CPD.EOL + @@ -140,56 +159,4 @@ public class UnusedLocalVariableTest extends RuleTst { " }" + CPD.EOL + "}"; - private UnusedLocalVariableRule rule; - - public void setUp() { - rule = new UnusedLocalVariableRule(); - rule.setMessage("Avoid this stuff -> ''{0}''"); - } - - public void test1() throws Throwable { - runTestFromString(TEST1, 1, rule); - } - public void test2() throws Throwable { - runTestFromString(TEST2, 1, rule); - } - public void test3() throws Throwable { - runTestFromString(TEST3, 1, rule); - } - public void test4() throws Throwable { - runTestFromString(TEST4, 0, rule); - } - public void test5() throws Throwable { - runTestFromString(TEST5, 1, rule); - } - public void test6() throws Throwable { - runTestFromString(TEST6, 0, rule); - } - public void test7() throws Throwable { - runTestFromString(TEST7, 0, rule); - } - public void test8() throws Throwable { - runTestFromString(TEST8, 0, rule); - } - public void test9() throws Throwable { - runTestFromString(TEST9, 0, rule); - } - public void test10() throws Throwable { - runTestFromString(TEST10, 0, rule); - } - public void test11() throws Throwable { - runTestFromString(TEST11, 2, rule); - } - public void test12() throws Throwable { - runTestFromString(TEST12, 0, rule); - } - public void test13() throws Throwable { - runTestFromString(TEST13, 0, rule); - } - public void test14() throws Throwable { - runTestFromString(TEST14, 2, rule); - } - public void test15() throws Throwable { - runTestFromString(TEST15, 0, rule); - } }