### Question:
AddChildNodeCommand extends AbstractGraphCompositeCommand { @SuppressWarnings("unchecked") protected AddChildNodeCommand initialize(final GraphCommandExecutionContext context) { super.initialize(context); final Node<?, Edge> parent = getParent(context); this.addCommand(getRegisterNodeCommand(candidate)); this.addCommand(getSetChildNodeCommand(parent, candidate)); if (null != location) { this.addCommand(getUpdateElementPositionCommand(candidate, location)); } return this; } AddChildNodeCommand(final @MapsTo("parentUUID") String parentUUID,
                               final @MapsTo("candidate") Node candidate,
                               final @MapsTo("location") Point2D location);  AddChildNodeCommand(final Node<?, Edge> parent,
                               final Node candidate,
                               final Point2D location);  AddChildNodeCommand(final Node<?, Edge> parent,
                               final Node candidate); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> allow(final GraphCommandExecutionContext context); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context); Node<?, Edge> getParent(); Node getCandidate(); Point2D getLocation(); @Override String toString();  }### Answer:
@Test @SuppressWarnings("unchecked") public void testInitializeCommands() { this.tested = spy(tested); tested.initialize(graphCommandExecutionContext); ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class); verify(tested, times(3)).addCommand(commandArgumentCaptor.capture()); List<Command> commands = commandArgumentCaptor.getAllValues(); assertNotNull(commands); assertTrue(commands.size() == 3); assertTrue(commands.get(0) instanceof RegisterNodeCommand); assertTrue(commands.get(1) instanceof SetChildrenCommand); assertTrue(commands.get(2) instanceof UpdateElementPositionCommand); }
@Test @SuppressWarnings("unchecked") public void testInitializeWithNoPositionCommands() { this.tested = spy(new AddChildNodeCommand(PARENT_UUID, candidate, null)); tested.initialize(graphCommandExecutionContext); ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class); verify(tested, times(2)).addCommand(commandArgumentCaptor.capture()); List<Command> commands = commandArgumentCaptor.getAllValues(); assertNotNull(commands); assertTrue(commands.size() == 2); assertTrue(commands.get(0) instanceof RegisterNodeCommand); assertTrue(commands.get(1) instanceof SetChildrenCommand); }