### Question:
TwigQuery extends NodeQuery { @Override public void setLevelConstraint(final int levelConstraint) { final int oldLevelConstraint = this.levelConstraint; super.setLevelConstraint(levelConstraint); root.setLevelConstraint(levelConstraint); NodeQuery q; for (final NodeBooleanClause clause : clauses) { q = clause.getQuery(); final int levelDelta = q.getLevelConstraint() - oldLevelConstraint; q.setLevelConstraint(levelConstraint + levelDelta); } } 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 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 @SuppressWarnings("unchecked") Query clone(); @Override String toString(final String field); @Override boolean equals(final Object o); @Override int hashCode();  }### Answer:
@Test public void testSetLevelConstraint() { final TwigQuery tq1 = new TwigQuery(2); tq1.addDescendant(2, new NodeTermQuery(new Term("field", "value")), Occur.MUST); assertEquals(2, tq1.getLevelConstraint()); assertEquals(4, tq1.clauses().get(0).getQuery().getLevelConstraint()); tq1.setLevelConstraint(3); assertEquals(3, tq1.getLevelConstraint()); assertEquals(5, tq1.clauses().get(0).getQuery().getLevelConstraint()); final TwigQuery tq2 = new TwigQuery(); tq2.addChild(tq1, Occur.MUST); assertEquals(2, tq1.getLevelConstraint()); assertEquals(4, tq1.clauses().get(0).getQuery().getLevelConstraint()); final TwigQuery tq3 = new TwigQuery(3); tq3.addRoot(tq2); assertEquals(3, tq2.getLevelConstraint()); assertEquals(4, tq1.getLevelConstraint()); assertEquals(6, tq1.clauses().get(0).getQuery().getLevelConstraint()); }