01: package test.net.sourceforge.pmd.symboltable;
02:
03: import static org.junit.Assert.assertEquals;
04: import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;
05: import net.sourceforge.pmd.ast.SimpleJavaNode;
06: import net.sourceforge.pmd.symboltable.NameOccurrence;
07: import net.sourceforge.pmd.symboltable.VariableNameDeclaration;
08: import net.sourceforge.pmd.symboltable.VariableUsageFinderFunction;
09: import net.sourceforge.pmd.util.Applier;
10:
11: import org.junit.Test;
12:
13: import java.util.ArrayList;
14: import java.util.HashMap;
15: import java.util.List;
16: import java.util.Map;
17:
18: public class VariableUsageFinderFunctionTest {
19:
20: @Test
21: public void testLookingForUsed() {
22: ASTVariableDeclaratorId variableDeclarationIdNode = new ASTVariableDeclaratorId(
23: 1);
24: variableDeclarationIdNode.setImage("x");
25: VariableNameDeclaration nameDeclaration = new VariableNameDeclaration(
26: variableDeclarationIdNode);
27: List<NameOccurrence> nameOccurrences = new ArrayList<NameOccurrence>();
28: nameOccurrences.add(new NameOccurrence(new SimpleJavaNode(2),
29: "x"));
30:
31: Map<VariableNameDeclaration, List<NameOccurrence>> declarations = new HashMap<VariableNameDeclaration, List<NameOccurrence>>();
32: declarations.put(nameDeclaration, nameOccurrences);
33:
34: List<VariableNameDeclaration> vars = new ArrayList<VariableNameDeclaration>();
35: vars.add(nameDeclaration);
36:
37: VariableUsageFinderFunction f = new VariableUsageFinderFunction(
38: declarations);
39: Applier.apply(f, vars.iterator());
40: Map p = f.getUsed();
41: assertEquals(1, p.size());
42: }
43:
44: public static junit.framework.Test suite() {
45: return new junit.framework.JUnit4TestAdapter(
46: VariableUsageFinderFunctionTest.class);
47: }
48: }
|