diff options
author | Denis Anisimov <denis@vaadin.com> | 2016-09-16 21:57:40 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-09-21 09:02:55 +0000 |
commit | 3db7de6eac975f75e76fafc1352f09cf2ac6fa53 (patch) | |
tree | e11b9bd81ea49f6ebc4727a1bb910262cfa29f59 /server | |
parent | 53427c897cacc979d8378d46cd8b72fd0cd2fbe6 (diff) | |
download | vaadin-framework-3db7de6eac975f75e76fafc1352f09cf2ac6fa53.tar.gz vaadin-framework-3db7de6eac975f75e76fafc1352f09cf2ac6fa53.zip |
Make CheckBoxGroup.SimpleMultiSelectModel return a selection copy #293.
getSelectedItems() must return a copy to fulfill the contract specified
in SelectionModel: it must be a snapshot of the current state and safe
to iterate over while changing selection.
Change-Id: Ie2f15eb626dd80df2036bcb2d4e9387fc31389c9
Diffstat (limited to 'server')
-rw-r--r-- | server/src/main/java/com/vaadin/ui/CheckBoxGroup.java | 2 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/data/BinderMultiSelectTest.java | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/server/src/main/java/com/vaadin/ui/CheckBoxGroup.java b/server/src/main/java/com/vaadin/ui/CheckBoxGroup.java index 8525dc6cbb..d5b2c5a851 100644 --- a/server/src/main/java/com/vaadin/ui/CheckBoxGroup.java +++ b/server/src/main/java/com/vaadin/ui/CheckBoxGroup.java @@ -71,7 +71,7 @@ public class CheckBoxGroup<T> extends AbstractMultiSelect<T> { @Override public Set<T> getSelectedItems() { - return Collections.unmodifiableSet(selection); + return Collections.unmodifiableSet(new LinkedHashSet<>(selection)); } @Override diff --git a/server/src/test/java/com/vaadin/data/BinderMultiSelectTest.java b/server/src/test/java/com/vaadin/data/BinderMultiSelectTest.java index 93f4ccdac4..fd75c930f3 100644 --- a/server/src/test/java/com/vaadin/data/BinderMultiSelectTest.java +++ b/server/src/test/java/com/vaadin/data/BinderMultiSelectTest.java @@ -118,6 +118,20 @@ public class BinderMultiSelectTest } @Test + public void bound_setSelection_beanValueIsACopy() { + bindEnum(); + + select.select(TestEnum.TWO); + + Set<TestEnum> enums = item.getEnums(); + + binder.bind(new BeanWithEnums()); + select.select(TestEnum.ONE); + + assertEquals(Collections.singleton(TestEnum.TWO), enums); + } + + @Test public void bound_deselect_beanValueUpdatedToNull() { item.setEnums(Collections.singleton(TestEnum.ONE)); bindEnum(); |