### Question:
AbstractAppendNodeShortcut implements KeyboardShortcut<AbstractCanvasHandler> { @Override public void executeAction(final AbstractCanvasHandler canvasHandler, final String selectedNodeId) { final Node sourceNode = CanvasLayoutUtils.getElement(canvasHandler, selectedNodeId).asNode(); final String definitionSetId = canvasHandler.getDiagram().getMetadata().getDefinitionSetId(); final CommonDomainLookups commonDomainLookups = toolboxDomainLookups.get(definitionSetId); final Set<String> connectorDefinitionIds = commonDomainLookups.lookupTargetConnectors(sourceNode); for (final String connectorDefinitionId : connectorDefinitionIds) { final Set<String> targetNodesDefinitionIds = commonDomainLookups.lookupTargetNodes(canvasHandler.getDiagram().getGraph(), sourceNode, connectorDefinitionId); for (final String targetNodeDefinitionId : targetNodesDefinitionIds) { final Object definition = definitionsCacheRegistry.getDefinitionById(targetNodeDefinitionId); if (canAppendNodeOfDefinition(definition)) { generalCreateNodeAction.executeAction(canvasHandler, selectedNodeId, targetNodeDefinitionId, connectorDefinitionId); break; } } } } AbstractAppendNodeShortcut(final ToolboxDomainLookups toolboxDomainLookups,
                                      final DefinitionsCacheRegistry definitionsCacheRegistry,
                                      final GeneralCreateNodeAction generalCreateNodeAction); @Override void executeAction(final AbstractCanvasHandler canvasHandler,
                              final String selectedNodeId); abstract boolean canAppendNodeOfDefinition(final Object definition);  }### Answer:
@Test public void testAppend() { final Object targetNodeDefinition = mock(Object.class); testedShortcut = new AbstractAppendNodeShortcutMock(targetNodeDefinition); selectedNodeId = "selected"; targetDefinitionNodeId = "target"; connectorDefinitionId = "connector"; definitionSetId = "definition"; when(canvasHandler.getGraphIndex()).thenReturn(graphIndex); when(canvasHandler.getDiagram()).thenReturn(diagram); when(diagram.getGraph()).thenReturn(graph); when(diagram.getMetadata()).thenReturn(metadata); when(metadata.getDefinitionSetId()).thenReturn(definitionSetId); final Element selectedElement = mock(Element.class); when(graphIndex.get(selectedNodeId)).thenReturn(selectedElement); final Node selectedNode = mock(Node.class); when(selectedElement.asNode()).thenReturn(selectedNode); when(toolboxDomainLookups.get(definitionSetId)).thenReturn(commonDomainLookups); final Set<String> connectorDefinitionIds = Collections.singleton(connectorDefinitionId); when(commonDomainLookups.lookupTargetConnectors(selectedNode)).thenReturn(connectorDefinitionIds); final Set<String> targetNodesDefinitionIds = Collections.singleton(targetDefinitionNodeId); when(commonDomainLookups.lookupTargetNodes(graph, selectedNode, connectorDefinitionId)).thenReturn(targetNodesDefinitionIds); when(definitionsCacheRegistry.getDefinitionById(targetDefinitionNodeId)).thenReturn(targetNodeDefinition); testedShortcut.executeAction(canvasHandler, selectedNodeId); verify(generalCreateNodeAction).executeAction(canvasHandler, selectedNodeId, targetDefinitionNodeId, connectorDefinitionId); reset(definitionsCacheRegistry); reset(generalCreateNodeAction); when(definitionsCacheRegistry.getDefinitionById(targetDefinitionNodeId)).thenReturn(new Object()); testedShortcut.executeAction(canvasHandler, selectedNodeId); verify(generalCreateNodeAction, never()).executeAction(any(), any(), any(), any()); }