UnaryExpr extends Expr { @Override public void setChild(int index, Expr expr) { if (index == 0) { this.expr = expr; return; } 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 setChild() throws Exception { assertEquals("~ x", expr.getText()); expr.setChild(0, new VariableIdentifierExpr("y")); assertEquals("~ y", expr.getText()); }
@Test(expected = IndexOutOfBoundsException.class) public void setChildBad() throws Exception { expr.setChild(-1, new IntConstantExpr("3")); }