ShowDetailsListener implements ItemClickListener<T> { @Override public void itemClick(ItemClick<T> event) { if (event.getItem() != null && ((event.getColumn() != null && detailsColumnId.equals(event.getColumn().getId())) || (showOnDoubleClick && event.getMouseEventDetails().isDoubleClick()))) { handleItemClick(event); } } ShowDetailsListener(String detailsColumnId, Consumer<T> itemHandler);  ShowDetailsListener(String detailsColumnId, boolean showOnDoubleClick, Consumer<T> itemHandler); String getDetailsColumnId(); boolean isShowOnDoubleClick(); Consumer<T> getItemHandler(); @Override void itemClick(ItemClick<T> event);  }
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void testItemClickDoesNotCallHandlerWhenItemIsNull() { Consumer<ContactIndexDto> handler = mock(Consumer.class); String detailsColumnId = ContactIndexDto.UUID; ShowDetailsListener<ContactIndexDto> cut = new ShowDetailsListener<>(detailsColumnId, handler); ItemClick<ContactIndexDto> event = mock(ItemClick.class); ContactIndexDto item = mock(ContactIndexDto.class); Column column = mock(Column.class); when(event.getColumn()).thenReturn(column); when(column.getId()).thenReturn(detailsColumnId); cut.itemClick(event); verify(handler, never()).accept(null); when(event.getItem()).thenReturn(item); cut.itemClick(event); verify(handler).accept(item); reset(handler, event); MouseEventDetails mouseEventDetails = mock(MouseEventDetails.class); when(event.getMouseEventDetails()).thenReturn(mouseEventDetails); when(mouseEventDetails.isDoubleClick()).thenReturn(true); cut.itemClick(event); verify(handler, never()).accept(null); when(event.getItem()).thenReturn(item); cut.itemClick(event); verify(handler).accept(item); }