### Question:
NodeTextSetter { Optional<NamedElement> getNamedElement(final Object node) { return Optional .ofNullable(node) .filter(obj -> obj instanceof Node) .map(obj -> (Node) obj) .map(Node::getContent) .filter(content -> content instanceof View) .map(content -> (View) content) .map(View::getDefinition) .filter(content -> content instanceof NamedElement) .map(content -> (NamedElement) content); } @Inject  NodeTextSetter(final TextPropertyProviderFactory textPropertyProviderFactory,
                          final Event<CanvasElementUpdatedEvent> canvasElementUpdatedEvent,
                          final DMNGraphUtils dmnGraphUtils); TextPropertyProviderFactory getTextPropertyProviderFactory(); void setText(final String newText,
                        final Node node);  }### Answer:
@Test public void testGetNamedElement() { final Node node = mock(Node.class); final View content = mock(View.class); final NamedElement namedElement = mock(NamedElement.class); when(node.getContent()).thenReturn(content); when(content.getDefinition()).thenReturn(namedElement); final Optional<NamedElement> actualNamed = nodeTextSetter.getNamedElement(node); assertTrue(actualNamed.isPresent()); assertEquals(namedElement, actualNamed.get()); }
@Test public void testGetNamedElementWhenNamedIsNotPresent() { final Node node = mock(Node.class); final View content = mock(View.class); final Object namedElement = mock(Object.class); when(node.getContent()).thenReturn(content); when(content.getDefinition()).thenReturn(namedElement); final Optional<NamedElement> actualNamed = nodeTextSetter.getNamedElement(node); assertFalse(actualNamed.isPresent()); }
@Test public void testGetNamedElementWhenViewIsNotPresent() { final Node node = mock(Node.class); final Object content = mock(Object.class); when(node.getContent()).thenReturn(content); final Optional<NamedElement> actualNamed = nodeTextSetter.getNamedElement(node); assertFalse(actualNamed.isPresent()); }