use of com.vaadin.flow.dom.PropertyChangeListener in project flow by vaadin.
the class ElementPropertyMapTest method listenerIsNotified.
private void listenerIsNotified(boolean clientEvent) {
ElementPropertyMap map = createSimplePropertyMap();
StateNode node = map.getNode();
AtomicReference<PropertyChangeEvent> event = new AtomicReference<>();
PropertyChangeListener listener = ev -> {
Assert.assertNull(event.get());
event.set(ev);
};
map.addPropertyChangeListener("foo", listener);
map.setProperty("foo", "bar", !clientEvent);
Assert.assertNull(event.get().getOldValue());
Assert.assertEquals("bar", event.get().getValue());
Assert.assertEquals("foo", event.get().getPropertyName());
Assert.assertEquals(Element.get(node), event.get().getSource());
Assert.assertEquals(clientEvent, event.get().isUserOriginated());
// listener is not called. Otherwise its assertion fails.
map.setProperty("bar", "foo");
}
use of com.vaadin.flow.dom.PropertyChangeListener 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);
}
use of com.vaadin.flow.dom.PropertyChangeListener in project flow by vaadin.
the class ElementPropertyMapTest method addSeveralPropertyChangeListeners_fireEvent_listenersAreNotified.
@Test
public void addSeveralPropertyChangeListeners_fireEvent_listenersAreNotified() {
ElementPropertyMap map = createSimplePropertyMap();
AtomicBoolean first = new AtomicBoolean();
AtomicBoolean second = new AtomicBoolean();
PropertyChangeListener listener1 = ev -> first.set(!first.get());
PropertyChangeListener listener2 = ev -> second.set(!second.get());
map.addPropertyChangeListener("foo", listener1);
map.addPropertyChangeListener("foo", listener2);
map.setProperty("foo", "bar", true);
Assert.assertTrue(first.get());
Assert.assertTrue(second.get());
}
Aggregations