### Question:
DMNEditBusinessKnowledgeModelToolboxAction implements ToolboxAction<AbstractCanvasHandler> { @Override @SuppressWarnings("unchecked") public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) { final Node<View<? extends BusinessKnowledgeModel>, Edge> bkmNode = (Node<View<? extends BusinessKnowledgeModel>, Edge>) CanvasLayoutUtils.getElement(canvasHandler, uuid) .asNode(); final BusinessKnowledgeModel bkm = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(bkmNode); final boolean isOnlyVisualChangeAllowed = bkm.isAllowOnlyVisualChange(); editExpressionEvent.fire(new EditExpressionEvent(sessionManager.getCurrentSession(), uuid, bkm.asHasExpression(), Optional.of(bkm), isOnlyVisualChangeAllowed)); return this; } @Inject  DMNEditBusinessKnowledgeModelToolboxAction(final SessionManager sessionManager,
                                                      final ClientTranslationService translationService,
                                                      final Event<EditExpressionEvent> editExpressionEvent); @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);  }### Answer:
@Test public void testAction() { final ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, E_UUID, mouseClickEvent); assertEquals(tested, cascade); final ArgumentCaptor<EditExpressionEvent> eventCaptor = ArgumentCaptor.forClass(EditExpressionEvent.class); verify(editExpressionEvent, times(1)).fire(eventCaptor.capture()); final EditExpressionEvent editExprEvent = eventCaptor.getValue(); assertEquals(E_UUID, editExprEvent.getNodeUUID()); final HasExpression hasExpression = editExprEvent.getHasExpression(); assertEquals(bkm.getEncapsulatedLogic(), hasExpression.getExpression()); assertEquals(bkm, hasExpression.asDMNModelInstrumentedBase()); assertFalse(hasExpression.isClearSupported()); assertEquals(bkm, editExprEvent.getHasName().get()); assertEquals(session, editExprEvent.getSession()); assertFalse(editExprEvent.isOnlyVisualChangeAllowed()); }
@Test public void testActionSetExpression() { tested.onMouseClick(canvasHandler, E_UUID, mouseClickEvent); final ArgumentCaptor<EditExpressionEvent> eventCaptor = ArgumentCaptor.forClass(EditExpressionEvent.class); verify(editExpressionEvent, times(1)).fire(eventCaptor.capture()); final EditExpressionEvent editExprEvent = eventCaptor.getValue(); final HasExpression hasExpression = editExprEvent.getHasExpression(); Assertions.assertThatThrownBy(() -> hasExpression.setExpression(new DecisionTable())) .isInstanceOf(UnsupportedOperationException.class) .hasMessage("It is not possible to set the EncapsulatedLogic of a BusinessKnowledgeModel."); }