|
|
@@ -29,6 +29,7 @@ import org.junit.rules.ExpectedException; |
|
|
|
import com.vaadin.data.Binder.Binding; |
|
|
|
import com.vaadin.data.Binder.BindingBuilder; |
|
|
|
import com.vaadin.data.converter.StringToBigDecimalConverter; |
|
|
|
import com.vaadin.data.converter.StringToDoubleConverter; |
|
|
|
import com.vaadin.data.converter.StringToIntegerConverter; |
|
|
|
import com.vaadin.data.validator.IntegerRangeValidator; |
|
|
|
import com.vaadin.data.validator.NotEmptyValidator; |
|
|
@@ -43,6 +44,8 @@ import org.hamcrest.CoreMatchers; |
|
|
|
|
|
|
|
public class BinderTest extends BinderTestBase<Binder<Person>, Person> { |
|
|
|
|
|
|
|
private int count; |
|
|
|
|
|
|
|
@Rule |
|
|
|
/* |
|
|
|
* transient to avoid interfering with serialization tests that capture a |
|
|
@@ -1487,6 +1490,34 @@ public class BinderTest extends BinderTestBase<Binder<Person>, Person> { |
|
|
|
binder.readBean(new AtomicReference<>(null)); |
|
|
|
} |
|
|
|
|
|
|
|
// See: https://github.com/vaadin/framework/issues/12356 |
|
|
|
@Test |
|
|
|
public void validationShouldNotRunTwice() { |
|
|
|
TextField salaryField = new TextField(); |
|
|
|
count = 0; |
|
|
|
item.setSalaryDouble(100d); |
|
|
|
binder.forField(salaryField) |
|
|
|
.withConverter(new StringToDoubleConverter("")) |
|
|
|
.bind(Person::getSalaryDouble, Person::setSalaryDouble); |
|
|
|
binder.setBean(item); |
|
|
|
binder.addValueChangeListener(event -> { |
|
|
|
count++; |
|
|
|
}); |
|
|
|
|
|
|
|
salaryField.setValue("1000"); |
|
|
|
assertTrue(binder.isValid()); |
|
|
|
|
|
|
|
salaryField.setValue("salary"); |
|
|
|
assertFalse(binder.isValid()); |
|
|
|
|
|
|
|
salaryField.setValue("2000"); |
|
|
|
|
|
|
|
// Without fix for #12356 count will be 5 |
|
|
|
assertEquals(3, count); |
|
|
|
|
|
|
|
assertEquals(new Double(2000), item.getSalaryDouble()); |
|
|
|
} |
|
|
|
|
|
|
|
private TextField createNullAnd42RejectingFieldWithEmptyValue( |
|
|
|
String emptyValue) { |
|
|
|
return new TextField() { |