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.SimpleAggregatorTst;
10  import test.net.sourceforge.pmd.testframework.TestDescriptor;
11  
12  public class SwitchStmtsShouldHaveDefaultRuleTest extends SimpleAggregatorTst {
13  
14      private Rule rule;
15  
16      public void setUp() throws RuleSetNotFoundException {
17          rule = findRule("design", "SwitchStmtsShouldHaveDefault");
18      }
19  
20      public void testAll() {
21         runTests(new TestDescriptor[] {
22             new TestDescriptor(TEST1, "simple failure case", 1, rule),
23             new TestDescriptor(TEST2, "simple ok case", 0, rule)
24         });
25      }
26  
27      private static final String TEST1 =
28      "public class Foo {" + PMD.EOL +
29      " void bar() {" + PMD.EOL +
30      "  int x = 2;" + PMD.EOL +
31      "  switch (x) {" + PMD.EOL +
32      "   case 2: int y=8;" + PMD.EOL +
33      "  }" + PMD.EOL +
34      " }" + PMD.EOL +
35      "}";
36  
37      private static final String TEST2 =
38      "public class Foo {" + PMD.EOL +
39      " void bar() {" + PMD.EOL +
40      "  int x = 2;" + PMD.EOL +
41      "  switch (x) {" + PMD.EOL +
42      "   case 2: int y=8;" + PMD.EOL +
43      "   default: int j=8;" + PMD.EOL +
44      "  }" + PMD.EOL +
45      " }" + PMD.EOL +
46      "}";
47  
48  
49  }