### Question:
MonacoEditorDOMElement extends BaseDOMElement<String, MonacoEditorWidget> implements TakesValue<String>,
                                                                                                  Focusable { MonacoStandaloneCodeEditor.CallbackFunction getOnKeyDown(final MonacoStandaloneCodeEditor codeEditor) { return event -> { boolean isSuggestWidgetVisible = codeEditor.isSuggestWidgetVisible(); final boolean isEsc = event.getKeyCode() == 9; if (isSuggestWidgetVisible && isEsc) { codeEditor.trigger("keyboard", "cursorHome"); codeEditor.trigger("keyboard", "cursorEnd"); event.stopPropagation(); event.preventDefault(); } }; } MonacoEditorDOMElement(final MonacoEditorWidget widget,
                                  final GridLayer gridLayer,
                                  final GridWidget gridWidget,
                                  final SessionManager sessionManager,
                                  final SessionCommandManager<AbstractCanvasHandler> sessionCommandManager,
                                  final Function<GridCellTuple, Command> hasNoValueCommand,
                                  final Function<GridCellValueTuple, Command> hasValueCommand); void setupElements(); @Override void initialise(final GridBodyCellRenderContext context); @Override void setValue(final String value); @Override String getValue(); @Override int getTabIndex(); @Override void setAccessKey(final char key); @Override void setFocus(final boolean focused); @Override void setTabIndex(final int index); @Override @SuppressWarnings("unchecked") void flush(final String value);  }### Answer:
@Test public void testGetOnKeyDownWhenSuggestWidgetIsVisibleAndKeyCodeIsEsc() { final MonacoStandaloneCodeEditor codeEditor = mock(MonacoStandaloneCodeEditor.class); final NativeEvent event = mock(NativeEvent.class); when(event.getKeyCode()).thenReturn(9); when(codeEditor.isSuggestWidgetVisible()).thenReturn(true); domElement.getOnKeyDown(codeEditor).call(event); verify(codeEditor).trigger("keyboard", "cursorHome"); verify(codeEditor).trigger("keyboard", "cursorEnd"); verify(event).stopPropagation(); verify(event).preventDefault(); }
@Test public void testGetOnKeyDownWhenSuggestWidgetIsVisibleAndKeyCodeIsNotEsc() { final MonacoStandaloneCodeEditor codeEditor = mock(MonacoStandaloneCodeEditor.class); final NativeEvent event = mock(NativeEvent.class); when(event.getKeyCode()).thenReturn(10); when(codeEditor.isSuggestWidgetVisible()).thenReturn(true); domElement.getOnKeyDown(codeEditor).call(event); verify(codeEditor, never()).trigger("keyboard", "cursorHome"); verify(codeEditor, never()).trigger("keyboard", "cursorEnd"); verify(event, never()).stopPropagation(); verify(event, never()).preventDefault(); }
@Test public void testGetOnKeyDownWhenSuggestWidgetIsNotVisibleAndKeyCodeIsEsc() { final MonacoStandaloneCodeEditor codeEditor = mock(MonacoStandaloneCodeEditor.class); final NativeEvent event = mock(NativeEvent.class); when(event.getKeyCode()).thenReturn(9); when(codeEditor.isSuggestWidgetVisible()).thenReturn(false); domElement.getOnKeyDown(codeEditor).call(event); verify(codeEditor, never()).trigger("keyboard", "cursorHome"); verify(codeEditor, never()).trigger("keyboard", "cursorEnd"); verify(event, never()).stopPropagation(); verify(event, never()).preventDefault(); }
@Test public void testGetOnKeyDownWhenSuggestWidgetIsNotVisibleAndKeyCodeIsNotEsc() { final MonacoStandaloneCodeEditor codeEditor = mock(MonacoStandaloneCodeEditor.class); final NativeEvent event = mock(NativeEvent.class); when(event.getKeyCode()).thenReturn(10); when(codeEditor.isSuggestWidgetVisible()).thenReturn(false); domElement.getOnKeyDown(codeEditor).call(event); verify(codeEditor, never()).trigger("keyboard", "cursorHome"); verify(codeEditor, never()).trigger("keyboard", "cursorEnd"); verify(event, never()).stopPropagation(); verify(event, never()).preventDefault(); }