### Question:
Unit { public void accept(UnitVisitor visitor) { for (Unit child : children) { child.accept(visitor); } } Unit(Unit... children); void accept(UnitVisitor visitor);  }### Answer:
@Test public void testAccept() { final Unit[] children = new Unit[5]; Arrays.setAll(children, (i) -> mock(Unit.class)); final U unit = this.factory.apply(children); final UnitVisitor visitor = mock(UnitVisitor.class); unit.accept(visitor); verifyVisit(unit, visitor); for (final Unit child : children) { verify(child).accept(eq(visitor)); } verifyNoMoreInteractions(children); verifyNoMoreInteractions(visitor); }
@Test public void testAccept() throws Exception { final Unit[] children = new Unit[5]; Arrays.setAll(children, (i) -> mock(Unit.class)); final U unit = this.factory.apply(children); final UnitVisitor visitor = mock(UnitVisitor.class); unit.accept(visitor); verifyVisit(unit, visitor); for (final Unit child : children) { verify(child).accept(eq(visitor)); } verifyNoMoreInteractions(children); verifyNoMoreInteractions(visitor); }