1 package test.net.sourceforge.pmd.symboltable;
2
3 import static org.junit.Assert.assertEquals;
4 import net.sourceforge.pmd.PMD;
5 import net.sourceforge.pmd.ast.ASTCompilationUnit;
6 import net.sourceforge.pmd.symboltable.ClassNameDeclaration;
7 import net.sourceforge.pmd.symboltable.Scope;
8
9 import org.junit.Test;
10
11 import java.util.Map;
12
13 public class GlobalScopeTest extends STBBaseTst {
14
15 @Test
16 public void testClassDeclAppears() {
17 parseCode(TEST1);
18 ASTCompilationUnit decl = acu.findChildrenOfType(ASTCompilationUnit.class).get(0);
19 Scope scope = decl.getScope();
20 Map m = scope.getClassDeclarations();
21 ClassNameDeclaration classNameDeclaration = (ClassNameDeclaration) m.keySet().iterator().next();
22 assertEquals(classNameDeclaration.getImage(), "Foo");
23 }
24
25 @Test
26 public void testEnums() {
27 parseCode15(TEST2);
28 }
29
30 private static final String TEST1 =
31 "public class Foo {}" + PMD.EOL;
32
33 private static final String TEST2 =
34 "public enum Bar {" + PMD.EOL +
35 " FOO1 { " + PMD.EOL +
36 " private static final String FIELD_NAME = \"\";" + PMD.EOL +
37 " }," + PMD.EOL +
38 " FOO2 { " + PMD.EOL +
39 " private static final String FIELD_NAME = \"\";" + PMD.EOL +
40 " }" + PMD.EOL +
41 "}" + PMD.EOL;
42
43 public static junit.framework.Test suite() {
44 return new junit.framework.JUnit4TestAdapter(GlobalScopeTest.class);
45 }
46 }