* 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?
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;
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 {
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);