1 package test.net.sourceforge.pmd.rules;
2
3 import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
4 import test.net.sourceforge.pmd.testframework.TestDescriptor;
5 import net.sourceforge.pmd.Rule;
6 import net.sourceforge.pmd.PMD;
7 import net.sourceforge.pmd.rules.XPathRule;
8
9 public class UnconditionalIfStatementRuleTest extends SimpleAggregatorTst {
10
11 private Rule rule;
12
13 public void setUp() {
14 rule = new XPathRule();
15 rule.addProperty("xpath", "//IfStatement/Expression/ConditionalAndExpression/InstanceOfExpression/UnaryExpression/PrimaryExpression/PrimaryPrefix/Literal/BooleanLiteral");
16 }
17
18 public void testAll() {
19 runTests(new TestDescriptor[] {
20 new TestDescriptor(TEST1, "if (true)", 1, rule),
21 new TestDescriptor(TEST2, "if (false)", 1, rule),
22 new TestDescriptor(TEST3, "no constant folding", 0, rule),
23 new TestDescriptor(TEST4, "short circuit operator", 1, rule)
24 });
25 }
26
27 private static final String TEST1 =
28 "public class Foo {" + PMD.EOL +
29 " void bar() {" + PMD.EOL +
30 " if (true) {}" + PMD.EOL +
31 " }" + PMD.EOL +
32 "}";
33
34 private static final String TEST2 =
35 "public class Foo {" + PMD.EOL +
36 " void bar() {" + PMD.EOL +
37 " if (false) {}" + PMD.EOL +
38 " }" + PMD.EOL +
39 "}";
40
41 private static final String TEST3 =
42 "public class Foo {" + PMD.EOL +
43 " private static final boolean DEBUG = \"false\";" + PMD.EOL +
44 " void bar() {" + PMD.EOL +
45 " if (DEBUG) {}" + PMD.EOL +
46 " }" + PMD.EOL +
47 "}";
48
49 // FIXME - this shouldn't be flagged
50 private static final String TEST4 =
51 "public class Foo {" + PMD.EOL +
52 " void bar(Object x, boolean y) {" + PMD.EOL +
53 " if (y == true) {}" + PMD.EOL +
54 " }" + PMD.EOL +
55 "}";
56
57 }
This page was automatically generated by Maven