### Question:
TwigQuery extends NodeQuery { @Override public void setAncestorPointer(final NodeQuery ancestor) { super.setAncestorPointer(ancestor); root.setAncestorPointer(ancestor); } TwigQuery(final int rootLevel);  TwigQuery(); static int getMaxClauseCount(); static void setMaxClauseCount(final int maxClauseCount); void addRoot(final NodeQuery root); void addChild(final NodeQuery query, final NodeBooleanClause.Occur occur); void addDescendant(final int nodeLevel, final NodeQuery query,
                            final NodeBooleanClause.Occur occur); @Override void setAncestorPointer(final NodeQuery ancestor); @Override void setNodeConstraint(final int lowerBound, final int upperBound); @Override void setLevelConstraint(final int levelConstraint); NodeQuery getRoot(); NodeBooleanClause[] getClauses(); List<NodeBooleanClause> clauses(); final Iterator<NodeBooleanClause> iterator(); @Override Weight createWeight(final IndexSearcher searcher); @Override Query rewrite(final IndexReader reader); @Override void extractTerms(final Set<Term> terms); @Override @SuppressWarnings("unchecked") Query clone(); @Override String toString(final String field); @Override boolean equals(final Object o); @Override int hashCode();  }### Answer:
@Test public void testSetAncestorPointer() { final NodeTermQuery term = new NodeTermQuery(new Term("field", "value")); final TwigQuery tq1 = new TwigQuery(); tq1.addDescendant(2, term, Occur.MUST); assertSame(tq1.getRoot(), term.ancestor); assertNull(tq1.ancestor); final TwigQuery tq2 = new TwigQuery(); tq2.addChild(tq1, Occur.MUST); assertSame(tq2.getRoot(), tq1.ancestor); assertSame(tq2.getRoot(), tq1.getRoot().ancestor); assertEquals(4, tq1.clauses().get(0).getQuery().getLevelConstraint()); final TwigQuery tq3 = new TwigQuery(3); tq3.addRoot(tq2); assertSame(tq3.ancestor, tq2.ancestor); assertSame(tq2.ancestor, tq2.getRoot().ancestor); }