use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method binding_with_null_representation_value_not_null.
@Test
public void binding_with_null_representation_value_not_null() {
String nullRepresentation = "Some arbitrary text";
binder.forField(nameField).withNullRepresentation(nullRepresentation).bind(Person::getFirstName, Person::setFirstName);
assertFalse("First name in item should not be null", Objects.isNull(item.getFirstName()));
binder.setBean(item);
Assert.assertEquals("Field value was not set correctly", item.getFirstName(), nameField.getValue());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderTest method binding_with_default_null_representation.
@Test
public void binding_with_default_null_representation() {
TestTextField nullTextField = new TestTextField() {
@Override
public String getEmptyValue() {
return "null";
}
};
Person namelessPerson = new Person(null, "Doe", "", 25, Sex.UNKNOWN, null);
binder.bind(nullTextField, Person::getFirstName, Person::setFirstName);
binder.setBean(namelessPerson);
assertTrue(nullTextField.isEmpty());
Assert.assertEquals("null", namelessPerson.getFirstName());
// Change value, see that textfield is not empty and bean is updated.
nullTextField.setValue("");
assertFalse(nullTextField.isEmpty());
Assert.assertEquals("First name of person was not properly updated", "", namelessPerson.getFirstName());
// Verify that default null representation does not map back to null
nullTextField.setValue("null");
assertTrue(nullTextField.isEmpty());
Assert.assertEquals("Default one-way null representation failed.", "null", namelessPerson.getFirstName());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderStatusChangeTest method setUp.
@Before
public void setUp() {
binder = new Binder<>();
item = new Person();
event = new AtomicReference<>();
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderValueChangeTest method userOriginatedUpdate_unbound_singleEventOnSetValue.
@Test
public void userOriginatedUpdate_unbound_singleEventOnSetValue() {
TestTextField field = new TestTextField();
binder.forField(field).bind(Person::getFirstName, Person::setFirstName);
binder.forField(ageField).withConverter(new StringToIntegerConverter("")).bind(Person::getAge, Person::setAge);
binder.addValueChangeListener(this::statusChanged);
Assert.assertNull(event.get());
field.getElement().getNode().getFeature(ElementPropertyMap.class).setProperty("value", "foo", false);
verifyEvent(field, true);
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderValidationStatusTest method bindingWithStatusLabel_setAfterHandler.
@Test(expected = IllegalStateException.class)
public void bindingWithStatusLabel_setAfterHandler() {
TestLabel label = new TestLabel();
BindingBuilder<Person, String> binding = binder.forField(nameField);
binding.withValidationStatusHandler(NOOP);
binding.withStatusLabel(label);
}
Aggregations