### Question:
KeyboardOperationEscapeGridCell extends BaseKeyboardOperation { @Override public boolean perform(final GridWidget gridWidget, final boolean isShiftKeyDown, final boolean isControlKeyDown) { final AtomicBoolean needToRedraw = new AtomicBoolean(false); final Optional<BaseExpressionGrid> oParent = ((BaseExpressionGrid) gridWidget).findParentGrid(); oParent.ifPresent(parentWidget -> { gridLayer.select(parentWidget); parentWidget.selectFirstCell(); needToRedraw.set(true); }); return needToRedraw.get(); } KeyboardOperationEscapeGridCell(final GridLayer gridLayer); @Override int getKeyCode(); @Override boolean isExecutable(final GridWidget gridWidget); @Override boolean perform(final GridWidget gridWidget,
                           final boolean isShiftKeyDown,
                           final boolean isControlKeyDown);  }### Answer:
@Test public void testEscapeFromNotChildCell() { final Optional<BaseExpressionGrid> oParent = Optional.empty(); final BaseExpressionGrid gridWidget = mock(BaseExpressionGrid.class); when(gridWidget.findParentGrid()).thenReturn(oParent); assertThat(operation.perform(gridWidget, false, false)) .as("No need to redraw") .isFalse(); }
@Test public void testEscapeFromChildCell() { final BaseExpressionGrid parent = mock(BaseExpressionGrid.class); final Optional<BaseExpressionGrid> oParent = Optional.of(parent); final BaseExpressionGrid gridWidget = mock(BaseExpressionGrid.class); when(gridWidget.findParentGrid()).thenReturn(oParent); assertThat(operation.perform(gridWidget, false, false)) .as("Need to redraw") .isTrue(); verify(gridLayer).select(parent); verify(parent).selectFirstCell(); }