    1   package test.net.sourceforge.pmd.rules;
    2
    3   import net.sourceforge.pmd.PMD;
    4   import net.sourceforge.pmd.Rule;
    5   import net.sourceforge.pmd.RuleSetNotFoundException;
    6   import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
    7   import test.net.sourceforge.pmd.testframework.TestDescriptor;
    8
    9   public class DefaultLabelNotLastInSwitchStmtRuleTest extends SimpleAggregatorTst {
    10
    11      private Rule rule;
    12
    13      public void setUp() throws RuleSetNotFoundException {
    14          rule = findRule("design", "DefaultLabelNotLastInSwitchStmt");
    15      }
    16
    17      public void testAll() {
    18          runTests(new TestDescriptor[]{
    19              new TestDescriptor(TEST1, "ok", 0, rule),
    20              new TestDescriptor(TEST2, "bad", 1, rule),
    21              new TestDescriptor(TEST3, "ok, no default", 0, rule),
    22          });
    23      }
    24
    25      private static final String TEST1 =
    26              "public class Foo {" + PMD.EOL +
    27              " void bar(int x) {" + PMD.EOL +
    28              "  switch(x) { " + PMD.EOL +
    29              "  case 1: " + PMD.EOL +
    30              "   break; " + PMD.EOL +
    31              "  default:" + PMD.EOL +
    32              "   break;" + 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(int x) {" + PMD.EOL +
    40              "  switch(x) { " + PMD.EOL +
    41              "  case 1: " + PMD.EOL +
    42              "   break; " + PMD.EOL +
    43              "  default:" + PMD.EOL +
    44              "   break;" + PMD.EOL +
    45              "  case 2: " + PMD.EOL +
    46              "   break; " + PMD.EOL +
    47              "  }" + PMD.EOL +
    48              " }" + PMD.EOL +
    49              "}";
    50
    51      private static final String TEST3 =
    52              "public class Foo {" + PMD.EOL +
    53              " void bar(int x) {" + PMD.EOL +
    54              "  switch(x) { " + PMD.EOL +
    55              "  case 1: " + PMD.EOL +
    56              "   break; " + PMD.EOL +
    57              "  case 2: " + PMD.EOL +
    58              "   break; " + PMD.EOL +
    59              "  }" + PMD.EOL +
    60              " }" + PMD.EOL +
    61              "}";
    62
    63  }