### Question:
DNDListComponentView implements DNDListComponent.View { @Override public Optional<HTMLElement> getPreviousElement(final Element reference) { final int positionY = Position.getY(reference); return querySelector(getDragArea()).getDraggableElement(positionY - 1); } @Inject  DNDListComponentView(final HTMLDivElement dragArea); @Override void init(final DNDListComponent presenter); @Override HTMLElement registerItem(final HTMLElement htmlElement); @Override void refreshItemsPosition(); @Override void refreshItemsHTML(); @Override void consolidateHierarchicalLevel(final boolean isElementsDraggedByUser); @Override void consolidateYPosition(); @Override void clear(); @Override Optional<HTMLElement> getPreviousElement(final Element reference); @Override void refreshDragAreaSize(); @Override HTMLDivElement getDragArea();  }### Answer:
@Test public void testGetPreviousElementWhenElementIsFound() { final HTMLElement current = mock(HTMLElement.class); final HTMLElement expectedPrevious = mock(HTMLElement.class); when(expectedPrevious.getAttribute(DATA_Y_POSITION)).thenReturn("0"); when(current.getAttribute(DATA_Y_POSITION)).thenReturn("1"); when(dragArea.querySelector(".kie-dnd-draggable[data-y-position=\"0\"]")).thenReturn(expectedPrevious); final Optional<HTMLElement> actualPrevious = view.getPreviousElement(current); assertTrue(actualPrevious.isPresent()); assertEquals(expectedPrevious, actualPrevious.get()); }
@Test public void testGetPreviousElementWhenElementIsNotFound() { final HTMLElement current = mock(HTMLElement.class); when(current.getAttribute(DATA_Y_POSITION)).thenReturn("1"); when(dragArea.querySelector(".kie-dnd-draggable[data-y-position=\"0\"]")).thenReturn(null); final Optional<HTMLElement> actualPrevious = view.getPreviousElement(current); assertFalse(actualPrevious.isPresent()); }