use of com.vaadin.flow.data.validator.IntegerRangeValidator 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());
}
Aggregations