### Question:
ContextMenuView implements ContextMenu.View,
                                        HasListSelectorControl { Element[] getEventPath(Event event) { return Optional .ofNullable(event.path) .orElseGet(() -> Stream.of(event.composedPath()) .filter(Event.ComposedPathArrayUnionType::isElement) .map(Event.ComposedPathArrayUnionType::asElement) .toArray(Element[]::new) ); } @Inject  ContextMenuView(final ListSelector listSelector); @Override void init(final ContextMenu presenter); @Override void show(); @Override void hide(); @Override List<ListSelectorItem> getItems(final int uiRowIndex, final int uiColumnIndex); @Override void onItemSelected(final ListSelectorItem item);  }### Answer:
@Test public void testWhenGettingEventPath() { final Event event = mock(Event.class); final Element element = mock(Element.class); final String value = "test-val"; event.path = new Element[] {element}; when(element.getAttribute(anyString())).thenReturn(value); final Element[] eventPath = contextMenuView.getEventPath(event); assertThat(eventPath).isNotNull(); assertThat(eventPath).isNotEmpty(); assertThat(eventPath.length).isEqualTo(1); assertThat(eventPath[0]).extracting(elem -> elem.getAttribute("test-attr")).isEqualTo(value); }
@Test public void testWhenGettingEventPathAndPathIsNull() { final Event event = mock(Event.class); final Element element = mock(Element.class); final String value = "test-val"; event.path = null; when(event.composedPath()).thenReturn(new Event.ComposedPathArrayUnionType[]{buildComposedPathArrayUnionType(element)}); when(element.getAttribute(anyString())).thenReturn(value); final Element[] eventPath = contextMenuView.getEventPath(event); assertThat(eventPath).isNotNull(); assertThat(eventPath).isNotEmpty(); assertThat(eventPath.length).isEqualTo(1); assertThat(eventPath[0]).extracting(elem -> elem.getAttribute("test-attr")).isEqualTo(value); }