@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");
}