diff options
author | Artur Signell <artur@vaadin.com> | 2014-05-28 15:29:28 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2014-05-28 15:30:41 +0300 |
commit | 7e948c19977f3be4320b39692d8f35f3a2e33264 (patch) | |
tree | 873bddce219ea9725c979f32862cbf3d74dec90c | |
parent | a25aab4ca166ff1989f04eef41fde2e9c01131b2 (diff) | |
download | vaadin-framework-7e948c19977f3be4320b39692d8f35f3a2e33264.tar.gz vaadin-framework-7e948c19977f3be4320b39692d8f35f3a2e33264.zip |
Allow use of Collection<String> and others with addItems (#13865)
Change-Id: Ie5c0a00b65d27f65522a14c4fbcd05fe21814cc0
-rw-r--r-- | server/src/com/vaadin/ui/AbstractSelect.java | 2 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/ui/AbstractSelectTest.java | 76 |
2 files changed, 77 insertions, 1 deletions
diff --git a/server/src/com/vaadin/ui/AbstractSelect.java b/server/src/com/vaadin/ui/AbstractSelect.java index c6abb8e685..b8db329906 100644 --- a/server/src/com/vaadin/ui/AbstractSelect.java +++ b/server/src/com/vaadin/ui/AbstractSelect.java @@ -904,7 +904,7 @@ public abstract class AbstractSelect extends AbstractField<Object> implements * if the underlying container don't support adding items with * identifiers */ - public void addItems(Collection<Object> itemIds) + public void addItems(Collection<?> itemIds) throws UnsupportedOperationException { addItems(itemIds.toArray()); } diff --git a/server/tests/src/com/vaadin/ui/AbstractSelectTest.java b/server/tests/src/com/vaadin/ui/AbstractSelectTest.java new file mode 100644 index 0000000000..83d66ee9d5 --- /dev/null +++ b/server/tests/src/com/vaadin/ui/AbstractSelectTest.java @@ -0,0 +1,76 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.ui; + +import java.util.ArrayList; + +import org.junit.Assert; +import org.junit.Test; + +public class AbstractSelectTest { + + @Test + public void addItemsStrings() { + NativeSelect ns = new NativeSelect(); + ns.addItems("Foo", "bar", "baz"); + Assert.assertEquals(3, ns.size()); + Assert.assertArrayEquals(new Object[] { "Foo", "bar", "baz" }, ns + .getItemIds().toArray()); + } + + @Test + public void addItemsObjects() { + Object o1 = new Object(); + Object o2 = new Object(); + Object o3 = new Object(); + + NativeSelect ns = new NativeSelect(); + ns.addItems(o1, o2, o3); + Assert.assertEquals(3, ns.size()); + Assert.assertArrayEquals(new Object[] { o1, o2, o3 }, ns.getItemIds() + .toArray()); + } + + @Test + public void addItemsStringList() { + ArrayList<String> itemIds = new ArrayList<String>(); + itemIds.add("foo"); + itemIds.add("bar"); + itemIds.add("baz"); + NativeSelect ns = new NativeSelect(); + ns.addItems(itemIds); + Assert.assertEquals(3, ns.size()); + Assert.assertArrayEquals(new Object[] { "foo", "bar", "baz" }, ns + .getItemIds().toArray()); + } + + @Test + public void addItemsObjectList() { + Object o1 = new Object(); + Object o2 = new Object(); + Object o3 = new Object(); + ArrayList<Object> itemIds = new ArrayList<Object>(); + itemIds.add(o1); + itemIds.add(o2); + itemIds.add(o3); + NativeSelect ns = new NativeSelect(); + ns.addItems(itemIds); + Assert.assertEquals(3, ns.size()); + Assert.assertArrayEquals(new Object[] { o1, o2, o3 }, ns.getItemIds() + .toArray()); + + } +} |