use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method invalidUsage_modifyFieldsInsideValidator_binderDoesNotThrow.
@Test
public void invalidUsage_modifyFieldsInsideValidator_binderDoesNotThrow() {
TestTextField field = new TestTextField();
AtomicBoolean validatorIsExecuted = new AtomicBoolean();
binder.forField(field).asRequired().withValidator((val, context) -> {
nameField.setValue("foo");
ageField.setValue("bar");
validatorIsExecuted.set(true);
return ValidationResult.ok();
}).bind(Person::getEmail, Person::setEmail);
binder.forField(nameField).bind(Person::getFirstName, Person::setFirstName);
binder.forField(ageField).bind(Person::getLastName, Person::setLastName);
binder.setBean(new Person());
field.setValue("baz");
// mostly self control, the main check is: not exception is thrown
Assert.assertTrue(validatorIsExecuted.get());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method bound_bindToAnotherBean_stopsUpdatingOriginal.
@Test
public void bound_bindToAnotherBean_stopsUpdatingOriginal() {
bindName();
nameField.setValue("Leif");
Person p2 = new Person();
p2.setFirstName("Marlon");
binder.setBean(p2);
assertEquals("Marlon", nameField.getValue());
assertEquals("Leif", item.getFirstName());
assertSame(p2, binder.getBean());
nameField.setValue("Ilia");
assertEquals("Ilia", p2.getFirstName());
assertEquals("Leif", item.getFirstName());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method withConverter_writeBackValueDisabled.
@Test
public void withConverter_writeBackValueDisabled() {
TestTextField rentField = new TestTextField();
rentField.setValue("");
Binding<Person, BigDecimal> binding = binder.forField(rentField).withConverter(new EuroConverter("")).withNullRepresentation(BigDecimal.valueOf(0d)).bind(Person::getRent, Person::setRent);
binder.setBean(item);
binding.setConvertBackToPresentation(false);
rentField.setValue("10");
assertNotEquals("€ 10.00", rentField.getValue());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method withConverter_disablesDefaulNullRepresentation.
@Test
public void withConverter_disablesDefaulNullRepresentation() {
Integer customNullConverter = 0;
binder.forField(ageField).withNullRepresentation("foo").withConverter(new StringToIntegerConverter("")).withConverter(age -> age, age -> age == null ? customNullConverter : age).bind(Person::getSalary, Person::setSalary);
binder.setBean(item);
Assert.assertEquals(customNullConverter.toString(), ageField.getValue());
Integer salary = 11;
ageField.setValue(salary.toString());
Assert.assertEquals(11, salary.intValue());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method save_bound_beanIsUpdated.
@Test
public void save_bound_beanIsUpdated() throws ValidationException {
Binder<Person> binder = new Binder<>();
binder.bind(nameField, Person::getFirstName, Person::setFirstName);
Person person = new Person();
String fieldValue = "bar";
nameField.setValue(fieldValue);
person.setFirstName("foo");
binder.writeBean(person);
Assert.assertEquals(fieldValue, person.getFirstName());
}
Aggregations