### Question:
AddCanvasControlPointCommand extends AbstractCanvasCommand { @Override public CommandResult<CanvasViolation> allow(final AbstractCanvasHandler context) { checkAddControlPoint(getViewControlPoints(context, candidate), controlPoint, index); return CanvasCommandResultBuilder.SUCCESS; } AddCanvasControlPointCommand(final Edge candidate,
                                        final ControlPoint controlPoint,
                                        final int index); @Override CommandResult<CanvasViolation> allow(final AbstractCanvasHandler context); @Override CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context); @Override CommandResult<CanvasViolation> undo(AbstractCanvasHandler context); ControlPoint getControlPoint(); int getIndex(); static ControlPoint[] getControlPoints(final Edge edge); static void consumeControlPoints(final AbstractCanvasHandler context,
                                            final Edge edge,
                                            final Consumer<HasManageableControlPoints> consumer); static HasManageableControlPoints<?> getManageableControlPoints(final AbstractCanvasHandler context,
                                                                           final Edge candidate); static ControlPoint[] getViewControlPoints(final AbstractCanvasHandler context,
                                                      final Edge candidate); @Override String toString();  }### Answer:
@Test public void testAllow() { tested = new AddCanvasControlPointCommand(edge, newControlPoint, 0); CommandResult<CanvasViolation> result = tested.allow(canvasHandler); assertFalse(CommandUtils.isError(result)); tested = new AddCanvasControlPointCommand(edge, newControlPoint, 1); result = tested.allow(canvasHandler); assertFalse(CommandUtils.isError(result)); tested = new AddCanvasControlPointCommand(edge, newControlPoint, 2); result = tested.allow(canvasHandler); assertFalse(CommandUtils.isError(result)); assertFalse(CommandUtils.isError(result)); tested = new AddCanvasControlPointCommand(edge, newControlPoint, 3); result = tested.allow(canvasHandler); assertFalse(CommandUtils.isError(result)); }
@Test(expected = IllegalArgumentException.class) public void testInvalidCPIndex() { tested = new AddCanvasControlPointCommand(edge, newControlPoint, 4); tested.allow(canvasHandler); }
@Test(expected = IllegalArgumentException.class) public void testInvalidCP() { tested = new AddCanvasControlPointCommand(edge, newControlPoint, 2); newControlPoint.setLocation(null); tested.allow(canvasHandler); }