generic collection type resolution respects upper bound as well
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -31,18 +29,18 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.propertyeditors.CustomNumberEditor;
|
||||
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
|
||||
import test.beans.GenericBean;
|
||||
import test.beans.GenericIntegerBean;
|
||||
import test.beans.GenericSetOfIntegerBean;
|
||||
import test.beans.TestBean;
|
||||
|
||||
import org.springframework.beans.propertyeditors.CustomNumberEditor;
|
||||
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
@@ -62,6 +60,19 @@ public final class BeanWrapperGenericsTests {
|
||||
assertTrue(gb.getIntegerSet().contains(new Integer(5)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericLowerBoundedSet() {
|
||||
GenericBean<?> gb = new GenericBean<Object>();
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, true));
|
||||
Set<String> input = new HashSet<String>();
|
||||
input.add("4");
|
||||
input.add("5");
|
||||
bw.setPropertyValue("numberSet", input);
|
||||
assertTrue(gb.getNumberSet().contains(new Integer(4)));
|
||||
assertTrue(gb.getNumberSet().contains(new Integer(5)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericSetWithConversionFailure() {
|
||||
GenericBean<?> gb = new GenericBean<Object>();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,6 +34,8 @@ public class GenericBean<T> {
|
||||
|
||||
private Set<Integer> integerSet;
|
||||
|
||||
private Set<? extends Number> numberSet;
|
||||
|
||||
private List<Resource> resourceList;
|
||||
|
||||
private List<List<Integer>> listOfLists;
|
||||
@@ -105,6 +107,14 @@ public class GenericBean<T> {
|
||||
this.integerSet = integerSet;
|
||||
}
|
||||
|
||||
public Set<? extends Number> getNumberSet() {
|
||||
return numberSet;
|
||||
}
|
||||
|
||||
public void setNumberSet(Set<? extends Number> numberSet) {
|
||||
this.numberSet = numberSet;
|
||||
}
|
||||
|
||||
public List<Resource> getResourceList() {
|
||||
return resourceList;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user