### Question:
HideOnEscapeHandler implements EventHandler<KeyEvent> { @Override public void handle(KeyEvent t) { if (window.isShowing() && ESCAPE_COMBO.match(t)) { window.hide(); } } HideOnEscapeHandler(Window window); @Override void handle(KeyEvent t);  }### Answer:
@Test public void notShowingNoMatch() { Window window = spy(new Window() { }); HideOnEscapeHandler victim = new HideOnEscapeHandler(window); victim.handle( new KeyEvent(KeyEvent.KEY_RELEASED, KeyCode.A.toString(), "", KeyCode.A, false, false, false, false)); verify(window, never()).hide(); }
@Test public void showingMatch() { Window window = spy(window(scene)); HideOnEscapeHandler victim = new HideOnEscapeHandler(window); WaitForAsyncUtils.waitForAsyncFx(2000, () -> victim.handle(new KeyEvent(KeyEvent.KEY_RELEASED, KeyCode.ESCAPE.toString(), "", KeyCode.ESCAPE, false, false, false, false))); verify(window, times(1)).hide(); }
@Test public void notShowingMatch() { Window window = spy(new Window() { }); HideOnEscapeHandler victim = new HideOnEscapeHandler(window); victim.handle(new KeyEvent(KeyEvent.KEY_RELEASED, KeyCode.ESCAPE.toString(), "", KeyCode.ESCAPE, false, false, false, false)); verify(window, never()).hide(); }