View Javadoc

1   package net.sourceforge.pmd.ast;
2   
3   import static org.junit.Assert.assertFalse;
4   import static org.junit.Assert.assertTrue;
5   import net.sourceforge.pmd.PMD;
6   import net.sourceforge.pmd.lang.java.ast.ASTSwitchLabel;
7   import net.sourceforge.pmd.testframework.ParserTst;
8   
9   import org.junit.Test;
10  
11  
12  import java.util.Set;
13  
14  public class ASTSwitchLabelTest extends ParserTst {
15  
16      @Test
17      public void testDefaultOff() throws Throwable {
18          Set ops = getNodes(ASTSwitchLabel.class, TEST1);
19          assertFalse(((ASTSwitchLabel) (ops.iterator().next())).isDefault());
20      }
21  
22      @Test
23      public void testDefaultSet() throws Throwable {
24          Set ops = getNodes(ASTSwitchLabel.class, TEST2);
25          assertTrue(((ASTSwitchLabel) (ops.iterator().next())).isDefault());
26      }
27  
28  
29      private static final String TEST1 =
30              "public class Foo {" + PMD.EOL +
31              " void bar() {" + PMD.EOL +
32              "  switch (x) {" + PMD.EOL +
33              "   case 1: y = 2;" + PMD.EOL +
34              "  }" + PMD.EOL +
35              " }" + PMD.EOL +
36              "}";
37  
38      private static final String TEST2 =
39              "public class Foo {" + PMD.EOL +
40              " void bar() {" + PMD.EOL +
41              "  switch (x) {" + PMD.EOL +
42              "   default: y = 2;" + PMD.EOL +
43              "  }" + PMD.EOL +
44              " }" + PMD.EOL +
45              "}";
46  
47      public static junit.framework.Test suite() {
48          return new junit.framework.JUnit4TestAdapter(ASTSwitchLabelTest.class);
49      }
50  }