More test cleanups
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1897 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -4,7 +4,24 @@ import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.cpd.CPD;
|
||||
import net.sourceforge.pmd.rules.XPathRule;
|
||||
|
||||
public class ForLoopShouldBeWhileLoopRuleTest extends RuleTst {
|
||||
public class ForLoopShouldBeWhileLoopRuleTest extends SimpleAggregatorTst {
|
||||
|
||||
private Rule rule;
|
||||
|
||||
public void setUp() {
|
||||
rule = new XPathRule();
|
||||
rule.addProperty(
|
||||
"xpath",
|
||||
"//ForStatement[count(*) > 1][not(ForInit)][not(ForUpdate)]");
|
||||
}
|
||||
|
||||
public void testAll() {
|
||||
runTests(new TestDescriptor[] {
|
||||
new TestDescriptor(TEST1, "simple failure case", 1, rule),
|
||||
new TestDescriptor(TEST2, "ok", 0, rule),
|
||||
new TestDescriptor(TEST3, "for loop like this: for (;;) {} ", 0, rule),
|
||||
});
|
||||
}
|
||||
|
||||
private static final String TEST1 =
|
||||
"public class ForLoopShouldBeWhileLoop1 {" + CPD.EOL +
|
||||
@ -32,25 +49,4 @@ public class ForLoopShouldBeWhileLoopRuleTest extends RuleTst {
|
||||
" }" + CPD.EOL +
|
||||
"}";
|
||||
|
||||
|
||||
private Rule rule;
|
||||
|
||||
public void setUp() {
|
||||
rule = new XPathRule();
|
||||
rule.addProperty(
|
||||
"xpath",
|
||||
"//ForStatement[count(*) > 1][not(ForInit)][not(ForUpdate)]");
|
||||
}
|
||||
|
||||
public void testSimple() throws Throwable {
|
||||
runTestFromString(TEST1, 1, rule);
|
||||
}
|
||||
|
||||
public void testOK() throws Throwable {
|
||||
runTestFromString(TEST2, 0, rule);
|
||||
}
|
||||
|
||||
public void testForSemicolonSemicolon() throws Throwable {
|
||||
runTestFromString(TEST3, 0, rule);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.cpd.CPD;
|
||||
import net.sourceforge.pmd.rules.XPathRule;
|
||||
|
||||
public class ForLoopsMustUseBracesRuleTest extends RuleTst {
|
||||
public class ForLoopsMustUseBracesRuleTest extends SimpleAggregatorTst {
|
||||
|
||||
private Rule rule;
|
||||
|
||||
@ -12,20 +12,15 @@ public class ForLoopsMustUseBracesRuleTest extends RuleTst {
|
||||
rule = new XPathRule();
|
||||
rule.addProperty("xpath", "//ForStatement[not(Statement/Block)]");
|
||||
}
|
||||
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,1, rule);
|
||||
}
|
||||
public void test4() throws Throwable {
|
||||
runTestFromString(TEST4,1, rule);
|
||||
}
|
||||
public void test5() throws Throwable {
|
||||
runTestFromString(TEST5,1, rule);
|
||||
|
||||
public void testAll() {
|
||||
runTests(new TestDescriptor[] {
|
||||
new TestDescriptor(TEST1, "simple failure case", 1, rule),
|
||||
new TestDescriptor(TEST2, "ok", 0, rule),
|
||||
new TestDescriptor(TEST3, "", 1, rule),
|
||||
new TestDescriptor(TEST4, "", 1, rule),
|
||||
new TestDescriptor(TEST5, "", 1, rule),
|
||||
});
|
||||
}
|
||||
|
||||
private static final String TEST1 =
|
||||
@ -50,7 +45,6 @@ public class ForLoopsMustUseBracesRuleTest extends RuleTst {
|
||||
" public void foo() { " + CPD.EOL +
|
||||
" for (int i=0; i<42;) " + CPD.EOL +
|
||||
" foo();" + CPD.EOL +
|
||||
" " + CPD.EOL +
|
||||
" }" + CPD.EOL +
|
||||
"}";
|
||||
|
||||
@ -59,7 +53,6 @@ public class ForLoopsMustUseBracesRuleTest extends RuleTst {
|
||||
" public void foo() { " + CPD.EOL +
|
||||
" for (int i=0;;) " + CPD.EOL +
|
||||
" foo();" + CPD.EOL +
|
||||
" " + CPD.EOL +
|
||||
" }" + CPD.EOL +
|
||||
"}";
|
||||
|
||||
@ -68,7 +61,6 @@ public class ForLoopsMustUseBracesRuleTest extends RuleTst {
|
||||
" public void foo() { " + CPD.EOL +
|
||||
" for (;;) " + CPD.EOL +
|
||||
" foo();" + CPD.EOL +
|
||||
" " + CPD.EOL +
|
||||
" }" + CPD.EOL +
|
||||
"}";
|
||||
}
|
||||
|
@ -4,7 +4,21 @@ import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.cpd.CPD;
|
||||
import net.sourceforge.pmd.rules.XPathRule;
|
||||
|
||||
public class IfElseStmtsMustUseBracesRuleTest extends RuleTst {
|
||||
public class IfElseStmtsMustUseBracesRuleTest extends SimpleAggregatorTst {
|
||||
|
||||
private Rule rule;
|
||||
|
||||
public void setUp() {
|
||||
rule = new XPathRule();
|
||||
rule.addProperty("xpath", "//IfStatement[count(*) > 2][not(Statement/Block)]");
|
||||
}
|
||||
|
||||
public void testAll() {
|
||||
runTests(new TestDescriptor[] {
|
||||
new TestDescriptor(TEST1, "simple failure case", 1, rule),
|
||||
new TestDescriptor(TEST2, "ok", 0, rule),
|
||||
});
|
||||
}
|
||||
|
||||
private static final String TEST1 =
|
||||
"public class IfElseStmtsNeedBraces1 {" + CPD.EOL +
|
||||
@ -32,18 +46,4 @@ public class IfElseStmtsMustUseBracesRuleTest extends RuleTst {
|
||||
|
||||
|
||||
|
||||
private Rule rule;
|
||||
|
||||
public void setUp() {
|
||||
rule = new XPathRule();
|
||||
rule.addProperty("xpath", "//IfStatement[count(*) > 2][not(Statement/Block)]");
|
||||
}
|
||||
|
||||
public void testIfElseStmtsMustUseBraces1() throws Throwable {
|
||||
runTestFromString(TEST1, 1, rule);
|
||||
}
|
||||
|
||||
public void testIfElseStmtsMustUseBraces2() throws Throwable {
|
||||
runTestFromString(TEST2, 0, rule);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user