View Javadoc
1 /*** 2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html 3 */ 4 package test.net.sourceforge.pmd.rules; 5 6 import net.sourceforge.pmd.PMD; 7 import net.sourceforge.pmd.Rule; 8 import net.sourceforge.pmd.rules.XPathRule; 9 import test.net.sourceforge.pmd.testframework.RuleTst; 10 11 public class SimplifyBooleanExpressionsRuleTest extends RuleTst { 12 13 private Rule rule; 14 15 public void setUp() { 16 rule = new XPathRule(); 17 rule.addProperty("xpath", "//Expression/ConditionalAndExpression/InstanceOfExpression[position()>1]/UnaryExpression/PrimaryExpression/PrimaryPrefix/Literal/BooleanLiteral"); 18 } 19 20 public void testInFieldAssignment() throws Throwable { 21 runTestFromString(TEST1, 1, rule); 22 } 23 public void testInMethodBody() throws Throwable { 24 runTestFromString(TEST2, 1, rule); 25 } 26 public void testOK() throws Throwable { 27 runTestFromString(TEST3, 0, rule); 28 } 29 30 private static final String TEST1 = 31 "public class Foo {" + PMD.EOL + 32 " private boolean foo = (isFoo() == true);" + PMD.EOL + 33 " public boolean isFoo() {return foo;}" + PMD.EOL + 34 "}"; 35 36 private static final String TEST2 = 37 "public class Foo {" + PMD.EOL + 38 " public void foo() {" + PMD.EOL + 39 " boolean bar = (new String().length() >2) == false;" + PMD.EOL + 40 " }" + PMD.EOL + 41 "}"; 42 43 private static final String TEST3 = 44 "public class Foo {" + PMD.EOL + 45 " boolean bar = true;" + PMD.EOL + 46 "}"; 47 }

This page was automatically generated by Maven