    1   package test.net.sourceforge.pmd.symboltable;
    2
    3   import junit.framework.TestCase;
    4   import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;
    5   import net.sourceforge.pmd.ast.SimpleJavaNode;
    6   import net.sourceforge.pmd.symboltable.NameDeclaration;
    7   import net.sourceforge.pmd.symboltable.NameOccurrence;
    8   import net.sourceforge.pmd.symboltable.VariableNameDeclaration;
    9   import net.sourceforge.pmd.symboltable.VariableUsageFinderFunction;
    10  import net.sourceforge.pmd.util.Applier;
    11
    12  import java.util.ArrayList;
    13  import java.util.HashMap;
    14  import java.util.List;
    15  import java.util.Map;
    16
    17  public class VariableUsageFinderFunctionTest extends TestCase {
    18
    19      public void testLookingForUsed() {
    20          ASTVariableDeclaratorId variableDeclarationIdNode = new ASTVariableDeclaratorId(1);
    21          variableDeclarationIdNode.setImage("x");
    22          NameDeclaration nameDeclaration = new VariableNameDeclaration(variableDeclarationIdNode);
    23          List nameOccurrences = new ArrayList();
    24          nameOccurrences.add(new NameOccurrence(new SimpleJavaNode(2), "x"));
    25
    26          Map declarations = new HashMap();
    27          declarations.put(nameDeclaration, nameOccurrences);
    28
    29          List vars = new ArrayList();
    30          vars.add(nameDeclaration);
    31
    32          VariableUsageFinderFunction f = new VariableUsageFinderFunction(declarations);
    33          Applier.apply(f, vars.iterator());
    34          Map p = f.getUsed();
    35          assertEquals(1, p.size());
    36      }
    37  }