### Question:
DeleteControlPointCommand extends AbstractControlPointCommand { @Override public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { check(context); final HasControlPoints edgeControlPoints = getEdgeControlPoints(context); final int size = edgeControlPoints.getControlPoints().length; final ControlPoint[] cps = new ControlPoint[size - 1]; for (int i = 0, j = 0; i < size; i++, j++) { ControlPoint controlPoint = edgeControlPoints.getControlPoints()[i]; if (i == index) { j--; deletedControlPoint = controlPoint; } else { cps[j] = controlPoint; } } edgeControlPoints.setControlPoints(cps); return GraphCommandResultBuilder.SUCCESS; } DeleteControlPointCommand(final @MapsTo("edgeUUID") String edgeUUID,
                                     final @MapsTo("index") int index); @Override CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context); @Override CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testInvalidIndexDuringExecute() { tested = new DeleteControlPointCommand(EDGE_UUID, -1); tested.execute(graphCommandExecutionContext); }
@Test(expected = IllegalArgumentException.class) public void testIndexForbiddenDuringExecute() { tested = new DeleteControlPointCommand(EDGE_UUID, 3); tested.execute(graphCommandExecutionContext); }
@Test public void testDeleteControlPointAt0() { tested = new DeleteControlPointCommand(EDGE_UUID, 0); CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext); ArgumentCaptor<ControlPoint[]> pointsCaptor = ArgumentCaptor.forClass(ControlPoint[].class); assertFalse(CommandUtils.isError(result)); verify(viewConnector, times(1)).setControlPoints(pointsCaptor.capture()); ControlPoint[] controlPoints = pointsCaptor.getValue(); assertNotNull(controlPoints); assertEquals(2, controlPoints.length); assertEquals(controlPoint2, controlPoints[0]); assertEquals(controlPoint3, controlPoints[1]); }
@Test public void testDeleteControlPointAt1() { tested = new DeleteControlPointCommand(EDGE_UUID, 1); CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext); ArgumentCaptor<ControlPoint[]> pointsCaptor = ArgumentCaptor.forClass(ControlPoint[].class); assertFalse(CommandUtils.isError(result)); verify(viewConnector, times(1)).setControlPoints(pointsCaptor.capture()); ControlPoint[] controlPoints = pointsCaptor.getValue(); assertNotNull(controlPoints); assertEquals(2, controlPoints.length); assertEquals(controlPoint1, controlPoints[0]); assertEquals(controlPoint3, controlPoints[1]); }
@Test public void testDeleteControlPointAt2() { tested = new DeleteControlPointCommand(EDGE_UUID, 2); CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext); ArgumentCaptor<ControlPoint[]> pointsCaptor = ArgumentCaptor.forClass(ControlPoint[].class); assertFalse(CommandUtils.isError(result)); verify(viewConnector, times(1)).setControlPoints(pointsCaptor.capture()); ControlPoint[] controlPoints = pointsCaptor.getValue(); assertNotNull(controlPoints); assertEquals(2, controlPoints.length); assertEquals(controlPoint1, controlPoints[0]); assertEquals(controlPoint2, controlPoints[1]); }