### Question:
DelegatingGridWidgetCellSelectorMouseEventHandler extends DefaultGridWidgetCellSelectorMouseEventHandler { @Override public boolean onNodeMouseEvent(final GridWidget gridWidget, final Point2D relativeLocation, final Optional<Integer> uiHeaderRowIndex, final Optional<Integer> uiHeaderColumnIndex, final Optional<Integer> uiRowIndex, final Optional<Integer> uiColumnIndex, final AbstractNodeMouseEvent event) { if (nestingSupplier.get() == 0) { return doSuperOnNodeMouseEvent(gridWidget, relativeLocation, uiHeaderRowIndex, uiHeaderColumnIndex, uiRowIndex, uiColumnIndex, event); } boolean isHandled = false; if (uiRowIndex.isPresent() && uiColumnIndex.isPresent()) { isHandled = delegatedHandleBodyCell(gridWidget, uiRowIndex.get(), uiColumnIndex.get(), event); } if (isHandled) { final GridWidget parentGridWidget = parentSupplier.get().getGridWidget(); if (!parentGridWidget.isSelected()) { selectionManager.select(parentGridWidget); } } return isHandled; } DelegatingGridWidgetCellSelectorMouseEventHandler(final GridSelectionManager selectionManager,
                                                             final Supplier<GridCellTuple> parentSupplier,
                                                             final Supplier<Integer> nestingSupplier); @Override boolean onNodeMouseEvent(final GridWidget gridWidget,
                                    final Point2D relativeLocation,
                                    final Optional<Integer> uiHeaderRowIndex,
                                    final Optional<Integer> uiHeaderColumnIndex,
                                    final Optional<Integer> uiRowIndex,
                                    final Optional<Integer> uiColumnIndex,
                                    final AbstractNodeMouseEvent event);  }### Answer:
@Test public void testOnNodeMouseEventWhenNestedOnHeader() { setupGrid(() -> parent, () -> 1); uiHeaderRowIndex = Optional.of(0); uiHeaderColumnIndex = Optional.of(1); uiRowIndex = Optional.empty(); uiColumnIndex = Optional.empty(); assertThat(handler.onNodeMouseEvent(gridWidget, relativeLocation, uiHeaderRowIndex, uiHeaderColumnIndex, uiRowIndex, uiColumnIndex, event)).isFalse(); }
@Test public void testOnNodeMouseEventWhenNestedOnBodyWithoutSelectionChange() { when(event.isShiftKeyDown()).thenReturn(false); when(event.isControlKeyDown()).thenReturn(true); when(parentCellSelectionManager.selectCell(anyInt(), anyInt(), anyBoolean(), anyBoolean())).thenReturn(false); setupGrid(() -> parent, () -> 1); uiHeaderRowIndex = Optional.empty(); uiHeaderColumnIndex = Optional.empty(); uiRowIndex = Optional.of(0); uiColumnIndex = Optional.of(1); assertThat(handler.onNodeMouseEvent(gridWidget, relativeLocation, uiHeaderRowIndex, uiHeaderColumnIndex, uiRowIndex, uiColumnIndex, event)).isFalse(); verify(parentCellSelectionManager).selectCell(eq(0), eq(1), eq(false), eq(true)); verify(gridWidget).doAfterSelectionChange(eq(0), eq(1)); }
@Test public void testOnNodeMouseEventWhenNestedOnBodyWithSelectionChange() { when(event.isShiftKeyDown()).thenReturn(false); when(event.isControlKeyDown()).thenReturn(true); when(parentGridWidget.isSelected()).thenReturn(false); when(parentCellSelectionManager.selectCell(anyInt(), anyInt(), anyBoolean(), anyBoolean())).thenReturn(true); setupGrid(() -> parent, () -> 1); uiHeaderRowIndex = Optional.empty(); uiHeaderColumnIndex = Optional.empty(); uiRowIndex = Optional.of(0); uiColumnIndex = Optional.of(1); assertThat(handler.onNodeMouseEvent(gridWidget, relativeLocation, uiHeaderRowIndex, uiHeaderColumnIndex, uiRowIndex, uiColumnIndex, event)).isTrue(); verify(parentCellSelectionManager).selectCell(eq(0), eq(1), eq(false), eq(true)); verify(layer).batch(); verify(gridWidget).doAfterSelectionChange(eq(0), eq(1)); verify(selectionManager).select(eq(parentGridWidget)); }