AstNodeXPathQuery { public T selectSingleNode(AstNode astNode) { try { astNodeNavigator.reset(); return (T) expression.selectSingleNode(astNode); } catch (JaxenException e) { throw new RuntimeException(e); } } private  AstNodeXPathQuery(String xpath); T selectSingleNode(AstNode astNode); List<T> selectNodes(AstNode astNode); static AstNodeXPathQuery<E> create(String xpath);  }
@Test public void selectSingleNodeTest() { AstNodeXPathQuery<AstNode> expr = AstNodeXPathQuery.create("branch/leaf"); AstNode tree = new AstNode(new NodeType(), "tree", null); AstNode branch = new AstNode(new NodeType(), "branch", null); AstNode leaf = new AstNode(new NodeType(), "leaf", null); tree.addChild(branch); branch.addChild(leaf); assertThat(expr.selectSingleNode(tree)).isEqualTo(leaf); }