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.RuleSetNotFoundException; 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() throws RuleSetNotFoundException { 16 rule = findRule("rulesets/design.xml", "SimplifyBooleanExpressions"); 17 } 18 19 public void testInFieldAssignment() throws Throwable { 20 runTestFromString(TEST1, 1, rule); 21 } 22 public void testInMethodBody() throws Throwable { 23 runTestFromString(TEST2, 1, rule); 24 } 25 public void testOK() throws Throwable { 26 runTestFromString(TEST3, 0, rule); 27 } 28 29 private static final String TEST1 = 30 "public class Foo {" + PMD.EOL + 31 " private boolean foo = (isFoo() == true);" + PMD.EOL + 32 " boolean isFoo() {return foo;}" + PMD.EOL + 33 "}"; 34 35 private static final String TEST2 = 36 "public class Foo {" + PMD.EOL + 37 " void foo() {" + PMD.EOL + 38 " boolean bar = (new String().length() >2) == false;" + PMD.EOL + 39 " }" + PMD.EOL + 40 "}"; 41 42 private static final String TEST3 = 43 "public class Foo {" + PMD.EOL + 44 " boolean bar = true;" + PMD.EOL + 45 "}"; 46 }