### Question:
DelegatingGridWidgetEditCellMouseEventHandler extends DefaultGridWidgetEditCellMouseEventHandler { @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 (DynamicReadOnlyUtils.isOnlyVisualChangeAllowed(gridWidget)) { return false; } if (nestingSupplier.get() == 0) { return doSuperOnNodeMouseEvent(gridWidget, relativeLocation, uiHeaderRowIndex, uiHeaderColumnIndex, uiRowIndex, uiColumnIndex, event); } boolean isHandled = false; if (uiRowIndex.isPresent() && uiColumnIndex.isPresent()) { isHandled = delegatedHandleBodyCell(gridWidget, relativeLocation, uiRowIndex.get(), uiColumnIndex.get(), event); } return isHandled; } DelegatingGridWidgetEditCellMouseEventHandler(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 testOnNodeMouseEventWhenOnlyVisualChangeAllowed() { when(gridWidget.isOnlyVisualChangeAllowed()).thenReturn(true); setupGrid(() -> null, () -> 0); assertThat(handler.onNodeMouseEvent(gridWidget, relativeLocation, uiHeaderRowIndex, uiHeaderColumnIndex, uiRowIndex, uiColumnIndex, event)).isFalse(); verify(gridWidget, never()).startEditingCell(any(Point2D.class)); }
@Test public void testOnNodeMouseEventWhenNestedOnHeader() { when(parentGridData.getSelectedCells()).thenReturn(Collections.emptyList()); 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 testOnNodeMouseEventWhenNestedOnBodyWithoutCellSelection() { when(event.isShiftKeyDown()).thenReturn(false); when(event.isControlKeyDown()).thenReturn(true); when(parentGridData.getSelectedCells()).thenReturn(Collections.emptyList()); 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(); }