### Question:
SetConnectionTargetNodeCommand extends AbstractGraphCommand { @Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { final CommandResult<RuleViolation> results = allow(context); if (!results.getType().equals(CommandResult.Type.ERROR)) { final Edge<? extends View, Node> edge = getEdge(context); final Node<?, Edge> targetNode = getTargetNode(context); final Node<? extends View<?>, Edge> lastTargetNode = edge.getTargetNode(); if (null != lastTargetNode) { lastTargetNodeUUID = lastTargetNode.getUUID(); lastTargetNode.getInEdges().remove(edge); } if (null != targetNode) { targetNode.getInEdges().add(edge); } edge.setTargetNode(targetNode); ViewConnector connectionContent = (ViewConnector) edge.getContent(); lastConnection = (Connection) connectionContent.getTargetConnection().orElse(null); connectionContent.setTargetConnection(connection); } return results; } @SuppressWarnings("unchecked")  SetConnectionTargetNodeCommand(final @MapsTo("targetNodeUUID") String targetNodeUUID,
                                          final @MapsTo("edgeUUID") String edgeUUID,
                                          final @MapsTo("magnet") Connection connection); @SuppressWarnings("unchecked")  SetConnectionTargetNodeCommand(final Node<? extends View<?>, Edge> targetNode,
                                          final Edge<? extends View, Node> edge,
                                          final Connection connection); @SuppressWarnings("unchecked")  SetConnectionTargetNodeCommand(final Node<? extends View<?>, Edge> targetNode,
                                          final Edge<? extends View, Node> edge); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context); Edge<? extends View, Node> getEdge(); Connection getConnection(); Node<? extends View<?>, Edge> getTargetNode(); Node<? extends View<?>, Edge> getSourceNode(); @Override String toString();  }### Answer:
@Test @SuppressWarnings("unchecked") public void testExecute() { final List lastTargetInEdges = spy(new ArrayList()); final List sourceOutEdges = spy(new ArrayList()); final List targetInEdges = spy(new ArrayList()); when(source.getOutEdges()).thenReturn(sourceOutEdges); when(lastTargetNode.getInEdges()).thenReturn(lastTargetInEdges); when(node.getInEdges()).thenReturn(targetInEdges); CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext); final ArgumentCaptor<RuleEvaluationContext> contextCaptor = ArgumentCaptor.forClass(RuleEvaluationContext.class); verify(ruleManager, times(3)).evaluate(eq(ruleSet), contextCaptor.capture()); final List<RuleEvaluationContext> contexts = contextCaptor.getAllValues(); assertEquals(3, contexts.size()); verifyConnection((GraphConnectionContext) contexts.get(0), edge, source, node); verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(1), graph, lastTargetNode, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.DELETE)); verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(2), graph, node, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.ADD)); assertEquals(CommandResult.Type.INFO, result.getType()); verify(lastTargetInEdges, times(1)).remove(eq(edge)); verify(targetInEdges, times(1)).add(eq(edge)); verify(edgeContent, times(1)).setTargetConnection(any(Connection.class)); verify(edge, times(1)).setTargetNode(eq(node)); verify(targetInEdges, times(0)).remove(any(Edge.class)); verify(sourceOutEdges, times(0)).add(any(Edge.class)); verify(graphIndex, times(0)).removeEdge(any(Edge.class)); verify(graphIndex, times(0)).addEdge(any(Edge.class)); verify(graphIndex, times(0)).addNode(any(Node.class)); verify(graphIndex, times(0)).removeNode(any(Node.class)); }