use of com.vaadin.flow.data.binder.testcomponents.TestTextField 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.data.binder.testcomponents.TestTextField in project flow by vaadin.
the class BinderTestBase method setUpBase.
@Before
public void setUpBase() {
UI ui = new UI() {
@Override
public Locale getLocale() {
return Locale.US;
}
};
nameField = new TestTextField();
ageField = new TestTextField();
ui.add(nameField, ageField);
}
use of com.vaadin.flow.data.binder.testcomponents.TestTextField 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);
}
Aggregations