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