From: Artur Signell Date: Thu, 8 Dec 2011 13:04:33 +0000 (+0000) Subject: #6603 Added IllegalArgumentException to javadoc and added test X-Git-Tag: 7.0.0.alpha1~225^2^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e968734dfa87136d7a488156789edf77cac1d7f6;p=vaadin-framework.git #6603 Added IllegalArgumentException to javadoc and added test svn changeset:22320/svn branch:6.7 --- diff --git a/src/com/vaadin/data/util/AbstractBeanContainer.java b/src/com/vaadin/data/util/AbstractBeanContainer.java index 0e4feaab32..6260e05518 100644 --- a/src/com/vaadin/data/util/AbstractBeanContainer.java +++ b/src/com/vaadin/data/util/AbstractBeanContainer.java @@ -626,9 +626,12 @@ public abstract class AbstractBeanContainer 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 collection) - throws IllegalStateException { + throws IllegalStateException, IllegalArgumentException { boolean modified = false; for (BEANTYPE bean : collection) { // TODO skipping invalid beans - should not allow them in javadoc? diff --git a/tests/server-side/com/vaadin/data/util/BeanContainerTest.java b/tests/server-side/com/vaadin/data/util/BeanContainerTest.java index 5a753e19d0..d9fa8d896e 100644 --- a/tests/server-side/com/vaadin/data/util/BeanContainerTest.java +++ b/tests/server-side/com/vaadin/data/util/BeanContainerTest.java @@ -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 container = new BeanContainer( + Person.class); + // resolver that returns null as item id + container + .setBeanIdResolver(new BeanIdResolver() { + + public String getIdForBean(Person bean) { + return bean.getName(); + } + }); + + List persons = new ArrayList(); + 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 container = new BeanContainer( Person.class);