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.ASTAssignmentOperator;
7   import net.sourceforge.pmd.testframework.ParserTst;
8   
9   import org.junit.Test;
10  
11  
12  import java.util.Set;
13  
14  public class ASTAssignmentOperatorTest extends ParserTst {
15  
16      @Test
17      public void testSimpleAssignmentRecognized() throws Throwable {
18          Set ops = super.getNodes(ASTAssignmentOperator.class, TEST1);
19          assertFalse(((ASTAssignmentOperator) (ops.iterator().next())).isCompound());
20      }
21  
22      @Test
23      public void testCompoundAssignmentPlusRecognized() throws Throwable {
24          Set ops = super.getNodes(ASTAssignmentOperator.class, TEST2);
25          assertTrue(((ASTAssignmentOperator) (ops.iterator().next())).isCompound());
26      }
27  
28      @Test
29      public void testCompoundAssignmentMultRecognized() throws Throwable {
30          Set ops = super.getNodes(ASTAssignmentOperator.class, TEST3);
31          assertTrue(((ASTAssignmentOperator) (ops.iterator().next())).isCompound());
32      }
33  
34      private static final String TEST1 =
35              "public class Foo {" + PMD.EOL +
36              " void bar() {" + PMD.EOL +
37              "  int x;" + PMD.EOL +
38              "  x=2;" + PMD.EOL +
39              " }" + PMD.EOL +
40              "}";
41  
42      private static final String TEST2 =
43              "public class Foo {" + PMD.EOL +
44              " void bar() {" + PMD.EOL +
45              "  int x;" + PMD.EOL +
46              "  x += 2;" + PMD.EOL +
47              " }" + PMD.EOL +
48              "}";
49  
50      private static final String TEST3 =
51              "public class Foo {" + PMD.EOL +
52              " void bar() {" + PMD.EOL +
53              "  int x;" + PMD.EOL +
54              "  x *= 2;" + PMD.EOL +
55              " }" + PMD.EOL +
56              "}";
57  
58      public static junit.framework.Test suite() {
59          return new junit.framework.JUnit4TestAdapter(ASTAssignmentOperatorTest.class);
60      }
61  }