TernaryExpr extends Expr { @Override public void setChild(int index, Expr expr) { if (index == 0) { test = expr; return; } if (index == 1) { thenExpr = expr; return; } if (index == 2) { elseExpr = expr; return; } throw new IndexOutOfBoundsException("Index for TernaryExpr must be 0, 1 or 2"); } TernaryExpr(Expr test, Expr thenExpr, Expr elseExpr); Expr getTest(); Expr getThenExpr(); Expr getElseExpr(); @Override void accept(IAstVisitor visitor); @Override TernaryExpr 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 { TernaryExpr te = makeTernary(); te.setChild(0, elseVar); te.setChild(1, conditionVar); te.setChild(2, thenVar); assertEquals(elseVar, te.getTest()); assertEquals(conditionVar, te.getThenExpr()); assertEquals(thenVar, te.getElseExpr()); }
@Test(expected = IndexOutOfBoundsException.class) public void setChildBad() { makeTernary().setChild(3, conditionVar); }