ShortcutRegistration implements Registration, Serializable { @Override public void remove() { if (executionRegistration != null) { executionRegistration.remove(); executionRegistration = null; } if (lifecycleRegistration != null) { lifecycleRegistration.remove(); lifecycleRegistration = null; } removeAllListenerRegistrations(); lifecycleOwner = null; listenOnComponents = null; eventListener = null; } ShortcutRegistration(Component lifecycleOwner,
            SerializableSupplier<Component[]> listenOnSuppliers,
            ShortcutEventListener eventListener, Key key); ShortcutRegistration withModifiers(KeyModifier... keyModifiers); ShortcutRegistration withAlt(); ShortcutRegistration withCtrl(); ShortcutRegistration withMeta(); ShortcutRegistration withShift(); ShortcutRegistration allowBrowserDefault(); ShortcutRegistration allowEventPropagation(); ShortcutRegistration bindLifecycleTo(Component component); ShortcutRegistration listenOn(Component... listenOnComponents); @Override void remove(); boolean isShortcutActive(); Key getKey(); Set<Key> getModifiers(); boolean isBrowserDefaultAllowed(); void setBrowserDefaultAllowed(boolean browserDefaultAllowed); boolean isEventPropagationAllowed(); void setEventPropagationAllowed(boolean eventPropagationAllowed); @Deprecated Component getOwner(); Component[] getOwners(); Component getLifecycleOwner(); @Override String toString();  }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void listenOnComponentIsChanged_eventIsPopulatedForANewListenOnComponent() { UI ui = Mockito.spy(UI.class); Component owner = new FakeComponent(); Component initialComponentToListenOn = new FakeComponent(); Component[] components = new Component[] { initialComponentToListenOn }; ui.add(owner); ui.add(initialComponentToListenOn); new ShortcutRegistration(owner, () -> components, event -> { }, Key.KEY_A); ArgumentCaptor<SerializableConsumer> captor = ArgumentCaptor .forClass(SerializableConsumer.class); verify(ui, atLeastOnce()).beforeClientResponse(eq(owner), captor.capture()); SerializableConsumer consumer = captor.getValue(); consumer.accept(mock(ExecutionContext.class)); Assert.assertTrue( hasKeyAInKeyDownExpression(initialComponentToListenOn)); Component replacementComponentToListenOn = new FakeComponent(); components[0] = replacementComponentToListenOn; ui.add(components[0]); ui.remove(initialComponentToListenOn); ui.remove(owner); ui.add(owner); consumer.accept(mock(ExecutionContext.class)); Assert.assertTrue( hasKeyAInKeyDownExpression(replacementComponentToListenOn)); }