@Test public void testAddControlPointFirstTime() { when(viewConnector.getControlPoints()).thenReturn(null); tested = new AddControlPointCommand(EDGE_UUID, newControlPoint, 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(1, controlPoints.length); assertEquals(newControlPoint, controlPoints[0]); }
@Override public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { check(context); final HasControlPoints edgeControlPoints = getEdgeControlPoints(context); final int size = Objects.isNull(edgeControlPoints.getControlPoints()) ? 0 : edgeControlPoints.getControlPoints().length; final ControlPoint[] cps = new ControlPoint[size + 1]; for (int i = 0; i < size + 1; i++) { if (i < index) { cps[i] = edgeControlPoints.getControlPoints()[i]; } else if (i == index) { cps[i] = controlPoint; } else { cps[i] = edgeControlPoints.getControlPoints()[i - 1]; } } edgeControlPoints.setControlPoints(cps); return GraphCommandResultBuilder.SUCCESS; }
AddControlPointCommand extends AbstractControlPointCommand { @Override public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { check(context); final HasControlPoints edgeControlPoints = getEdgeControlPoints(context); final int size = Objects.isNull(edgeControlPoints.getControlPoints()) ? 0 : edgeControlPoints.getControlPoints().length; final ControlPoint[] cps = new ControlPoint[size + 1]; for (int i = 0; i < size + 1; i++) { if (i < index) { cps[i] = edgeControlPoints.getControlPoints()[i]; } else if (i == index) { cps[i] = controlPoint; } else { cps[i] = edgeControlPoints.getControlPoints()[i - 1]; } } edgeControlPoints.setControlPoints(cps); return GraphCommandResultBuilder.SUCCESS; } }
AddControlPointCommand extends AbstractControlPointCommand { @Override public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { check(context); final HasControlPoints edgeControlPoints = getEdgeControlPoints(context); final int size = Objects.isNull(edgeControlPoints.getControlPoints()) ? 0 : edgeControlPoints.getControlPoints().length; final ControlPoint[] cps = new ControlPoint[size + 1]; for (int i = 0; i < size + 1; i++) { if (i < index) { cps[i] = edgeControlPoints.getControlPoints()[i]; } else if (i == index) { cps[i] = controlPoint; } else { cps[i] = edgeControlPoints.getControlPoints()[i - 1]; } } edgeControlPoints.setControlPoints(cps); return GraphCommandResultBuilder.SUCCESS; } AddControlPointCommand(final @MapsTo("edgeUUID") String edgeUUID,
                                  final @MapsTo("controlPoint") ControlPoint controlPoint,
                                  final @MapsTo("index") int index); }
AddControlPointCommand extends AbstractControlPointCommand { @Override public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { check(context); final HasControlPoints edgeControlPoints = getEdgeControlPoints(context); final int size = Objects.isNull(edgeControlPoints.getControlPoints()) ? 0 : edgeControlPoints.getControlPoints().length; final ControlPoint[] cps = new ControlPoint[size + 1]; for (int i = 0; i < size + 1; i++) { if (i < index) { cps[i] = edgeControlPoints.getControlPoints()[i]; } else if (i == index) { cps[i] = controlPoint; } else { cps[i] = edgeControlPoints.getControlPoints()[i - 1]; } } edgeControlPoints.setControlPoints(cps); return GraphCommandResultBuilder.SUCCESS; } AddControlPointCommand(final @MapsTo("edgeUUID") String edgeUUID,
                                  final @MapsTo("controlPoint") ControlPoint controlPoint,
                                  final @MapsTo("index") int index); @Override CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context); @Override CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context); }
AddControlPointCommand extends AbstractControlPointCommand { @Override public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { check(context); final HasControlPoints edgeControlPoints = getEdgeControlPoints(context); final int size = Objects.isNull(edgeControlPoints.getControlPoints()) ? 0 : edgeControlPoints.getControlPoints().length; final ControlPoint[] cps = new ControlPoint[size + 1]; for (int i = 0; i < size + 1; i++) { if (i < index) { cps[i] = edgeControlPoints.getControlPoints()[i]; } else if (i == index) { cps[i] = controlPoint; } else { cps[i] = edgeControlPoints.getControlPoints()[i - 1]; } } edgeControlPoints.setControlPoints(cps); return GraphCommandResultBuilder.SUCCESS; } AddControlPointCommand(final @MapsTo("edgeUUID") String edgeUUID,
                                  final @MapsTo("controlPoint") ControlPoint controlPoint,
                                  final @MapsTo("index") int index); @Override CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context); @Override CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context);  }