]> source.dussan.org Git - vaadin-framework.git/commitdiff
#6603 Added IllegalArgumentException to javadoc and added test
authorArtur Signell <artur.signell@itmill.com>
Thu, 8 Dec 2011 13:04:33 +0000 (13:04 +0000)
committerArtur Signell <artur.signell@itmill.com>
Thu, 8 Dec 2011 13:04:33 +0000 (13:04 +0000)
svn changeset:22320/svn branch:6.7

src/com/vaadin/data/util/AbstractBeanContainer.java
tests/server-side/com/vaadin/data/util/BeanContainerTest.java

index 0e4feaab32b1f463108e8be89ac4e421f161bec9..6260e05518c6a454d4f532733ef1bd37791f4e38 100644 (file)
@@ -626,9 +626,12 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends
      *            The collection of beans to add. Must not be null.
      * @throws IllegalStateException
      *             if no bean identifier resolver has been set
+     * @throws IllegalArgumentException
+     *             if the resolver returns a null itemId for one of the beans in
+     *             the collection
      */
     protected void addAll(Collection<? extends BEANTYPE> collection)
-            throws IllegalStateException {
+            throws IllegalStateException, IllegalArgumentException {
         boolean modified = false;
         for (BEANTYPE bean : collection) {
             // TODO skipping invalid beans - should not allow them in javadoc?
index 5a753e19d003bdba158d9f89d110a45b26150bbe..d9fa8d896ef04398c7107d2015560604a26fe39f 100644 (file)
@@ -1,7 +1,9 @@
 package com.vaadin.data.util;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
@@ -10,7 +12,6 @@ import junit.framework.Assert;
 import com.vaadin.data.Container;
 import com.vaadin.data.Item;
 import com.vaadin.data.util.AbstractBeanContainer.BeanIdResolver;
-import com.vaadin.data.util.BeanContainer;
 
 public class BeanContainerTest extends AbstractBeanContainerTest {
 
@@ -324,6 +325,37 @@ public class BeanContainerTest extends AbstractBeanContainerTest {
         assertEquals(0, container.size());
     }
 
+    public void testAddAllWithNullItemId() {
+        BeanContainer<String, Person> container = new BeanContainer<String, Person>(
+                Person.class);
+        // resolver that returns null as item id
+        container
+                .setBeanIdResolver(new BeanIdResolver<String, AbstractBeanContainerTest.Person>() {
+
+                    public String getIdForBean(Person bean) {
+                        return bean.getName();
+                    }
+                });
+
+        List<Person> persons = new ArrayList<Person>();
+        persons.add(new Person("John"));
+        persons.add(new Person("Marc"));
+        persons.add(new Person(null));
+        persons.add(new Person("foo"));
+
+        try {
+            container.addAll(persons);
+            fail();
+        } catch (IllegalArgumentException e) {
+            // should get exception
+        }
+
+        container.removeAllItems();
+        persons.remove(2);
+        container.addAll(persons);
+        assertEquals(3, container.size());
+    }
+
     public void testAddBeanWithNullResolver() {
         BeanContainer<String, Person> container = new BeanContainer<String, Person>(
                 Person.class);