### Question:
DNDListComponent { public Optional<HTMLElement> getPreviousElement(final Element reference) { return view.getPreviousElement(reference); } @Inject  DNDListComponent(final View view,
                            final DataTypeList dataTypeList); void refreshItemsPosition(); void refreshItemsCSSAndHTMLPosition(); HTMLElement registerNewItem(final HTMLElement htmlElement); HTMLElement getElement(); HTMLElement getDragArea(); void consolidateYPosition(); Optional<HTMLElement> getPreviousElement(final Element reference); void clear(); void setPositionX(final Element element,
                             final double positionX); void setPositionY(final Element element,
                             final double positionY); int getPositionY(final Element element); void setOnDropItem(final BiConsumer<Element, Element> onDropItem); void refreshDragAreaSize(); void setInitialPositionY(final HTMLElement dragAndDropElement,
                                    final List<HTMLElement> children); void setInitialHiddenPositionY(final HTMLElement itemElement); void highlightLevel(final HTMLElement htmlElement);  }### Answer:
@Test public void testGetPreviousElement() { final HTMLElement element0 = mock(HTMLElement.class); final HTMLElement element1 = mock(HTMLElement.class); final HTMLElement element2 = mock(HTMLElement.class); when(view.getPreviousElement(element0)).thenReturn(Optional.of(element1)); when(view.getPreviousElement(element1)).thenReturn(Optional.of(element2)); final Optional<Element> actual = dndListComponent.getPreviousElement(element0, element -> element == element2); assertTrue(actual.isPresent()); assertEquals(element2, actual.get()); }
@Test public void testGetPreviousElementWhenReferenceIsNull() { assertFalse(dndListComponent.getPreviousElement(null, null).isPresent()); }