1
2
3
4 package net.sourceforge.pmd.lang.ast.xpath;
5
6 import static org.junit.Assert.assertNotNull;
7 import static org.junit.Assert.assertSame;
8 import static org.junit.Assert.fail;
9 import net.sourceforge.pmd.lang.ast.DummyNode;
10 import net.sourceforge.pmd.lang.ast.Node;
11 import net.sourceforge.pmd.lang.ast.RootNode;
12
13 import org.junit.Test;
14
15
16
17
18 public class DocumentNavigatorTest {
19
20 private static class DummyRootNode extends DummyNode implements RootNode {
21 public DummyRootNode(int id) {
22 super(id);
23 }
24 }
25
26 @Test
27 public void getDocumentNode() {
28 DocumentNavigator nav = new DocumentNavigator();
29
30 try {
31 nav.getDocumentNode(null);
32 fail();
33 } catch (RuntimeException e) {
34 assertNotNull(e);
35 }
36
37 Node root = new DummyRootNode(1);
38 Node n = new DummyNode(1);
39 root.jjtAddChild(n, 0);
40 n.jjtSetParent(root);
41 assertSame(root, nav.getDocumentNode(n));
42 }
43 }