aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/test
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-06-15 20:04:38 +0300
committerGitHub <noreply@github.com>2017-06-15 20:04:38 +0300
commit2c5dd49f00672b8df3c81609a9e82a04b9aabd03 (patch)
tree56d5cd81559f00487c3143981f41ac4af3f2c972 /server/src/test
parent620b413478976474a00ddd368309931e7417b41b (diff)
downloadvaadin-framework-2c5dd49f00672b8df3c81609a9e82a04b9aabd03.tar.gz
vaadin-framework-2c5dd49f00672b8df3c81609a9e82a04b9aabd03.zip
Only throw from Binder.bindInstanceFields if there are no bindings at all (#9487)8.1.0.beta2
Fixes #8986
Diffstat (limited to 'server/src/test')
-rw-r--r--server/src/test/java/com/vaadin/data/BeanBinderTest.java49
-rw-r--r--server/src/test/java/com/vaadin/data/BinderInstanceFieldTest.java13
2 files changed, 56 insertions, 6 deletions
diff --git a/server/src/test/java/com/vaadin/data/BeanBinderTest.java b/server/src/test/java/com/vaadin/data/BeanBinderTest.java
index f494d71555..0b67097d54 100644
--- a/server/src/test/java/com/vaadin/data/BeanBinderTest.java
+++ b/server/src/test/java/com/vaadin/data/BeanBinderTest.java
@@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import java.io.Serializable;
+import java.time.LocalDate;
import java.util.List;
import java.util.Set;
@@ -35,6 +36,9 @@ public class BeanBinderTest
private TextField number = new TextField();
}
+ private class TestClassWithoutFields {
+ }
+
private static class TestBean implements Serializable {
private Set<TestEnum> enums;
private int number;
@@ -145,6 +149,22 @@ public class BeanBinderTest
}
}
+ public static class Person {
+ LocalDate mydate;
+
+ public LocalDate getMydate() {
+ return mydate;
+ }
+
+ public void setMydate(LocalDate mydate) {
+ this.mydate = mydate;
+ }
+ }
+
+ public static class PersonForm {
+ private TextField mydate = new TextField();
+ }
+
@Before
public void setUp() {
binder = new BeanValidationBinder<>(BeanToValidate.class);
@@ -195,6 +215,35 @@ public class BeanBinderTest
}
@Test(expected = IllegalStateException.class)
+ public void bindInstanceFields_throw_if_no_fields_bound() {
+ Binder<TestBean> otherBinder = new Binder<>(TestBean.class);
+ TestClassWithoutFields testClass = new TestClassWithoutFields();
+
+ // Should throw an IllegalStateException no fields are bound
+ otherBinder.bindInstanceFields(testClass);
+ }
+
+ @Test
+ public void bindInstanceFields_does_not_throw_if_fields_are_bound_manually() {
+ PersonForm form = new PersonForm();
+ Binder<Person> binder = new Binder<>(Person.class);
+ binder.forMemberField(form.mydate)
+ .withConverter(str -> LocalDate.now(), date -> "Hello")
+ .bind("mydate");
+ binder.bindInstanceFields(form);
+
+ }
+
+ @Test
+ public void bindInstanceFields_does_not_throw_if_there_are_incomplete_bindings() {
+ PersonForm form = new PersonForm();
+ Binder<Person> binder = new Binder<>(Person.class);
+ binder.forMemberField(form.mydate).withConverter(str -> LocalDate.now(),
+ date -> "Hello");
+ binder.bindInstanceFields(form);
+ }
+
+ @Test(expected = IllegalStateException.class)
public void incomplete_forMemberField_bindings() {
Binder<TestBean> otherBinder = new Binder<>(TestBean.class);
TestClass testClass = new TestClass();
diff --git a/server/src/test/java/com/vaadin/data/BinderInstanceFieldTest.java b/server/src/test/java/com/vaadin/data/BinderInstanceFieldTest.java
index d0cd75649d..b09283936d 100644
--- a/server/src/test/java/com/vaadin/data/BinderInstanceFieldTest.java
+++ b/server/src/test/java/com/vaadin/data/BinderInstanceFieldTest.java
@@ -414,8 +414,8 @@ public class BinderInstanceFieldTest {
Assert.assertEquals("90", form.age.getValue());
}
- @Test(expected = IllegalStateException.class)
- public void bindInstanceFields_explicitelyBoundFieldAndNotBoundField_throwNoBoundFields() {
+ @Test
+ public void bindInstanceFields_explicitelyBoundFieldAndNotBoundField() {
BindOnlyOneField form = new BindOnlyOneField();
Binder<Person> binder = new Binder<>(Person.class);
@@ -424,8 +424,8 @@ public class BinderInstanceFieldTest {
binder.bindInstanceFields(form);
}
- @Test(expected = IllegalStateException.class)
- public void bindInstanceFields_tentativelyBoundFieldAndNotBoundField_throwNoBoundFields() {
+ @Test
+ public void bindInstanceFields_tentativelyBoundFieldAndNotBoundField() {
BindOnlyOneField form = new BindOnlyOneField();
Binder<Person> binder = new Binder<>(Person.class);
@@ -436,8 +436,9 @@ public class BinderInstanceFieldTest {
// manually
binder.forMemberField(field);
- // bindInstance expects at least one auto configured field (there is no
- // such, only incomplete one) and fails
+ // bindInstanceFields will not complain even though it can't bind
+ // anything as there is a binding in progress (an exception will be
+ // thrown later if the binding is not completed)
binder.bindInstanceFields(form);
}
}