From 4cacbf7d7fda2918bfb030c49cc6776a07bf6a9c Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Thu, 8 Feb 2018 15:21:33 +0200 Subject: Add setReadOnly for Bindings (#10482) --- .../src/test/java/com/vaadin/data/BinderTest.java | 48 +++++++++++++++++----- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'server/src/test') diff --git a/server/src/test/java/com/vaadin/data/BinderTest.java b/server/src/test/java/com/vaadin/data/BinderTest.java index 131dcb29b0..5988061cd5 100644 --- a/server/src/test/java/com/vaadin/data/BinderTest.java +++ b/server/src/test/java/com/vaadin/data/BinderTest.java @@ -612,24 +612,28 @@ public class BinderTest extends BinderTestBase, Person> { public void setReadonlyShouldIgnoreBindingsWithNullSetter() { binder.bind(nameField, Person::getFirstName, null); binder.forField(ageField) - .withConverter(new StringToIntegerConverter("")) - .bind(Person::getAge, Person::setAge); + .withConverter(new StringToIntegerConverter("")) + .bind(Person::getAge, Person::setAge); binder.setReadOnly(true); - assertTrue("Name field should be ignored but should be readonly", nameField.isReadOnly()); + assertTrue("Name field should be ignored but should be readonly", + nameField.isReadOnly()); assertTrue("Age field should be readonly", ageField.isReadOnly()); binder.setReadOnly(false); - assertTrue("Name field should be ignored and should remain readonly", nameField.isReadOnly()); + assertTrue("Name field should be ignored and should remain readonly", + nameField.isReadOnly()); assertFalse("Age field should not be readonly", ageField.isReadOnly()); nameField.setReadOnly(false); binder.setReadOnly(false); - assertFalse("Name field should be ignored and remain not readonly", nameField.isReadOnly()); + assertFalse("Name field should be ignored and remain not readonly", + nameField.isReadOnly()); assertFalse("Age field should not be readonly", ageField.isReadOnly()); binder.setReadOnly(true); - assertFalse("Name field should be ignored and remain not readonly", nameField.isReadOnly()); + assertFalse("Name field should be ignored and remain not readonly", + nameField.isReadOnly()); assertTrue("Age field should be readonly", ageField.isReadOnly()); } @@ -1045,14 +1049,38 @@ public class BinderTest extends BinderTestBase, Person> { binder.removeBinding(binding); } + @Test(expected = IllegalStateException.class) + public void bindWithNullSetterSetReadWrite() { + Binding binding = binder.bind(nameField, + Person::getFirstName, null); + binding.setReadOnly(false); + } + @Test public void bindWithNullSetterShouldMarkFieldAsReadonly() { - binder.bind(nameField, Person::getFirstName, null); + Binding nameBinding = binder.bind(nameField, + Person::getFirstName, null); binder.forField(ageField) - .withConverter(new StringToIntegerConverter("")) - .bind(Person::getAge, Person::setAge); + .withConverter(new StringToIntegerConverter("")) + .bind(Person::getAge, Person::setAge); + + assertTrue("Name field should be readonly", nameField.isReadOnly()); + assertFalse("Age field should not be readonly", ageField.isReadOnly()); + assertTrue("Binding should be marked readonly", + nameBinding.isReadOnly()); + } + + @Test + public void setReadOnly_binding() { + Binding binding = binder.bind(nameField, + Person::getFirstName, Person::setFirstName); + + assertFalse("Binding should not be readonly", binding.isReadOnly()); + assertFalse("Name field should not be readonly", + nameField.isReadOnly()); + binding.setReadOnly(true); + assertTrue("Binding should be readonly", binding.isReadOnly()); assertTrue("Name field should be readonly", nameField.isReadOnly()); - assertFalse("Name field should be readonly", ageField.isReadOnly()); } } -- cgit v1.2.3