use of com.vaadin.flow.shared.Registration in project flow by vaadin.
the class BootstrapHandlerTest method uiInitialization_allRegisteredListenersAreNotified.
// UIInitListeners
@Test
public void uiInitialization_allRegisteredListenersAreNotified() {
BootstrapHandler bootstrapHandler = new BootstrapHandler();
VaadinResponse response = Mockito.mock(VaadinResponse.class);
AtomicReference<UI> uiReference = new AtomicReference<>();
Registration registration = service.addUIInitListener(event -> Assert.assertTrue("Atomic reference was not empty.", uiReference.compareAndSet(null, event.getUI())));
final BootstrapContext context = bootstrapHandler.createAndInitUI(TestUI.class, createVaadinRequest(), response, session);
Assert.assertEquals("Event UI didn't match initialized UI instance.", context.getUI(), uiReference.get());
// unregister listener
registration.remove();
AtomicReference<UI> secondListenerReference = new AtomicReference<>();
service.addUIInitListener(event -> Assert.assertTrue("Atomic reference did not contain previous UI.", uiReference.compareAndSet(context.getUI(), event.getUI())));
service.addUIInitListener(event -> Assert.assertTrue("Atomic reference was not empty.", secondListenerReference.compareAndSet(null, event.getUI())));
final BootstrapContext secondInit = bootstrapHandler.createAndInitUI(TestUI.class, createVaadinRequest(), response, session);
Assert.assertEquals("Event UI didn't match initialized UI instance.", secondInit.getUI(), uiReference.get());
Assert.assertEquals("Second event UI didn't match initialized UI instance.", secondInit.getUI(), secondListenerReference.get());
}
use of com.vaadin.flow.shared.Registration in project flow by vaadin.
the class BootstrapHandlerTest method uiInitialization_changingListenersOnEventWorks.
// UIInitListeners
@Test
public void uiInitialization_changingListenersOnEventWorks() {
BootstrapHandler bootstrapHandler = new BootstrapHandler();
VaadinResponse response = Mockito.mock(VaadinResponse.class);
AtomicReference<UI> uiReference = new AtomicReference<>();
Registration registration = service.addUIInitListener(event -> service.addUIInitListener(laterEvent -> uiReference.compareAndSet(null, laterEvent.getUI())));
bootstrapHandler.createAndInitUI(TestUI.class, createVaadinRequest(), response, session);
Assert.assertEquals("Event UI didn't match initialized UI instance.", null, uiReference.get());
// unregister listener
registration.remove();
service.addUIInitListener(event -> registration.remove());
final BootstrapContext secondInit = bootstrapHandler.createAndInitUI(TestUI.class, createVaadinRequest(), response, session);
Assert.assertEquals("Event UI didn't match initialized UI instance.", secondInit.getUI(), uiReference.get());
}
use of com.vaadin.flow.shared.Registration in project flow by vaadin.
the class StateNodeTest method testDetachListener_listenerRemoved_listenerNotTriggered.
@Test
public void testDetachListener_listenerRemoved_listenerNotTriggered() {
StateNode root = new RootStateNode();
TestStateNode child = new TestStateNode();
setParent(child, root);
Assert.assertTrue(child.isAttached());
AtomicBoolean triggered = new AtomicBoolean(false);
Registration registrationHandle = child.addDetachListener(() -> triggered.set(true));
registrationHandle.remove();
setParent(child, null);
Assert.assertFalse("Detach listener was triggered even though handler was removed.", triggered.get());
}
use of com.vaadin.flow.shared.Registration in project flow by vaadin.
the class ElementListenersTest method testEventNameInClientData.
@Test
public void testEventNameInClientData() {
Assert.assertFalse(ns.contains("foo"));
Registration handle = ns.add("foo", noOp, new String[0]);
Assert.assertEquals(0, getExpressions("foo").size());
handle.remove();
Assert.assertFalse(ns.contains("foo"));
}
use of com.vaadin.flow.shared.Registration in project flow by vaadin.
the class ElementPropertyMapTest method removePropertyChangeListener_fireEvent_listenerIsNotNotified.
@Test
public void removePropertyChangeListener_fireEvent_listenerIsNotNotified() {
ElementPropertyMap map = createSimplePropertyMap();
PropertyChangeListener listener = ev -> {
Assert.fail();
};
Registration registration = map.addPropertyChangeListener("foo", listener);
registration.remove();
// listener is not called. Otherwise its assertion fails.
map.setProperty("foo", "bar", true);
}
Aggregations