1 package test.net.sourceforge.pmd.symboltable;
2
3 import static org.junit.Assert.assertEquals;
4
5 import java.util.Iterator;
6 import java.util.List;
7 import java.util.Map;
8 import java.util.Set;
9
10 import net.sourceforge.pmd.PMD;
11 import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
12 import net.sourceforge.pmd.symboltable.ClassScope;
13 import net.sourceforge.pmd.symboltable.MethodNameDeclaration;
14 import net.sourceforge.pmd.symboltable.NameOccurrence;
15
16 import org.junit.Test;
17
18 public class MethodNameDeclarationTest extends STBBaseTst {
19
20 @Test
21 public void testEquality() {
22
23 parseCode15(SIMILAR);
24 ASTClassOrInterfaceDeclaration n = acu.findChildrenOfType(ASTClassOrInterfaceDeclaration.class).get(0);
25 Map<MethodNameDeclaration, List<NameOccurrence>> m = ((ClassScope) n.getScope()).getMethodDeclarations();
26 Set<MethodNameDeclaration> methodNameDeclarations = m.keySet();
27 assertEquals("Wrong number of method name declarations", methodNameDeclarations.size(), 3);
28 }
29
30 private static final String SIMILAR =
31 "public class Foo {" + PMD.EOL +
32 " public void bar() {" + PMD.EOL +
33 " bar(x, y);" + PMD.EOL +
34 " }" + PMD.EOL +
35 " private void bar(int x, int y) {}" + PMD.EOL +
36 " private void bar(int x, int... y) {}" + PMD.EOL +
37 "}";
38
39 public static junit.framework.Test suite() {
40 return new junit.framework.JUnit4TestAdapter(MethodNameDeclarationTest.class);
41 }
42 }