### Question:
DMNCanvasHandler extends CanvasHandlerImpl<D, C> { void updateDiagramId(final Element element) { final Object content = element.getContent(); if (content instanceof Definition) { final Object definition = ((Definition) content).getDefinition(); if (definition instanceof HasContentDefinitionId) { final HasContentDefinitionId hasContentDefinitionId = (HasContentDefinitionId) definition; if (Strings.isNullOrEmpty(hasContentDefinitionId.getDiagramId())) { hasContentDefinitionId.setDiagramId(getGraphsProvider().getCurrentDiagramId()); } } } } @Inject  DMNCanvasHandler(final ClientDefinitionManager clientDefinitionManager,
                            final CanvasCommandFactory<AbstractCanvasHandler> commandFactory,
                            final RuleManager ruleManager,
                            final GraphUtils graphUtils,
                            final GraphIndexBuilder<? extends MutableIndex<Node, Edge>> indexBuilder,
                            final ShapeManager shapeManager,
                            final TextPropertyProviderFactory textPropertyProviderFactory,
                            final Event<CanvasElementAddedEvent> canvasElementAddedEvent,
                            final Event<CanvasElementRemovedEvent> canvasElementRemovedEvent,
                            final Event<CanvasElementUpdatedEvent> canvasElementUpdatedEvent,
                            final Event<CanvasElementsClearEvent> canvasElementsClearEvent,
                            final DMNElementsSynchronizer dmnElementsSynchronizer,
                            final GraphsProvider graphsProvider); @Override @SuppressWarnings("unchecked") void addChild(final Element parent,
                         final Element child);  }### Answer:
@Test public void testUpdateDiagramIdWhenDiagramIdIsNull() { final String diagramId = "diagram id"; final HasContentDefinitionId hasContentDefinitionId = mock(HasContentDefinitionId.class); final Element element = getElementForTestUpdateDiagramId(diagramId, null, hasContentDefinitionId); canvasHandler.updateDiagramId(element); verify(hasContentDefinitionId).setDiagramId(diagramId); }
@Test public void testUpdateDiagramIdWhenDiagramIdIsSet() { final String diagramId = "diagram id"; final String currentDiagramId = "some set diagram"; final HasContentDefinitionId hasContentDefinitionId = mock(HasContentDefinitionId.class); final Element element = getElementForTestUpdateDiagramId(diagramId, currentDiagramId, hasContentDefinitionId); canvasHandler.updateDiagramId(element); verify(hasContentDefinitionId, never()).setDiagramId(anyString()); }
@Test public void testUpdateDiagramIdWhenDiagramIdIsEmpty() { final String diagramId = "diagram id"; final String currentDiagramId = ""; final HasContentDefinitionId hasContentDefinitionId = mock(HasContentDefinitionId.class); final Element element = getElementForTestUpdateDiagramId(diagramId, currentDiagramId, hasContentDefinitionId); canvasHandler.updateDiagramId(element); verify(hasContentDefinitionId).setDiagramId(diagramId); }