use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method execute_binding_status_handler_from_binder_status_handler.
@Test
public void execute_binding_status_handler_from_binder_status_handler() {
MyBindingHandler bindingHandler = new MyBindingHandler();
binder.forField(nameField).withValidator(t -> !t.isEmpty(), "No empty values.").withValidationStatusHandler(bindingHandler).bind(Person::getFirstName, Person::setFirstName);
String ageError = "CONVERSIONERROR";
binder.forField(ageField).withConverter(new StringToIntegerConverter(ageError)).bind(Person::getAge, Person::setAge);
binder.setValidationStatusHandler(BinderValidationStatus::notifyBindingValidationStatusHandlers);
String initialName = item.getFirstName();
int initialAge = item.getAge();
binder.setBean(item);
// Test specific error handling.
bindingHandler.expectingError = true;
nameField.setValue("");
// Test default error handling.
ageField.setValue("foo");
assertThat("Error message is not what was expected", ageField.getErrorMessage(), containsString(ageError));
// Restore values and test no errors.
ageField.setValue(String.valueOf(initialAge));
assertFalse("The field should be valid", ageField.isInvalid());
bindingHandler.expectingError = false;
nameField.setValue(initialName);
// Assert that the handler was called.
assertEquals("Unexpected callCount to binding validation status handler", 6, bindingHandler.callCount);
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderValidationStatusTest method binderWithStatusLabel_addAfterBound.
@Test(expected = IllegalStateException.class)
public void binderWithStatusLabel_addAfterBound() {
Label label = new Label();
BindingBuilder<Person, String> binding = binder.forField(nameField).withValidator(notEmpty);
binding.bind(Person::getFirstName, Person::setFirstName);
binding.withStatusLabel(label);
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderValidationStatusTest method bindingWithStatusLabel_addAfterBound.
@Test(expected = IllegalStateException.class)
public void bindingWithStatusLabel_addAfterBound() {
Label label = new Label();
BindingBuilder<Person, String> binding = binder.forField(nameField).withValidator(notEmpty);
binding.bind(Person::getFirstName, Person::setFirstName);
binding.withStatusLabel(label);
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderValidationStatusTest method setUp.
@Before
public void setUp() {
binder = new Binder<Person>() {
@Override
protected void handleError(HasValue<?, ?> field, ValidationResult result) {
componentErrors.put(field, result.getErrorMessage());
}
@Override
protected void clearError(HasValue<?, ?> field) {
super.clearError(field);
componentErrors.remove(field);
}
};
item = new Person();
item.setFirstName("Johannes");
item.setAge(32);
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderValidationStatusTest method bindingWithStatusHandler_setAfterLabel.
@Test(expected = IllegalStateException.class)
public void bindingWithStatusHandler_setAfterLabel() {
Label label = new Label();
BindingBuilder<Person, String> binding = binder.forField(nameField);
binding.withStatusLabel(label);
binding.withValidationStatusHandler(NOOP);
}
Aggregations