1 package test.net.sourceforge.pmd.rules;
2
3 import net.sourceforge.pmd.PMD;
4 import net.sourceforge.pmd.Rule;
5 import net.sourceforge.pmd.rules.XPathRule;
6
7 public class SimplifyBooleanExpressionsRuleTest extends RuleTst {
8 private static final String TEST1 =
9 "public class SimplifyBooleanExpressions1 {" + PMD.EOL +
10 " private boolean foo = (isFoo() == true);" + PMD.EOL +
11 " public boolean isFoo() {return foo;}" + PMD.EOL +
12 "}";
13
14 private static final String TEST2 =
15 "public class SimplifyBooleanExpressions2 {" + PMD.EOL +
16 " public void foo() {" + PMD.EOL +
17 " boolean bar = (new String().length() >2) == false;" + PMD.EOL +
18 " }" + PMD.EOL +
19 "}";
20
21 private static final String TEST3 =
22 "public class SimplifyBooleanExpressions3 {" + PMD.EOL +
23 " boolean bar = true;" + PMD.EOL +
24 "}";
25
26 private Rule rule;
27
28 public void setUp() {
29 rule = new XPathRule();
30 rule.addProperty("xpath", "//Expression/ConditionalAndExpression/InstanceOfExpression[position()>1]/PrimaryExpression/PrimaryPrefix/Literal/BooleanLiteral");
31 }
32
33 public void testInFieldAssignment() throws Throwable {
34 runTestFromString(TEST1, 1, rule);
35 }
36 public void testInMethodBody() throws Throwable {
37 runTestFromString(TEST2, 1, rule);
38 }
39 public void testOK() throws Throwable {
40 runTestFromString(TEST3, 0, rule);
41 }
42 }
This page was automatically generated by Maven