01: package test.net.sourceforge.pmd.ast;
02:
03: import static org.junit.Assert.assertTrue;
04: import net.sourceforge.pmd.PMD;
05: import net.sourceforge.pmd.ast.ASTAssignmentOperator;
06:
07: import org.junit.Test;
08:
09: import test.net.sourceforge.pmd.testframework.ParserTst;
10:
11: import java.util.Set;
12:
13: public class ASTAssignmentOperatorTest extends ParserTst {
14:
15: @Test
16: public void testSimpleAssignmentRecognized() throws Throwable {
17: Set ops = super .getNodes(ASTAssignmentOperator.class, TEST1);
18: assertTrue(!((ASTAssignmentOperator) (ops.iterator().next()))
19: .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()))
26: .isCompound());
27: }
28:
29: @Test
30: public void testCompoundAssignmentMultRecognized() throws Throwable {
31: Set ops = super .getNodes(ASTAssignmentOperator.class, TEST3);
32: assertTrue(((ASTAssignmentOperator) (ops.iterator().next()))
33: .isCompound());
34: }
35:
36: private static final String TEST1 = "public class Foo {" + PMD.EOL
37: + " void bar() {" + PMD.EOL + " int x;" + PMD.EOL
38: + " x=2;" + PMD.EOL + " }" + PMD.EOL + "}";
39:
40: private static final String TEST2 = "public class Foo {" + PMD.EOL
41: + " void bar() {" + PMD.EOL + " int x;" + PMD.EOL
42: + " x += 2;" + PMD.EOL + " }" + PMD.EOL + "}";
43:
44: private static final String TEST3 = "public class Foo {" + PMD.EOL
45: + " void bar() {" + PMD.EOL + " int x;" + PMD.EOL
46: + " x *= 2;" + PMD.EOL + " }" + PMD.EOL + "}";
47:
48: public static junit.framework.Test suite() {
49: return new junit.framework.JUnit4TestAdapter(
50: ASTAssignmentOperatorTest.class);
51: }
52: }
|