View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.ast.xpath;
5   
6   import java.util.HashMap;
7   import java.util.Map;
8   
9   import net.sourceforge.pmd.lang.java.ast.DummyJavaNode;
10  
11  import org.junit.Assert;
12  import org.junit.Test;
13  
14  /**
15   * Unit test for {@link AttributeAxisIterator}
16   */
17  public class AttributeAxisIteratorTest {
18  
19      /**
20       * Test hasNext and next.
21       */
22      @Test
23      public void testAttributeAxisIterator() {
24          DummyJavaNode dummyNode = new DummyJavaNode(1);
25          dummyNode.testingOnly__setBeginLine(1);
26          dummyNode.testingOnly__setBeginColumn(1);
27  
28          AttributeAxisIterator it = new AttributeAxisIterator(dummyNode);
29          Map<String, Attribute> atts = new HashMap<String, Attribute>();
30          while (it.hasNext()) {
31              Attribute attribute = it.next();
32              atts.put(attribute.getName(), attribute);
33          }
34          Assert.assertEquals(7, atts.size());
35          Assert.assertTrue(atts.containsKey("BeginColumn"));
36          Assert.assertTrue(atts.containsKey("BeginLine"));
37          Assert.assertTrue(atts.containsKey("FindBoundary"));
38          Assert.assertTrue(atts.containsKey("Image"));
39          Assert.assertTrue(atts.containsKey("SingleLine"));
40          Assert.assertTrue(atts.containsKey("EndColumn"));
41          Assert.assertTrue(atts.containsKey("EndLine"));
42      }
43  }