use of com.vaadin.flow.shared.Registration in project flow by vaadin.
the class AbstractDataProviderTest method removeListener_listenerIsNotNotified.
@Test
public void removeListener_listenerIsNotNotified() {
TestDataProvider dataProvider = new TestDataProvider();
AtomicReference<DataChangeEvent<Object>> event = new AtomicReference<>();
Registration registration = dataProvider.addDataProviderListener(event::set);
registration.remove();
dataProvider.refreshAll();
Assert.assertNull(event.get());
}
use of com.vaadin.flow.shared.Registration in project flow by vaadin.
the class CompositeDataGeneratorTest method removeDataGenerator_dataIsDestroyed.
@Test
public void removeDataGenerator_dataIsDestroyed() {
CompositeDataGenerator<String> composite = new CompositeDataGenerator<>();
MockDataGenerator mock1 = new MockDataGenerator("mock", "value1");
MockDataGenerator mock2 = new MockDataGenerator("mock", "value1");
Registration registration = composite.addDataGenerator(mock1);
composite.addDataGenerator(mock2);
composite.generateData("item1", Json.createObject());
Assert.assertThat(mock1.getProcessed(), CoreMatchers.hasItem("item1"));
Assert.assertThat(mock2.getProcessed(), CoreMatchers.hasItem("item1"));
registration.remove();
Assert.assertThat(mock1.getProcessed(), CoreMatchers.not(CoreMatchers.hasItem("item1")));
Assert.assertThat(mock2.getProcessed(), CoreMatchers.hasItem("item1"));
composite.removeDataGenerator(mock2);
Assert.assertThat(mock2.getProcessed(), CoreMatchers.not(CoreMatchers.hasItem("item1")));
}
use of com.vaadin.flow.shared.Registration in project flow by vaadin.
the class ShadowRootTest method detachListener_parentDetach_childListenersTriggered.
@Test
public void detachListener_parentDetach_childListenersTriggered() {
Element body = new UI().getElement();
Element parent = ElementFactory.createDiv();
Element child = ElementFactory.createDiv();
Element grandChild = ElementFactory.createDiv();
AtomicInteger triggered = new AtomicInteger();
Registration registrationHandle = child.addDetachListener(event -> {
triggered.addAndGet(1);
Assert.assertEquals(child, event.getSource());
});
grandChild.addDetachListener(event -> {
triggered.addAndGet(1);
Assert.assertEquals(grandChild, event.getSource());
});
child.appendChild(grandChild);
parent.attachShadow().appendChild(child);
body.appendChild(parent);
Assert.assertEquals(triggered.get(), 0);
body.removeAllChildren();
Assert.assertEquals(triggered.get(), 2);
body.appendChild(parent);
body.removeAllChildren();
Assert.assertEquals(triggered.get(), 4);
body.appendChild(parent);
registrationHandle.remove();
body.removeAllChildren();
Assert.assertEquals(triggered.get(), 5);
}
use of com.vaadin.flow.shared.Registration in project flow by vaadin.
the class StateNodeTest method testAttachListener_listenerRemoved_listenerNotTriggered.
@Test
public void testAttachListener_listenerRemoved_listenerNotTriggered() {
StateNode root = new RootStateNode();
TestStateNode child = new TestStateNode();
Assert.assertFalse(child.isAttached());
AtomicBoolean triggered = new AtomicBoolean(false);
Registration registrationHandle = child.addAttachListener(() -> triggered.set(true));
registrationHandle.remove();
setParent(child, root);
Assert.assertFalse(triggered.get());
}
use of com.vaadin.flow.shared.Registration in project flow by vaadin.
the class ElementListenersTest method testAddedListenerGetsEvent.
@Test
public void testAddedListenerGetsEvent() {
AtomicInteger eventCount = new AtomicInteger();
Registration handle = ns.add("foo", e -> eventCount.incrementAndGet(), new String[0]);
Assert.assertEquals(0, eventCount.get());
ns.fireEvent(createEvent("foo"));
Assert.assertEquals(1, eventCount.get());
handle.remove();
ns.fireEvent(createEvent("foo"));
Assert.assertEquals(1, eventCount.get());
}
Aggregations