### Question:
DeleteNodeToolboxAction implements ToolboxAction<AbstractCanvasHandler> { @Override @SuppressWarnings("unchecked") public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) { if (confirmDelete.test(this)) { final Metadata metadata = canvasHandler.getDiagram().getMetadata(); final Annotation qualifier = definitionUtils.getQualifier(metadata.getDefinitionSetId()); final CanvasCommandFactory<AbstractCanvasHandler> commandFactory = lookup(commandFactories, qualifier); final Node<?, Edge> node = CanvasLayoutUtils.getElement(canvasHandler, uuid).asNode(); clearSelectionEvent.fire(new CanvasClearSelectionEvent(canvasHandler)); sessionCommandManager.execute(canvasHandler, commandFactory.deleteNode(node)); } return this; } @Inject  DeleteNodeToolboxAction(final ClientTranslationService translationService,
                                   final SessionCommandManager<AbstractCanvasHandler> sessionCommandManager,
                                   final @Any ManagedInstance<DefaultCanvasCommandFactory> commandFactories,
                                   final DefinitionUtils definitionUtils,
                                   final Event<CanvasClearSelectionEvent> clearSelectionEvent);   DeleteNodeToolboxAction(final ClientTranslationService translationService,
                            final SessionCommandManager<AbstractCanvasHandler> sessionCommandManager,
                            final ManagedInstance<DefaultCanvasCommandFactory> commandFactories,
                            final DefinitionUtils definitionUtils,
                            final Predicate<DeleteNodeToolboxAction> confirmDelete,
                            final Event<CanvasClearSelectionEvent> clearSelectionEvent); @Override Glyph getGlyph(final AbstractCanvasHandler canvasHandler,
                          final String uuid); @Override String getTitle(final AbstractCanvasHandler canvasHandler,
                           final String uuid); @Override @SuppressWarnings("unchecked") ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler,
                                                             final String uuid,
                                                             final MouseClickEvent event); @PreDestroy void destroy();  }### Answer:
@Test public void testAction() { final MouseClickEvent event = mock(MouseClickEvent.class); final ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, E_UUID, event); assertEquals(tested, cascade); verify(commandFactory, times(1)).deleteNode(eq(element)); verify(sessionCommandManager, times(1)).execute(eq(canvasHandler), eq(deleteNodeCommand)); verify(clearSelectionEventEventSourceMock).fire(any(CanvasClearSelectionEvent.class)); }
@Test @SuppressWarnings("unchecked") public void testSkipAction() { this.tested = new DeleteNodeToolboxAction(translationService, sessionCommandManager, commandFactories, definitionUtils, action -> false, clearSelectionEventEventSourceMock); final MouseClickEvent event = mock(MouseClickEvent.class); final ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, E_UUID, event); assertEquals(tested, cascade); verify(sessionCommandManager, never()).execute(eq(canvasHandler), any(CanvasCommand.class)); verify(clearSelectionEventEventSourceMock, never()).fire(any(CanvasClearSelectionEvent.class)); }