View Javadoc

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