BaseSingletonDOMElementFactory implements SingletonDOMElementFactory<W, E> { @Override public void registerHandlers(final W widget, final E widgetDomElement) { widget.addDomHandler(destroyOrFlushKeyDownHandler(), KeyDownEvent.getType()); widget.addDomHandler((e) -> e.stopPropagation(), KeyDownEvent.getType()); widget.addDomHandler((e) -> e.stopPropagation(), MouseDownEvent.getType()); if (widget instanceof Focusable) { widget.addDomHandler((e) -> { flush(); gridLayer.batch(); gridPanel.setFocus(true); }, BlurEvent.getType()); } } BaseSingletonDOMElementFactory(final GridLienzoPanel gridPanel,
                                          final GridLayer gridLayer,
                                          final GridWidget gridWidget); @Override void attachDomElement(final GridBodyCellRenderContext context,
                                 final Consumer<E> onCreation,
                                 final Consumer<E> onDisplay); @Override E createDomElement(final GridLayer gridLayer,
                              final GridWidget gridWidget); @Override void registerHandlers(final W widget, final E widgetDomElement); @Override void destroyResources(); @Override void flush();  }
@Test public void testRegisterHandlers() { testedFactory.createDomElement(gridLayerMock, gridWidgetMock); testedFactory.registerHandlers(testedFactory.widget, testedFactory.e); verify(testedFactory.widget, times(4)).addDomHandler(handlerCaptor.capture(), any(DomEvent.Type.class)); Assertions.assertThat(handlerCaptor.getAllValues().get(0)).isInstanceOf(KeyDownHandlerCommon.class); final KeyDownEvent keyDownEventMock = mock(KeyDownEvent.class); Assertions.assertThat(handlerCaptor.getAllValues().get(1)).isInstanceOf(KeyDownHandler.class); ((KeyDownHandler) handlerCaptor.getAllValues().get(1)).onKeyDown(keyDownEventMock); verify(keyDownEventMock).stopPropagation(); final MouseDownEvent mouseDownEventMock = mock(MouseDownEvent.class); Assertions.assertThat(handlerCaptor.getAllValues().get(2)).isInstanceOf(MouseDownHandler.class); ((MouseDownHandler) handlerCaptor.getAllValues().get(2)).onMouseDown(mouseDownEventMock); verify(mouseDownEventMock).stopPropagation(); final BaseDOMElement domElement = testedFactory.e; final BlurEvent blurEventMock = mock(BlurEvent.class); Assertions.assertThat(handlerCaptor.getAllValues().get(3)).isInstanceOf(BlurHandler.class); ((BlurHandler) handlerCaptor.getAllValues().get(3)).onBlur(blurEventMock); Assertions.assertThat(testedFactory.widget).isNull(); Assertions.assertThat(testedFactory.e).isNull(); verify(domElement).detach(); verify(gridLayerMock).batch(); verify(gridLienzoPanelMock).setFocus(true); }