use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method addStatusListenerFromStatusListener_listenerAdded.
@Test
public void addStatusListenerFromStatusListener_listenerAdded() {
AtomicBoolean outerListenerInvoked = new AtomicBoolean();
AtomicBoolean innerListenerInvoked = new AtomicBoolean();
binder.addStatusChangeListener(event -> {
if (!outerListenerInvoked.getAndSet(true)) {
binder.addStatusChangeListener(event2 -> {
innerListenerInvoked.set(true);
});
}
});
// Trigger status change event
binder.setBean(new Person());
Assert.assertTrue("Outer listener should be invoked", outerListenerInvoked.get());
Assert.assertFalse("Inner listener should not (yet) be invoked", innerListenerInvoked.get());
// Trigger status change event
binder.setBean(new Person());
Assert.assertTrue("Inner listener should be invoked", innerListenerInvoked.get());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method withValidator_doesNotDisablesDefaulNullRepresentation.
@Test
public void withValidator_doesNotDisablesDefaulNullRepresentation() {
String nullRepresentation = "foo";
binder.forField(nameField).withNullRepresentation(nullRepresentation).withValidator(new NotEmptyValidator<>("")).bind(Person::getFirstName, Person::setFirstName);
item.setFirstName(null);
binder.setBean(item);
Assert.assertEquals(nullRepresentation, nameField.getValue());
String newValue = "bar";
nameField.setValue(newValue);
Assert.assertEquals(newValue, item.getFirstName());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method writeBean_converterThrows_exceptionHandlerSet_bindingExceptionIsThrown.
@Test(expected = BindingException.class)
public void writeBean_converterThrows_exceptionHandlerSet_bindingExceptionIsThrown() throws ValidationException {
TestTextField testField = new TestTextField();
setExceptionHandler();
binder.forField(testField).withConverter(Converter.<String, String>from(name -> {
throw new NullPointerException();
}, name -> name)).bind(Person::getFirstName, Person::setFirstName);
binder.writeBean(new Person());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method withConverter_hasChangesFalse.
// See: https://github.com/vaadin/framework/issues/9581
@Test
public void withConverter_hasChangesFalse() {
TestTextField nameField = new TestTextField();
nameField.setValue("");
TestTextField rentField = new TestTextField();
rentField.setValue("");
rentField.addValueChangeListener(event -> {
nameField.setValue("Name");
});
item.setRent(BigDecimal.valueOf(10));
binder.forField(nameField).bind(Person::getFirstName, Person::setFirstName);
binder.forField(rentField).withConverter(new EuroConverter("")).withNullRepresentation(BigDecimal.valueOf(0d)).bind(Person::getRent, Person::setRent);
binder.readBean(item);
assertFalse(binder.hasChanges());
assertEquals("€ 10.00", rentField.getValue());
assertEquals("Name", nameField.getValue());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method writeBean_getValueThrows_exceptionHandlerSet_bindingExceptionIsThrown.
@Test(expected = BindingException.class)
public void writeBean_getValueThrows_exceptionHandlerSet_bindingExceptionIsThrown() throws ValidationException {
TestTextField testField = new ThrowingGetter();
setExceptionHandler();
binder.forField(testField).bind(Person::getFirstName, Person::setFirstName);
binder.writeBean(new Person());
}
Aggregations