### Question:
DataTypeSearchBarView implements DataTypeSearchBar.View { int getIndexOfParentOrLastElementInGroup(final List<DataTypeListItem> groupedElements, final DataTypeListItem parent) { final int parentIndex = groupedElements.indexOf(parent); final String parentId = parent.getDragAndDropElement().getAttribute(UUID_ATTR); int index = parentIndex; for (int i = parentIndex; i < groupedElements.size(); i++) { if (Objects.equals(groupedElements.get(i).getDragAndDropElement().getAttribute(PARENT_UUID_ATTR), parentId)) { index++; } } return index; } @Inject  DataTypeSearchBarView(final HTMLInputElement searchBar,
                                 final @Named("span") HTMLElement searchIcon,
                                 final HTMLButtonElement closeSearch,
                                 final TranslationService translationService); @PostConstruct void setupSearchBar(); @Override void init(final DataTypeSearchBar presenter); @EventHandler("close-search") void onSearchBarCloseButton(final ClickEvent e); @EventHandler("search-bar") void onSearchBarKeyUpEvent(final KeyUpEvent event); @EventHandler("search-bar") void onSearchBarKeyDownEvent(final KeyDownEvent e); @EventHandler("search-bar") void onSearchBarChangeEvent(final ChangeEvent e); @Override void resetSearchBar(); @Override void showSearchResults(final List<DataType> results); void refreshItemsPosition();  }### Answer:
@Test public void testGetIndexOfParentOrLastElementInGroup() { final DataTypeListItem parent = mock(DataTypeListItem.class); final HTMLElement parentElement = mock(HTMLElement.class); final String parentId = "parentId"; final List<DataTypeListItem> groupedElements = new ArrayList<>(); groupedElements.add(parent); final int expectedIndex = 0; when(parentElement.getAttribute(UUID_ATTR)).thenReturn(parentId); when(parent.getDragAndDropElement()).thenReturn(parentElement); final int index = view.getIndexOfParentOrLastElementInGroup(groupedElements, parent); assertEquals(expectedIndex, index); }
@Test public void testGetIndexOfParentOrLastElementInGroupWhenHaveMoreElements() { final DataTypeListItem parent = mock(DataTypeListItem.class); final DataTypeListItem listItem1 = mock(DataTypeListItem.class); final DataTypeListItem listItem2 = mock(DataTypeListItem.class); final HTMLElement parentElement = mock(HTMLElement.class); final HTMLElement listItemElement1 = mock(HTMLElement.class); final HTMLElement listItemElement2 = mock(HTMLElement.class); final String parentId = "parentId"; final List<DataTypeListItem> groupedElements = new ArrayList<>(); groupedElements.add(parent); groupedElements.add(listItem1); groupedElements.add(listItem2); final int expectedIndex = 2; when(parentElement.getAttribute(UUID_ATTR)).thenReturn(parentId); when(parent.getDragAndDropElement()).thenReturn(parentElement); when(listItem1.getDragAndDropElement()).thenReturn(listItemElement1); when(listItem2.getDragAndDropElement()).thenReturn(listItemElement2); when(listItemElement1.getAttribute(PARENT_UUID_ATTR)).thenReturn(parentId); when(listItemElement2.getAttribute(PARENT_UUID_ATTR)).thenReturn(parentId); final int index = view.getIndexOfParentOrLastElementInGroup(groupedElements, parent); assertEquals(expectedIndex, index); }