### Question:
ExpressionEditorViewImpl implements ExpressionEditorView { @Override public void setExpression(final String nodeUUID, final HasExpression hasExpression, final Optional<HasName> hasName, final boolean isOnlyVisualChangeAllowed) { expressionContainerGrid.setExpression(nodeUUID, hasExpression, hasName, isOnlyVisualChangeAllowed); setExpressionNameText(hasName); setExpressionTypeText(Optional.ofNullable(hasExpression.getExpression())); } ExpressionEditorViewImpl(); @Inject  ExpressionEditorViewImpl(final Anchor returnToLink,
                                    final Span expressionName,
                                    final Span expressionType,
                                    final @DMNEditor DMNGridPanelContainer gridPanelContainer,
                                    final TranslationService translationService,
                                    final ListSelectorView.Presenter listSelector,
                                    final SessionManager sessionManager,
                                    final SessionCommandManager<AbstractCanvasHandler> sessionCommandManager,
                                    final @DMNEditor DefaultCanvasCommandFactory canvasCommandFactory,
                                    final @DMNEditor Supplier<ExpressionEditorDefinitions> expressionEditorDefinitionsSupplier,
                                    final Event<RefreshFormPropertiesEvent> refreshFormPropertiesEvent,
                                    final Event<DomainObjectSelectionEvent> domainObjectSelectionEvent); @Override void init(final ExpressionEditorView.Presenter presenter); @Override void bind(final DMNSession session); @Override void setReturnToLinkText(final String text); @Override void setExpression(final String nodeUUID,
                              final HasExpression hasExpression,
                              final Optional<HasName> hasName,
                              final boolean isOnlyVisualChangeAllowed); ExpressionContainerGrid getExpressionContainerGrid(); @Override void setExpressionNameText(final Optional<HasName> hasName); @Override void setExpressionTypeText(final Optional<Expression> expression); @Override void onResize(); @Override void refresh(); @Override void setFocus();  }### Answer:
@Test public void testSetExpression() { final Optional<HasName> hasName = Optional.empty(); view.setExpression(NODE_UUID, hasExpression, hasName, false); verify(gridLayer).add(expressionContainerArgumentCaptor.capture()); final ExpressionContainerGrid expressionContainer = (ExpressionContainerGrid) expressionContainerArgumentCaptor.getValue(); assertFalse(expressionContainer.isOnlyVisualChangeAllowed()); }
@Test public void testSetExpressionWhenOnlyVisualChangeAllowed() { final Optional<HasName> hasName = Optional.empty(); view.setExpression(NODE_UUID, hasExpression, hasName, true); verify(gridLayer).add(expressionContainerArgumentCaptor.capture()); final ExpressionContainerGrid expressionContainer = (ExpressionContainerGrid) expressionContainerArgumentCaptor.getValue(); assertTrue(expressionContainer.isOnlyVisualChangeAllowed()); }
@Test public void testSetExpressionDoesUpdateExpressionNameTextWhenHasNameIsNotEmpty() { final String NAME = "NAME"; final Name name = new Name(NAME); final HasName hasNameMock = mock(HasName.class); doReturn(name).when(hasNameMock).getName(); final Optional<HasName> hasName = Optional.of(hasNameMock); view.setExpression(NODE_UUID, hasExpression, hasName, false); verify(expressionName).setTextContent(eq(NAME)); }
@Test public void testSetExpressionDoesNotUpdateExpressionNameTextWhenHasNameIsEmpty() { final Optional<HasName> hasName = Optional.empty(); view.setExpression(NODE_UUID, hasExpression, hasName, false); verify(expressionName, never()).setTextContent(any(String.class)); }
@Test public void testSetExpressionDoesUpdateExpressionTypeTextWhenHasExpressionIsNotEmpty() { final Expression expression = new LiteralExpression(); final Optional<HasName> hasName = Optional.empty(); when(hasExpression.getExpression()).thenReturn(expression); view.setExpression(NODE_UUID, hasExpression, hasName, false); verify(expressionType).setTextContent(eq(LITERAL_EXPRESSION_DEFINITION_NAME)); }
@Test public void testSetExpressionDoesNotUpdateExpressionTypeTextWhenHasExpressionTextWhenHasExpressionIsEmpty() { final Optional<HasName> hasName = Optional.empty(); view.setExpression(NODE_UUID, hasExpression, hasName, false); verify(expressionType).setTextContent(eq("<" + UNDEFINED_EXPRESSION_DEFINITION_NAME + ">")); }