use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method beanBinder_nullRepresentationIsNotDisabled.
@Test
public void beanBinder_nullRepresentationIsNotDisabled() {
Binder<Person> binder = new Binder<>(Person.class);
binder.forField(nameField).bind("firstName");
Person person = new Person();
binder.setBean(person);
Assert.assertEquals("", nameField.getValue());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method readNullBeanRemovesError.
@Test
public void readNullBeanRemovesError() {
TestTextField textField = new TestTextField();
binder.forField(textField).asRequired("foobar").bind(Person::getFirstName, Person::setFirstName);
Assert.assertTrue(textField.isRequiredIndicatorVisible());
Assert.assertNull(componentErrors.get(textField));
binder.readBean(item);
Assert.assertNull(componentErrors.get(textField));
textField.setValue(textField.getEmptyValue());
Assert.assertTrue(textField.isRequiredIndicatorVisible());
Assert.assertNotNull(componentErrors.get(textField));
binder.readBean(null);
assertTrue(textField.isRequiredIndicatorVisible());
Assert.assertNull(componentErrors.get(textField));
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method setReadOnly_binderLoadedByReadBean.
@Test
public void setReadOnly_binderLoadedByReadBean() {
binder.forField(nameField).bind(Person::getFirstName, Person::setFirstName);
binder.forField(ageField).withConverter(new StringToIntegerConverter("")).bind(Person::getAge, Person::setAge);
binder.readBean(new Person());
binder.setReadOnly(true);
assertTrue(nameField.isReadOnly());
assertTrue(ageField.isReadOnly());
binder.setReadOnly(false);
assertFalse(nameField.isReadOnly());
assertFalse(ageField.isReadOnly());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method multiple_calls_to_same_binding_builder.
@Test
public void multiple_calls_to_same_binding_builder() {
String stringLength = "String length failure";
String conversion = "Conversion failed";
String ageLimit = "Age not in valid range";
BindingValidationStatus validation;
binder = new Binder<>(Person.class);
BindingBuilder builder = binder.forField(ageField);
builder.withValidator(new StringLengthValidator(stringLength, 0, 3));
builder.withConverter(new StringToIntegerConverter(conversion));
builder.withValidator(new IntegerRangeValidator(ageLimit, 3, 150));
Binding<Person, ?> bind = builder.bind("age");
binder.setBean(item);
ageField.setValue("123123");
validation = bind.validate();
Assert.assertTrue(validation.isError());
Assert.assertEquals(stringLength, validation.getMessage().get());
ageField.setValue("age");
validation = bind.validate();
Assert.assertTrue(validation.isError());
Assert.assertEquals(conversion, validation.getMessage().get());
ageField.setValue("256");
validation = bind.validate();
Assert.assertTrue(validation.isError());
Assert.assertEquals(ageLimit, validation.getMessage().get());
ageField.setValue("30");
validation = bind.validate();
Assert.assertFalse(validation.isError());
Assert.assertEquals(30, item.getAge());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method save_unbound_noChanges.
@Test
public void save_unbound_noChanges() throws ValidationException {
Binder<Person> binder = new Binder<>();
Person person = new Person();
int age = 10;
person.setAge(age);
binder.writeBean(person);
Assert.assertEquals(age, person.getAge());
}
Aggregations