Test code refactorings
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1878 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -4,7 +4,23 @@ import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.cpd.CPD;
|
||||
import net.sourceforge.pmd.rules.XPathRule;
|
||||
|
||||
public class StringInstantiationRuleTest extends RuleTst {
|
||||
public class StringInstantiationRuleTest extends SimpleAggregatorTst {
|
||||
|
||||
private Rule rule;
|
||||
|
||||
public void setUp() {
|
||||
rule = new XPathRule();
|
||||
rule.addProperty("xpath", "//AllocationExpression[Name/@Image='String'][count(.//Expression) < 2][not(ArrayDimsAndInits)]");
|
||||
}
|
||||
|
||||
public void testAll() {
|
||||
runTests(new TestDescriptor[] {
|
||||
new TestDescriptor(TEST1, "new 'new String's", 2, rule),
|
||||
new TestDescriptor(TEST2, "new String array", 0, rule),
|
||||
new TestDescriptor(TEST3, "using multiple parameter constructor", 0, rule),
|
||||
new TestDescriptor(TEST4, "using 4 parameter constructor", 0, rule)
|
||||
});
|
||||
}
|
||||
|
||||
private static final String TEST1 =
|
||||
"public class StringInstantiation1 {" + CPD.EOL +
|
||||
@ -34,23 +50,4 @@ public class StringInstantiationRuleTest extends RuleTst {
|
||||
"}";
|
||||
|
||||
|
||||
private Rule rule;
|
||||
|
||||
public void setUp() {
|
||||
rule = new XPathRule();
|
||||
rule.addProperty("xpath", "//AllocationExpression[Name/@Image='String'][count(.//Expression) < 2][not(ArrayDimsAndInits)]");
|
||||
}
|
||||
|
||||
public void test1() throws Throwable {
|
||||
runTestFromString(TEST1, 2, rule);
|
||||
}
|
||||
public void test2() throws Throwable {
|
||||
runTestFromString(TEST2, 0, rule);
|
||||
}
|
||||
public void test3() throws Throwable {
|
||||
runTestFromString(TEST3, 0, rule);
|
||||
}
|
||||
public void test4() throws Throwable {
|
||||
runTestFromString(TEST4, 0, rule);
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,20 @@ package test.net.sourceforge.pmd.rules;
|
||||
import net.sourceforge.pmd.cpd.CPD;
|
||||
import net.sourceforge.pmd.rules.StringToStringRule;
|
||||
|
||||
public class StringToStringRuleTest extends RuleTst {
|
||||
public class StringToStringRuleTest extends SimpleAggregatorTst {
|
||||
|
||||
private static final String TEST1 =
|
||||
public void testAll() {
|
||||
runTests(new TestDescriptor[] {
|
||||
new TestDescriptor(TEST1, "local var", 1, new StringToStringRule()),
|
||||
new TestDescriptor(TEST2, "parameter", 1, new StringToStringRule()),
|
||||
new TestDescriptor(TEST3, "field", 1, new StringToStringRule()),
|
||||
new TestDescriptor(TEST4, "primitive", 0, new StringToStringRule()),
|
||||
new TestDescriptor(TEST5, "multiple similar params", 0, new StringToStringRule()),
|
||||
new TestDescriptor(TEST6, "string array", 1, new StringToStringRule())
|
||||
});
|
||||
}
|
||||
|
||||
private static final String TEST1 =
|
||||
"public class StringToString1 {" + CPD.EOL +
|
||||
" private String baz() {" + CPD.EOL +
|
||||
" String bar = \"howdy\";" + CPD.EOL +
|
||||
@ -51,27 +62,4 @@ public class StringToStringRuleTest extends RuleTst {
|
||||
" }" + CPD.EOL +
|
||||
"}";
|
||||
|
||||
public void testLocalVar() throws Throwable {
|
||||
runTestFromString(TEST1, 1, new StringToStringRule());
|
||||
}
|
||||
|
||||
public void testParam() throws Throwable {
|
||||
runTestFromString(TEST2, 1, new StringToStringRule());
|
||||
}
|
||||
|
||||
public void testInstanceVar() throws Throwable {
|
||||
runTestFromString(TEST3, 1, new StringToStringRule());
|
||||
}
|
||||
|
||||
public void testPrimitiveType() throws Throwable {
|
||||
runTestFromString(TEST4, 0, new StringToStringRule());
|
||||
}
|
||||
|
||||
public void testMultipleSimilarParams() throws Throwable {
|
||||
runTestFromString(TEST5, 0, new StringToStringRule());
|
||||
}
|
||||
|
||||
public void testStringArray() throws Throwable {
|
||||
runTestFromString(TEST6, 1, new StringToStringRule());
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,21 @@ import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.cpd.CPD;
|
||||
import net.sourceforge.pmd.rules.XPathRule;
|
||||
|
||||
public class SwitchStmtsShouldHaveDefaultRuleTest extends RuleTst {
|
||||
public class SwitchStmtsShouldHaveDefaultRuleTest extends SimpleAggregatorTst {
|
||||
|
||||
private Rule rule;
|
||||
|
||||
public void setUp() {
|
||||
rule = new XPathRule();
|
||||
rule.addProperty("xpath", "//SwitchStatement[not(SwitchLabel[count(*) = 0])]");
|
||||
}
|
||||
|
||||
public void testAll() {
|
||||
runTests(new TestDescriptor[] {
|
||||
new TestDescriptor(TEST1, "simple failure case", 1, rule),
|
||||
new TestDescriptor(TEST2, "simple ok case", 0, rule)
|
||||
});
|
||||
}
|
||||
|
||||
private static final String TEST1 =
|
||||
"public class SwitchStmtsShouldHaveDefault1 {" + CPD.EOL +
|
||||
@ -28,19 +42,4 @@ public class SwitchStmtsShouldHaveDefaultRuleTest extends RuleTst {
|
||||
"}";
|
||||
|
||||
|
||||
private Rule rule;
|
||||
|
||||
public void setUp() {
|
||||
rule = new XPathRule();
|
||||
rule.addProperty("xpath", "//SwitchStatement[not(SwitchLabel[count(*) = 0])]");
|
||||
}
|
||||
|
||||
public void test1() throws Throwable {
|
||||
runTestFromString(TEST1, 1, rule);
|
||||
}
|
||||
|
||||
public void test2() throws Throwable {
|
||||
runTestFromString(TEST2, 0, rule);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,25 @@ import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.cpd.CPD;
|
||||
import net.sourceforge.pmd.rules.XPathRule;
|
||||
|
||||
public class UnnecessaryConstructorRuleTest extends RuleTst {
|
||||
public class UnnecessaryConstructorRuleTest extends SimpleAggregatorTst {
|
||||
|
||||
private Rule rule;
|
||||
|
||||
public void setUp() {
|
||||
rule = new XPathRule();
|
||||
rule.addProperty("xpath", "//ConstructorDeclaration[1][count(//ConstructorDeclaration)=1][@Public='true'][not(FormalParameters/*)][not(BlockStatement)][not(NameList)]");
|
||||
}
|
||||
|
||||
public void testAll() {
|
||||
runTests(new TestDescriptor[] {
|
||||
new TestDescriptor(TEST1, "simple failure case", 1, rule),
|
||||
new TestDescriptor(TEST2, "private constructor", 0, rule),
|
||||
new TestDescriptor(TEST3, "constructor with arguments", 0, rule),
|
||||
new TestDescriptor(TEST4, "constructor with contents", 0, rule),
|
||||
new TestDescriptor(TEST5, "constructor throws exception", 0, rule),
|
||||
new TestDescriptor(TEST6, "two constructors", 0, rule)
|
||||
});
|
||||
}
|
||||
|
||||
private static final String TEST1 =
|
||||
"public class UnnecessaryConstructor1 {" + CPD.EOL +
|
||||
@ -42,29 +60,4 @@ public class UnnecessaryConstructorRuleTest extends RuleTst {
|
||||
"}";
|
||||
|
||||
|
||||
private Rule rule;
|
||||
|
||||
public void setUp() {
|
||||
rule = new XPathRule();
|
||||
rule.addProperty("xpath", "//ConstructorDeclaration[1][count(//ConstructorDeclaration)=1][@Public='true'][not(FormalParameters/*)][not(BlockStatement)][not(NameList)]");
|
||||
}
|
||||
|
||||
public void testSimpleFailureCase() throws Throwable {
|
||||
runTestFromString(TEST1, 1, rule);
|
||||
}
|
||||
public void testPrivate() throws Throwable {
|
||||
runTestFromString(TEST2, 0, rule);
|
||||
}
|
||||
public void testHasArgs() throws Throwable {
|
||||
runTestFromString(TEST3, 0, rule);
|
||||
}
|
||||
public void testHasBody() throws Throwable {
|
||||
runTestFromString(TEST4, 0, rule);
|
||||
}
|
||||
public void testHasExceptions() throws Throwable {
|
||||
runTestFromString(TEST5, 0, rule);
|
||||
}
|
||||
public void testMultipleConstructors() throws Throwable {
|
||||
runTestFromString(TEST6, 0, rule);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user