use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method beanBinder_withConverter_nullRepresentationIsNotDisabled.
@Test
public void beanBinder_withConverter_nullRepresentationIsNotDisabled() {
String customNullPointerRepresentation = "foo";
Binder<Person> binder = new Binder<>(Person.class);
binder.forField(nameField).withConverter(value -> value, value -> value == null ? customNullPointerRepresentation : value).bind("firstName");
Person person = new Person();
binder.setBean(person);
Assert.assertEquals(customNullPointerRepresentation, nameField.getValue());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method load_bound_fieldValueIsUpdated.
@Test
public void load_bound_fieldValueIsUpdated() {
binder.bind(nameField, Person::getFirstName, Person::setFirstName);
Person person = new Person();
String name = "bar";
person.setFirstName(name);
binder.readBean(person);
Assert.assertEquals(name, nameField.getValue());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method load_unbound_noChanges.
@Test
public void load_unbound_noChanges() {
nameField.setValue("");
Person person = new Person();
String name = "bar";
person.setFirstName(name);
binder.readBean(person);
Assert.assertEquals("", nameField.getValue());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method setRequired_withErrorMessageProvider_fieldGetsRequiredIndicatorAndValidator.
@Test
public void setRequired_withErrorMessageProvider_fieldGetsRequiredIndicatorAndValidator() {
TestTextField textField = new TestTextField();
assertFalse(textField.isRequiredIndicatorVisible());
BindingBuilder<Person, String> binding = binder.forField(textField);
assertFalse(textField.isRequiredIndicatorVisible());
AtomicInteger invokes = new AtomicInteger();
binding.asRequired(context -> {
invokes.incrementAndGet();
return "foobar";
});
assertTrue(textField.isRequiredIndicatorVisible());
binding.bind(Person::getFirstName, Person::setFirstName);
binder.setBean(item);
assertThat(textField.getErrorMessage(), isEmptyString());
Assert.assertEquals(0, invokes.get());
textField.setValue(textField.getEmptyValue());
Assert.assertEquals("foobar", componentErrors.get(textField));
// validation is done for all changed bindings once.
Assert.assertEquals(1, invokes.get());
textField.setValue("value");
assertFalse(textField.isInvalid());
assertTrue(textField.isRequiredIndicatorVisible());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method settingAsRequiredEnabledFalseWhenNoAsRequired.
@Test(expected = IllegalStateException.class)
public void settingAsRequiredEnabledFalseWhenNoAsRequired() {
TestTextField textField = new TestTextField();
BindingBuilder<Person, String> bindingBuilder = binder.forField(textField);
Binding<Person, String> binding = bindingBuilder.bind(Person::getFirstName, Person::setFirstName);
binder.readBean(item);
// TextField input is not set required, this should trigger
// IllegalStateExceptipon
binding.setAsRequiredEnabled(false);
}
Aggregations