Search in sources :

Example 1 with StringToDoubleConverter

use of com.vaadin.flow.data.converter.StringToDoubleConverter in project flow by vaadin.

the class BinderTest method validationShouldNotRunTwice.

@Test
public void validationShouldNotRunTwice() {
    TestTextField salaryField = new TestTextField();
    AtomicInteger count = new AtomicInteger(0);
    item.setSalaryDouble(100d);
    binder.forField(salaryField).withConverter(new StringToDoubleConverter("")).bind(Person::getSalaryDouble, Person::setSalaryDouble);
    binder.setBean(item);
    binder.addValueChangeListener(event -> {
        count.incrementAndGet();
    });
    salaryField.setValue("1000");
    assertTrue(binder.isValid());
    assertEquals(1, count.get());
    salaryField.setValue("salary");
    assertFalse(binder.isValid());
    assertEquals(2, count.get());
    salaryField.setValue("2000");
    // Without fix for #12356 count will be 5
    assertEquals(3, count.get());
    assertEquals(new Double(2000), item.getSalaryDouble());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestTextField(com.vaadin.flow.data.binder.testcomponents.TestTextField) StringToDoubleConverter(com.vaadin.flow.data.converter.StringToDoubleConverter) Person(com.vaadin.flow.tests.data.bean.Person) Test(org.junit.Test)

Aggregations

TestTextField (com.vaadin.flow.data.binder.testcomponents.TestTextField)1 StringToDoubleConverter (com.vaadin.flow.data.converter.StringToDoubleConverter)1 Person (com.vaadin.flow.tests.data.bean.Person)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1