@Test public void setTarget_nullTarget_connectorIsRemovedFromPreviousTarget() { Grid grid = Mockito.mock(Grid.class); Element element = Mockito.mock(Element.class); StateNode node = Mockito.mock(StateNode.class); Mockito.when(grid.getElement()).thenReturn(element); Mockito.when(element.getNode()).thenReturn(node); DomListenerRegistration registration = Mockito .mock(DomListenerRegistration.class); Mockito.when( element.addEventListener(Mockito.anyString(), Mockito.any())) .thenReturn(registration); Mockito.when(registration.addEventData(Mockito.anyString())) .thenReturn(registration); Mockito.when(grid.getUI()).thenReturn(Optional.empty()); Registration attachRegistration = Mockito.mock(Registration.class); Mockito.when(grid.addAttachListener(Mockito.any())) .thenReturn(attachRegistration); GridContextMenu gridContextMenu = new GridContextMenu<>(); gridContextMenu.setTarget(grid); gridContextMenu.setTarget(null); Mockito.verify(registration).remove(); Mockito.verify(element) .callJsFunction("$contextMenuConnector.removeConnector"); }
@Override public void setTarget(Component target) { if (target != null && !(target instanceof Grid<?>)) { throw new IllegalArgumentException( "Only an instance of Grid can be used as the target for GridContextMenu. " + "Use ContextMenu for any other component."); } super.setTarget(target); }
GridContextMenu extends
        ContextMenuBase<GridContextMenu<T>, GridMenuItem<T>, GridSubMenu<T>> implements HasGridMenuItems<T> { @Override public void setTarget(Component target) { if (target != null && !(target instanceof Grid<?>)) { throw new IllegalArgumentException( "Only an instance of Grid can be used as the target for GridContextMenu. " + "Use ContextMenu for any other component."); } super.setTarget(target); } }
GridContextMenu extends
        ContextMenuBase<GridContextMenu<T>, GridMenuItem<T>, GridSubMenu<T>> implements HasGridMenuItems<T> { @Override public void setTarget(Component target) { if (target != null && !(target instanceof Grid<?>)) { throw new IllegalArgumentException( "Only an instance of Grid can be used as the target for GridContextMenu. " + "Use ContextMenu for any other component."); } super.setTarget(target); } GridContextMenu();  GridContextMenu(Grid<T> target); }
GridContextMenu extends
        ContextMenuBase<GridContextMenu<T>, GridMenuItem<T>, GridSubMenu<T>> implements HasGridMenuItems<T> { @Override public void setTarget(Component target) { if (target != null && !(target instanceof Grid<?>)) { throw new IllegalArgumentException( "Only an instance of Grid can be used as the target for GridContextMenu. " + "Use ContextMenu for any other component."); } super.setTarget(target); } GridContextMenu();  GridContextMenu(Grid<T> target); @Override void setTarget(Component target); @Override GridMenuItem<T> addItem(String text,
            ComponentEventListener<GridContextMenuItemClickEvent<T>> clickListener); @Override GridMenuItem<T> addItem(Component component,
            ComponentEventListener<GridContextMenuItemClickEvent<T>> clickListener); Registration addGridContextMenuOpenedListener(
            ComponentEventListener<GridContextMenuOpenedEvent<T>> listener); SerializablePredicate<T> getDynamicContentHandler(); void setDynamicContentHandler(
            SerializablePredicate<T> dynamicContentHandler); }
GridContextMenu extends
        ContextMenuBase<GridContextMenu<T>, GridMenuItem<T>, GridSubMenu<T>> implements HasGridMenuItems<T> { @Override public void setTarget(Component target) { if (target != null && !(target instanceof Grid<?>)) { throw new IllegalArgumentException( "Only an instance of Grid can be used as the target for GridContextMenu. " + "Use ContextMenu for any other component."); } super.setTarget(target); } GridContextMenu();  GridContextMenu(Grid<T> target); @Override void setTarget(Component target); @Override GridMenuItem<T> addItem(String text,
            ComponentEventListener<GridContextMenuItemClickEvent<T>> clickListener); @Override GridMenuItem<T> addItem(Component component,
            ComponentEventListener<GridContextMenuItemClickEvent<T>> clickListener); Registration addGridContextMenuOpenedListener(
            ComponentEventListener<GridContextMenuOpenedEvent<T>> listener); SerializablePredicate<T> getDynamicContentHandler(); void setDynamicContentHandler(
            SerializablePredicate<T> dynamicContentHandler);  }