Test code refactorings

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1877 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2003-04-29 16:10:56 +00:00
parent 1952352008
commit 1daa5fd737
2 changed files with 34 additions and 43 deletions

View File

@ -3,7 +3,23 @@ package test.net.sourceforge.pmd.rules;
import net.sourceforge.pmd.cpd.CPD;
import net.sourceforge.pmd.rules.UnusedFormalParameterRule;
public class UnusedFormalParameterRuleTest extends RuleTst {
public class UnusedFormalParameterRuleTest extends SimpleAggregatorTst {
private UnusedFormalParameterRule rule;
public void setUp() {
rule = new UnusedFormalParameterRule();
rule.setMessage("Avoid this stuff -> ''{0}''");
}
public void testAll() {
runTests(new TestDescriptor[] {
new TestDescriptor(TEST1, "one parameter", 1, rule),
new TestDescriptor(TEST2, "fully qualified parameter", 0, rule),
new TestDescriptor(TEST3, "one parameter with a method call", 0, rule),
new TestDescriptor(TEST4, "interface", 0, rule)
});
}
private static final String TEST1 =
"class UnusedFormalParam1 {" + CPD.EOL +
@ -30,23 +46,4 @@ public class UnusedFormalParameterRuleTest extends RuleTst {
" public void foo(String bar);" + CPD.EOL +
"}";
private UnusedFormalParameterRule rule;
public void setUp() {
rule = new UnusedFormalParameterRule();
rule.setMessage("Avoid this stuff -> ''{0}''");
}
public void testOneParam() throws Throwable {
runTestFromString(TEST1, 1, rule);
}
public void testFullyQualified() throws Throwable {
runTestFromString(TEST2, 0, rule);
}
public void testOneParamWithMethodCall() throws Throwable {
runTestFromString(TEST3, 0, rule);
}
public void testInterface() throws Throwable {
runTestFromString(TEST4, 0, rule);
}
}

View File

@ -3,7 +3,23 @@ package test.net.sourceforge.pmd.rules;
import net.sourceforge.pmd.cpd.CPD;
import net.sourceforge.pmd.rules.UnusedImportsRule;
public class UnusedImportsRuleTest extends RuleTst {
public class UnusedImportsRuleTest extends SimpleAggregatorTst {
private UnusedImportsRule rule;
public void setUp() {
rule = new UnusedImportsRule();
rule.setMessage("Avoid this stuff -> ''{0}''");
}
public void testAll() {
runTests(new TestDescriptor[] {
new TestDescriptor(TEST1, "simple unused single type import", 1, rule),
new TestDescriptor(TEST2, "one used single type import", 0, rule),
new TestDescriptor(TEST3, "2 unused single-type imports", 2, rule),
new TestDescriptor(TEST4, "1 used single type import", 0, rule)
});
}
private static final String TEST1 =
"import java.io.File;" + CPD.EOL +
@ -30,26 +46,4 @@ public class UnusedImportsRuleTest extends RuleTst {
"}";
private UnusedImportsRule rule;
public void setUp() {
rule = new UnusedImportsRule();
rule.setMessage("Avoid this stuff -> ''{0}''");
}
public void test1() throws Throwable {
runTestFromString(TEST1, 1, rule);
}
public void test2() throws Throwable {
runTestFromString(TEST2, 0, rule);
}
public void test3() throws Throwable {
runTestFromString(TEST3, 2, rule);
}
public void test4() throws Throwable {
runTestFromString(TEST4, 0, rule);
}
}