### Question:
GuidedTourUtils { public Optional<String> getName(final AbstractCanvasHandlerElementEvent event) { final Element<?> element = event.getElement(); if (element instanceof NodeImpl) { return Optional.ofNullable(getName(element)); } return Optional.empty(); } @Inject  GuidedTourUtils(final TextPropertyProviderFactory textPropertyProviderFactory); Optional<String> getName(final AbstractCanvasHandlerElementEvent event); String getName(final Element<?> element); String getName(final NodeImpl<View> node); @SuppressWarnings("unchecked") NodeImpl<View> asNodeImpl(final Element<?> element);  }### Answer:
@Test public void getNameWithAbstractCanvasHandlerElementEvent() { final String expectedName = "name"; final NodeImpl<View> node = new NodeImpl<>("uuid"); final CanvasHandler canvasHandler = mock(CanvasHandler.class); final TextPropertyProvider textPropertyProvider = mock(TextPropertyProvider.class); final CanvasElementAddedEvent event = new CanvasElementAddedEvent(canvasHandler, node); when(textPropertyProviderFactory.getProvider(node)).thenReturn(textPropertyProvider); when(textPropertyProvider.getText(node)).thenReturn(expectedName); final Optional<String> actualName = utils.getName(event); assertTrue(actualName.isPresent()); assertEquals(expectedName, actualName.get()); }
@Test public void testGetNodeWhenElementIsNotNodeImpl() { final EdgeImpl<View> edge = new EdgeImpl<>("uuid"); final CanvasHandler canvasHandler = mock(CanvasHandler.class); final CanvasElementAddedEvent event = new CanvasElementAddedEvent(canvasHandler, edge); assertFalse(utils.getName(event).isPresent()); }
@Test public void testGetNameWithNodeImpl() { final NodeImpl<View> node = new NodeImpl<>("uuid"); final TextPropertyProvider textPropertyProvider = mock(TextPropertyProvider.class); final String expectedNodeName = "Decision-1"; when(textPropertyProviderFactory.getProvider(node)).thenReturn(textPropertyProvider); when(textPropertyProvider.getText(node)).thenReturn(expectedNodeName); final String actualNodeName = utils.getName(node); assertEquals(expectedNodeName, actualNodeName); }