### Question:
ExpressionEditor implements ExpressionEditorView.Presenter { @Override public void handleCanvasElementUpdated(final CanvasElementUpdatedEvent event) { final Element<?> element = event.getElement(); if ((element instanceof Node)) { if (element.getContent() instanceof Definition) { final Definition definition = (Definition) element.getContent(); final Optional<Definitions> definitions = Optional.ofNullable(dmnGraphUtils.getModelDefinitions()); definitions.ifPresent(d -> { if (Objects.equals(d, definition.getDefinition())) { view.setReturnToLinkText(returnToLinkTextSupplier.get()); } }); hasExpression.ifPresent(e -> { if (Objects.equals(e.asDMNModelInstrumentedBase(), definition.getDefinition())) { view.setExpressionNameText(Optional.ofNullable((HasName) definition.getDefinition())); view.refresh(); } }); } } } @SuppressWarnings("unchecked")  ExpressionEditor(final ExpressionEditorView view,
                            final DecisionNavigatorPresenter decisionNavigator,
                            final DMNGraphUtils dmnGraphUtils,
                            final DMNDiagramsSession dmnDiagramsSession,
                            final DRDNameChanger drdNameChanger); @Override HTMLElement getElement(); @Override void bind(final DMNSession session); @Override ExpressionEditorView getView(); @Override void setToolbarStateHandler(final ToolbarStateHandler toolbarStateHandler); @Override void setExpression(final String nodeUUID,
                              final HasExpression hasExpression,
                              final Optional<HasName> hasName,
                              final boolean isOnlyVisualChangeAllowed); @Override void setExitCommand(final Command exitCommand); @Override void exit(); @Override void handleCanvasElementUpdated(final CanvasElementUpdatedEvent event); @Override boolean isActive();  }### Answer:
@Test public void testOnCanvasElementUpdated() { final CanvasElementUpdatedEvent event = new CanvasElementUpdatedEvent(canvasHandler, node); when(node.getContent()).thenReturn(definition); when(definition.getDefinition()).thenReturn(decision); setupExpression(decision, decision, toolbarStateHandler, false); testedEditor.handleCanvasElementUpdated(event); verify(view).setExpressionNameText(optionalHasNameCaptor.capture()); verify(view).refresh(); final Optional<HasName> optionalHasName = optionalHasNameCaptor.getValue(); assertTrue(optionalHasName.isPresent()); assertEquals(decision, optionalHasName.get()); }
@Test public void testOnCanvasElementUpdatedDefinitions() { final CanvasElementUpdatedEvent event = new CanvasElementUpdatedEvent(canvasHandler, node); final String NEW_DRG_NAME = "new-drg-name"; when(node.getContent()).thenReturn(definition); when(definition.getDefinition()).thenReturn(definitions); when(dmnDiagramsSession.isGlobalGraphSelected()).thenReturn(true); setupExpression(decision, decision, toolbarStateHandler, false); verify(view).setReturnToLinkText(eq(DRG_NAME)); this.definitions.getName().setValue(NEW_DRG_NAME); testedEditor.handleCanvasElementUpdated(event); verify(view).setReturnToLinkText(eq(NEW_DRG_NAME)); }
@Test public void testOnCanvasElementUpdatedBusinessKnowledgeModel() { final BusinessKnowledgeModel bkm = new BusinessKnowledgeModel(); final CanvasElementUpdatedEvent event = new CanvasElementUpdatedEvent(canvasHandler, node); when(node.getContent()).thenReturn(definition); when(definition.getDefinition()).thenReturn(bkm); setupExpression(bkm.asHasExpression(), bkm, toolbarStateHandler, false); testedEditor.handleCanvasElementUpdated(event); verify(view).setExpressionNameText(optionalHasNameCaptor.capture()); verify(view).refresh(); final Optional<HasName> optionalHasName = optionalHasNameCaptor.getValue(); assertTrue(optionalHasName.isPresent()); assertEquals(bkm, optionalHasName.get()); }
@Test @SuppressWarnings("unchecked") public void testOnCanvasElementUpdatedDifferentNode() { final CanvasElementUpdatedEvent event = new CanvasElementUpdatedEvent(canvasHandler, node); final Decision differentNodeDefinition = mock(Decision.class); when(node.getContent()).thenReturn(definition); when(definition.getDefinition()).thenReturn(differentNodeDefinition); setupExpression(decision, decision, toolbarStateHandler, false); testedEditor.handleCanvasElementUpdated(event); verify(view, never()).setExpressionNameText(any(Optional.class)); }