UnaryExpr extends Expr { @Override public Expr getChild(int index) { if (index == 0) { return expr; } throw new IndexOutOfBoundsException("Index for UnaryExpr must be 0"); } UnaryExpr(Expr expr, UnOp op); Expr getExpr(); UnOp getOp(); @Override void accept(IAstVisitor visitor); @Override UnaryExpr clone(); @Override boolean hasChild(IAstNode candidateChild); @Override Expr getChild(int index); @Override void setChild(int index, Expr expr); @Override int getNumChildren();  }
@Test public void getChild() throws Exception { assertTrue(expr.getChild(0) instanceof VariableIdentifierExpr); assertEquals("x", expr.getChild(0).getText()); }
@Test(expected = IndexOutOfBoundsException.class) public void getChildBad() throws Exception { expr.getChild(1); }