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.rules.SimplifyBooleanReturns;
8   import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
9   import test.net.sourceforge.pmd.testframework.TestDescriptor;
10  
11  public class SimplifyBooleanReturnsTest extends SimpleAggregatorTst {
12  
13  
14      public void testAll() {
15          runTests(new TestDescriptor[]{
16              new TestDescriptor(TEST1, "bad", 1, new SimplifyBooleanReturns()),
17              new TestDescriptor(TEST2, "bad", 1, new SimplifyBooleanReturns()),
18              new TestDescriptor(TEST3, "ok", 0, new SimplifyBooleanReturns()),
19          });
20      }
21  
22      private static final String TEST1 =
23              "public class Foo {" + PMD.EOL +
24              " public void foo() {   " + PMD.EOL +
25              "  if (true) {" + PMD.EOL +
26              "   return true;" + PMD.EOL +
27              "  } else {" + PMD.EOL +
28              "   return false;" + PMD.EOL +
29              "  }" + PMD.EOL +
30              " }" + PMD.EOL +
31              "}";
32  
33      private static final String TEST2 =
34              "public class Foo {" + PMD.EOL +
35              " public boolean foo() {        " + PMD.EOL +
36              "  if (true) " + PMD.EOL +
37              "   return true;" + PMD.EOL +
38              "   else " + PMD.EOL +
39              "  return false;" + PMD.EOL +
40              " }" + PMD.EOL +
41              "}";
42  
43      private static final String TEST3 =
44              "public class Foo {" + PMD.EOL +
45              " public Object foo() { " + PMD.EOL +
46              "  if (!true) {" + PMD.EOL +
47              "   return null;" + PMD.EOL +
48              "  } else {}" + PMD.EOL +
49              "  return null;" + PMD.EOL +
50              " }" + PMD.EOL +
51              "}";
52  
53  }