+ polishing .beans tests

+ removed unnecessary dependency on hibernate
This commit is contained in:
Chris Beams 2008-12-24 19:14:15 +00:00
parent 3d634f1eb7
commit 670bfd5ee2
23 changed files with 216 additions and 131 deletions

View File

@ -11,7 +11,6 @@
<classpathentry kind="var" path="IVY_CACHE/net.sourceforge.cglib/com.springsource.net.sf.cglib/2.1.3/com.springsource.net.sf.cglib-2.1.3.jar" sourcepath="/IVY_CACHE/net.sourceforge.cglib/com.springsource.net.sf.cglib/2.1.3/com.springsource.net.sf.cglib-sources-2.1.3.jar"/> <classpathentry kind="var" path="IVY_CACHE/net.sourceforge.cglib/com.springsource.net.sf.cglib/2.1.3/com.springsource.net.sf.cglib-2.1.3.jar" sourcepath="/IVY_CACHE/net.sourceforge.cglib/com.springsource.net.sf.cglib/2.1.3/com.springsource.net.sf.cglib-sources-2.1.3.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.apache.log4j/com.springsource.org.apache.log4j/1.2.15/com.springsource.org.apache.log4j-1.2.15.jar" sourcepath="/IVY_CACHE/org.apache.log4j/com.springsource.org.apache.log4j/1.2.15/com.springsource.org.apache.log4j-sources-1.2.15.jar"/> <classpathentry kind="var" path="IVY_CACHE/org.apache.log4j/com.springsource.org.apache.log4j/1.2.15/com.springsource.org.apache.log4j-1.2.15.jar" sourcepath="/IVY_CACHE/org.apache.log4j/com.springsource.org.apache.log4j/1.2.15/com.springsource.org.apache.log4j-sources-1.2.15.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.junit/com.springsource.org.junit/4.5.0/com.springsource.org.junit-4.5.0.jar" sourcepath="/IVY_CACHE/org.junit/com.springsource.org.junit/4.5.0/com.springsource.org.junit-sources-4.5.0.jar"/> <classpathentry kind="var" path="IVY_CACHE/org.junit/com.springsource.org.junit/4.5.0/com.springsource.org.junit-4.5.0.jar" sourcepath="/IVY_CACHE/org.junit/com.springsource.org.junit/4.5.0/com.springsource.org.junit-sources-4.5.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.hibernate/com.springsource.org.hibernate/3.2.6.ga/com.springsource.org.hibernate-3.2.6.ga.jar" sourcepath="/IVY_CACHE/org.hibernate/com.springsource.org.hibernate/3.2.6.ga/com.springsource.org.hibernate-sources-3.2.6.ga.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-2.3.0.jar" sourcepath="/IVY_CACHE/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-sources-2.3.0.jar"/> <classpathentry kind="var" path="IVY_CACHE/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-2.3.0.jar" sourcepath="/IVY_CACHE/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-sources-2.3.0.jar"/>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

View File

@ -26,7 +26,6 @@
<dependency org="org.springframework" name="org.springframework.core" rev="latest.integration" conf="compile->compile"/> <dependency org="org.springframework" name="org.springframework.core" rev="latest.integration" conf="compile->compile"/>
<!-- test dependencies --> <!-- test dependencies -->
<dependency org="org.apache.log4j" name="com.springsource.org.apache.log4j" rev="1.2.15" conf="test->runtime"/> <dependency org="org.apache.log4j" name="com.springsource.org.apache.log4j" rev="1.2.15" conf="test->runtime"/>
<dependency org="org.hibernate" name="com.springsource.org.hibernate" rev="3.2.6.ga" conf="test->compile"/>
<dependency org="org.junit" name="com.springsource.org.junit" rev="4.5.0" conf="test->runtime"/> <dependency org="org.junit" name="com.springsource.org.junit" rev="4.5.0" conf="test->runtime"/>
<dependency org="org.easymock" name="com.springsource.org.easymock" rev="2.3.0" conf="test->compile"/> <dependency org="org.easymock" name="com.springsource.org.easymock" rev="2.3.0" conf="test->compile"/>
</dependencies> </dependencies>

View File

@ -30,6 +30,8 @@ import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceEditor; import org.springframework.core.io.ResourceEditor;
import test.beans.DerivedTestBean;
/** /**
* Unit tests for {@link BeanUtils}. * Unit tests for {@link BeanUtils}.
* *

View File

@ -20,6 +20,9 @@ import static org.junit.Assert.*;
import org.junit.Test; import org.junit.Test;
import test.beans.CustomEnum;
import test.beans.GenericBean;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams

View File

@ -38,6 +38,8 @@ import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource; import org.springframework.core.io.UrlResource;
import test.beans.GenericBean;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams

View File

@ -16,6 +16,8 @@
package org.springframework.beans; package org.springframework.beans;
import static org.junit.Assert.*;
import java.beans.PropertyEditorSupport; import java.beans.PropertyEditorSupport;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
@ -34,11 +36,11 @@ import java.util.SortedMap;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.Map.Entry;
import junit.framework.TestCase;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.hibernate.FlushMode; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.propertyeditors.CustomNumberEditor; import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.beans.propertyeditors.StringArrayPropertyEditor; import org.springframework.beans.propertyeditors.StringArrayPropertyEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor; import org.springframework.beans.propertyeditors.StringTrimmerEditor;
@ -46,14 +48,18 @@ import org.springframework.beans.support.DerivedFromProtectedBaseBean;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import test.beans.BooleanTestBean;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Alef Arendsen * @author Alef Arendsen
* @author Arjen Poutsma * @author Arjen Poutsma
* @author Chris Beams
*/ */
public class BeanWrapperTests extends TestCase { public final class BeanWrapperTests {
@Test
public void testIsReadablePropertyNotReadable() { public void testIsReadablePropertyNotReadable() {
NoRead nr = new NoRead(); NoRead nr = new NoRead();
BeanWrapper bw = new BeanWrapperImpl(nr); BeanWrapper bw = new BeanWrapperImpl(nr);
@ -63,12 +69,14 @@ public class BeanWrapperTests extends TestCase {
/** /**
* Shouldn't throw an exception: should just return false * Shouldn't throw an exception: should just return false
*/ */
@Test
public void testIsReadablePropertyNoSuchProperty() { public void testIsReadablePropertyNoSuchProperty() {
NoRead nr = new NoRead(); NoRead nr = new NoRead();
BeanWrapper bw = new BeanWrapperImpl(nr); BeanWrapper bw = new BeanWrapperImpl(nr);
assertFalse(bw.isReadableProperty("xxxxx")); assertFalse(bw.isReadableProperty("xxxxx"));
} }
@Test
public void testIsReadablePropertyNull() { public void testIsReadablePropertyNull() {
NoRead nr = new NoRead(); NoRead nr = new NoRead();
BeanWrapper bw = new BeanWrapperImpl(nr); BeanWrapper bw = new BeanWrapperImpl(nr);
@ -81,6 +89,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testIsWritablePropertyNull() { public void testIsWritablePropertyNull() {
NoRead nr = new NoRead(); NoRead nr = new NoRead();
BeanWrapper bw = new BeanWrapperImpl(nr); BeanWrapper bw = new BeanWrapperImpl(nr);
@ -93,6 +102,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testReadableAndWritableForIndexedProperties() { public void testReadableAndWritableForIndexedProperties() {
BeanWrapper bw = new BeanWrapperImpl(IndexedTestBean.class); BeanWrapper bw = new BeanWrapperImpl(IndexedTestBean.class);
@ -137,6 +147,7 @@ public class BeanWrapperTests extends TestCase {
assertFalse(bw.isWritableProperty("array[key1]")); assertFalse(bw.isWritableProperty("array[key1]"));
} }
@Test
public void testTypeDeterminationForIndexedProperty() { public void testTypeDeterminationForIndexedProperty() {
BeanWrapper bw = new BeanWrapperImpl(IndexedTestBean.class); BeanWrapper bw = new BeanWrapperImpl(IndexedTestBean.class);
assertEquals(null, bw.getPropertyType("map[key0]")); assertEquals(null, bw.getPropertyType("map[key0]"));
@ -150,6 +161,7 @@ public class BeanWrapperTests extends TestCase {
assertEquals(String.class, bw.getPropertyType("map[key0]")); assertEquals(String.class, bw.getPropertyType("map[key0]"));
} }
@Test
public void testGetterThrowsException() { public void testGetterThrowsException() {
GetterBean gb = new GetterBean(); GetterBean gb = new GetterBean();
BeanWrapper bw = new BeanWrapperImpl(gb); BeanWrapper bw = new BeanWrapperImpl(gb);
@ -157,6 +169,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("Set name to tom", gb.getName().equals("tom")); assertTrue("Set name to tom", gb.getName().equals("tom"));
} }
@Test
public void testEmptyPropertyValuesSet() { public void testEmptyPropertyValuesSet() {
TestBean t = new TestBean(); TestBean t = new TestBean();
int age = 50; int age = 50;
@ -177,6 +190,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testAllValid() { public void testAllValid() {
TestBean t = new TestBean(); TestBean t = new TestBean();
String newName = "tony"; String newName = "tony";
@ -199,6 +213,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testBeanWrapperUpdates() { public void testBeanWrapperUpdates() {
TestBean t = new TestBean(); TestBean t = new TestBean();
int newAge = 33; int newAge = 33;
@ -215,6 +230,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testValidNullUpdate() { public void testValidNullUpdate() {
TestBean t = new TestBean(); TestBean t = new TestBean();
t.setName("Frank"); // we need to change it back t.setName("Frank"); // we need to change it back
@ -229,6 +245,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("spouse is now null", t.getSpouse() == null); assertTrue("spouse is now null", t.getSpouse() == null);
} }
@Test
public void testIgnoringIndexedProperty() { public void testIgnoringIndexedProperty() {
MutablePropertyValues values = new MutablePropertyValues(); MutablePropertyValues values = new MutablePropertyValues();
values.addPropertyValue("toBeIgnored[0]", new Integer(42)); values.addPropertyValue("toBeIgnored[0]", new Integer(42));
@ -236,6 +253,7 @@ public class BeanWrapperTests extends TestCase {
bw.setPropertyValues(values, true); bw.setPropertyValues(values, true);
} }
@Test
public void testConvertPrimitiveToString() { public void testConvertPrimitiveToString() {
MutablePropertyValues values = new MutablePropertyValues(); MutablePropertyValues values = new MutablePropertyValues();
values.addPropertyValue("name", new Integer(42)); values.addPropertyValue("name", new Integer(42));
@ -245,6 +263,7 @@ public class BeanWrapperTests extends TestCase {
assertEquals("42", tb.getName()); assertEquals("42", tb.getName());
} }
@Test
public void testConvertClassToString() { public void testConvertClassToString() {
MutablePropertyValues values = new MutablePropertyValues(); MutablePropertyValues values = new MutablePropertyValues();
values.addPropertyValue("name", Integer.class); values.addPropertyValue("name", Integer.class);
@ -259,6 +278,7 @@ public class BeanWrapperTests extends TestCase {
assertEquals(Integer.class.toString(), tb.getName()); assertEquals(Integer.class.toString(), tb.getName());
} }
@Test
public void testBooleanObject() { public void testBooleanObject() {
BooleanTestBean tb = new BooleanTestBean(); BooleanTestBean tb = new BooleanTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
@ -273,6 +293,7 @@ public class BeanWrapperTests extends TestCase {
} }
@Test
public void testNumberObjects() { public void testNumberObjects() {
NumberTestBean tb = new NumberTestBean(); NumberTestBean tb = new NumberTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
@ -306,6 +327,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(tb.getBigDecimal())); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(tb.getBigDecimal()));
} }
@Test
public void testNumberCoercion() { public void testNumberCoercion() {
NumberTestBean tb = new NumberTestBean(); NumberTestBean tb = new NumberTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
@ -339,18 +361,19 @@ public class BeanWrapperTests extends TestCase {
assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(tb.getBigDecimal())); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(tb.getBigDecimal()));
} }
@Test
public void testEnumByFieldName() { public void testEnumByFieldName() {
EnumTester et = new EnumTester(); EnumTester et = new EnumTester();
BeanWrapper bw = new BeanWrapperImpl(et); BeanWrapper bw = new BeanWrapperImpl(et);
bw.setPropertyValue("flushMode", "MANUAL"); bw.setPropertyValue("autowire", "BY_NAME");
assertEquals(FlushMode.MANUAL, et.getFlushMode()); assertEquals(Autowire.BY_NAME, et.getAutowire());
bw.setPropertyValue("flushMode", " AUTO "); bw.setPropertyValue("autowire", " BY_TYPE ");
assertEquals(FlushMode.AUTO, et.getFlushMode()); assertEquals(Autowire.BY_TYPE, et.getAutowire());
try { try {
bw.setPropertyValue("flushMode", "EVER"); bw.setPropertyValue("autowire", "NHERITED");
fail("Should have thrown TypeMismatchException"); fail("Should have thrown TypeMismatchException");
} }
catch (TypeMismatchException ex) { catch (TypeMismatchException ex) {
@ -358,6 +381,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testPropertiesProperty() throws Exception { public void testPropertiesProperty() throws Exception {
PropsTester pt = new PropsTester(); PropsTester pt = new PropsTester();
BeanWrapper bw = new BeanWrapperImpl(pt); BeanWrapper bw = new BeanWrapperImpl(pt);
@ -375,6 +399,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("Freedom==slavery", freedomVal.equals("slavery")); assertTrue("Freedom==slavery", freedomVal.equals("slavery"));
} }
@Test
public void testStringArrayProperty() throws Exception { public void testStringArrayProperty() throws Exception {
PropsTester pt = new PropsTester(); PropsTester pt = new PropsTester();
BeanWrapper bw = new BeanWrapperImpl(pt); BeanWrapper bw = new BeanWrapperImpl(pt);
@ -384,7 +409,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("correct values", pt.stringArray[0].equals("foo") && pt.stringArray[1].equals("fi") && assertTrue("correct values", pt.stringArray[0].equals("foo") && pt.stringArray[1].equals("fi") &&
pt.stringArray[2].equals("fi") && pt.stringArray[3].equals("fum")); pt.stringArray[2].equals("fi") && pt.stringArray[3].equals("fum"));
List list = new ArrayList(); List<String> list = new ArrayList<String>();
list.add("foo"); list.add("foo");
list.add("fi"); list.add("fi");
list.add("fi"); list.add("fi");
@ -394,13 +419,13 @@ public class BeanWrapperTests extends TestCase {
assertTrue("correct values", pt.stringArray[0].equals("foo") && pt.stringArray[1].equals("fi") && assertTrue("correct values", pt.stringArray[0].equals("foo") && pt.stringArray[1].equals("fi") &&
pt.stringArray[2].equals("fi") && pt.stringArray[3].equals("fum")); pt.stringArray[2].equals("fi") && pt.stringArray[3].equals("fum"));
Set set = new HashSet(); Set<String> set = new HashSet<String>();
set.add("foo"); set.add("foo");
set.add("fi"); set.add("fi");
set.add("fum"); set.add("fum");
bw.setPropertyValue("stringArray", set); bw.setPropertyValue("stringArray", set);
assertTrue("stringArray length = 3", pt.stringArray.length == 3); assertTrue("stringArray length = 3", pt.stringArray.length == 3);
List result = Arrays.asList(pt.stringArray); List<String> result = Arrays.asList(pt.stringArray);
assertTrue("correct values", result.contains("foo") && result.contains("fi") && result.contains("fum")); assertTrue("correct values", result.contains("foo") && result.contains("fi") && result.contains("fum"));
bw.setPropertyValue("stringArray", "one"); bw.setPropertyValue("stringArray", "one");
@ -411,6 +436,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("stringArray is null", pt.stringArray == null); assertTrue("stringArray is null", pt.stringArray == null);
} }
@Test
public void testStringArrayPropertyWithCustomStringEditor() throws Exception { public void testStringArrayPropertyWithCustomStringEditor() throws Exception {
PropsTester pt = new PropsTester(); PropsTester pt = new PropsTester();
BeanWrapper bw = new BeanWrapperImpl(pt); BeanWrapper bw = new BeanWrapperImpl(pt);
@ -425,7 +451,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("correct values", pt.stringArray[0].equals("foo") && pt.stringArray[1].equals("fi") && assertTrue("correct values", pt.stringArray[0].equals("foo") && pt.stringArray[1].equals("fi") &&
pt.stringArray[2].equals("fi") && pt.stringArray[3].equals("fum")); pt.stringArray[2].equals("fi") && pt.stringArray[3].equals("fum"));
List list = new ArrayList(); List<String> list = new ArrayList<String>();
list.add("4foo"); list.add("4foo");
list.add("7fi"); list.add("7fi");
list.add("6fi"); list.add("6fi");
@ -435,13 +461,13 @@ public class BeanWrapperTests extends TestCase {
assertTrue("correct values", pt.stringArray[0].equals("foo") && pt.stringArray[1].equals("fi") && assertTrue("correct values", pt.stringArray[0].equals("foo") && pt.stringArray[1].equals("fi") &&
pt.stringArray[2].equals("fi") && pt.stringArray[3].equals("fum")); pt.stringArray[2].equals("fi") && pt.stringArray[3].equals("fum"));
Set set = new HashSet(); Set<String> set = new HashSet<String>();
set.add("4foo"); set.add("4foo");
set.add("7fi"); set.add("7fi");
set.add("6fum"); set.add("6fum");
bw.setPropertyValue("stringArray", set); bw.setPropertyValue("stringArray", set);
assertTrue("stringArray length = 3", pt.stringArray.length == 3); assertTrue("stringArray length = 3", pt.stringArray.length == 3);
List result = Arrays.asList(pt.stringArray); List<String> result = Arrays.asList(pt.stringArray);
assertTrue("correct values", result.contains("foo") && result.contains("fi") && result.contains("fum")); assertTrue("correct values", result.contains("foo") && result.contains("fi") && result.contains("fum"));
bw.setPropertyValue("stringArray", "8one"); bw.setPropertyValue("stringArray", "8one");
@ -449,6 +475,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("correct values", pt.stringArray[0].equals("one")); assertTrue("correct values", pt.stringArray[0].equals("one"));
} }
@Test
public void testStringArrayPropertyWithStringSplitting() throws Exception { public void testStringArrayPropertyWithStringSplitting() throws Exception {
PropsTester pt = new PropsTester(); PropsTester pt = new PropsTester();
BeanWrapperImpl bw = new BeanWrapperImpl(pt); BeanWrapperImpl bw = new BeanWrapperImpl(pt);
@ -458,6 +485,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("correct values", pt.stringArray[0].equals("a1") && pt.stringArray[1].equals("b2")); assertTrue("correct values", pt.stringArray[0].equals("a1") && pt.stringArray[1].equals("b2"));
} }
@Test
public void testStringArrayPropertyWithCustomStringDelimiter() throws Exception { public void testStringArrayPropertyWithCustomStringDelimiter() throws Exception {
PropsTester pt = new PropsTester(); PropsTester pt = new PropsTester();
BeanWrapper bw = new BeanWrapperImpl(pt); BeanWrapper bw = new BeanWrapperImpl(pt);
@ -467,6 +495,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("correct values", pt.stringArray[0].equals("a1") && pt.stringArray[1].equals("b2")); assertTrue("correct values", pt.stringArray[0].equals("a1") && pt.stringArray[1].equals("b2"));
} }
@Test
public void testStringPropertyWithCustomEditor() throws Exception { public void testStringPropertyWithCustomEditor() throws Exception {
TestBean tb = new TestBean(); TestBean tb = new TestBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
@ -488,6 +517,7 @@ public class BeanWrapperTests extends TestCase {
assertEquals("", tb.getName()); assertEquals("", tb.getName());
} }
@Test
public void testIntArrayProperty() { public void testIntArrayProperty() {
PropsTester pt = new PropsTester(); PropsTester pt = new PropsTester();
BeanWrapper bw = new BeanWrapperImpl(pt); BeanWrapper bw = new BeanWrapperImpl(pt);
@ -502,7 +532,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("correct values", pt.intArray[0] == 4 && pt.intArray[1] == 5 && assertTrue("correct values", pt.intArray[0] == 4 && pt.intArray[1] == 5 &&
pt.intArray[2] == 2 && pt.intArray[3] == 3); pt.intArray[2] == 2 && pt.intArray[3] == 3);
List list = new ArrayList(); List<Object> list = new ArrayList<Object>();
list.add(new Integer(4)); list.add(new Integer(4));
list.add("5"); list.add("5");
list.add(new Integer(2)); list.add(new Integer(2));
@ -512,13 +542,13 @@ public class BeanWrapperTests extends TestCase {
assertTrue("correct values", pt.intArray[0] == 4 && pt.intArray[1] == 5 && assertTrue("correct values", pt.intArray[0] == 4 && pt.intArray[1] == 5 &&
pt.intArray[2] == 2 && pt.intArray[3] == 3); pt.intArray[2] == 2 && pt.intArray[3] == 3);
Set set = new HashSet(); Set<Object> set = new HashSet<Object>();
set.add("4"); set.add("4");
set.add(new Integer(5)); set.add(new Integer(5));
set.add("3"); set.add("3");
bw.setPropertyValue("intArray", set); bw.setPropertyValue("intArray", set);
assertTrue("intArray length = 3", pt.intArray.length == 3); assertTrue("intArray length = 3", pt.intArray.length == 3);
List result = new ArrayList(); List<Integer> result = new ArrayList<Integer>();
result.add(new Integer(pt.intArray[0])); result.add(new Integer(pt.intArray[0]));
result.add(new Integer(pt.intArray[1])); result.add(new Integer(pt.intArray[1]));
result.add(new Integer(pt.intArray[2])); result.add(new Integer(pt.intArray[2]));
@ -542,6 +572,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("correct values", pt.intArray[0] == 1); assertTrue("correct values", pt.intArray[0] == 1);
} }
@Test
public void testIntArrayPropertyWithCustomEditor() { public void testIntArrayPropertyWithCustomEditor() {
PropsTester pt = new PropsTester(); PropsTester pt = new PropsTester();
BeanWrapper bw = new BeanWrapperImpl(pt); BeanWrapper bw = new BeanWrapperImpl(pt);
@ -574,6 +605,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("correct values", pt.intArray[0] == 1); assertTrue("correct values", pt.intArray[0] == 1);
} }
@Test
public void testIntArrayPropertyWithStringSplitting() throws Exception { public void testIntArrayPropertyWithStringSplitting() throws Exception {
PropsTester pt = new PropsTester(); PropsTester pt = new PropsTester();
BeanWrapperImpl bw = new BeanWrapperImpl(pt); BeanWrapperImpl bw = new BeanWrapperImpl(pt);
@ -583,6 +615,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("correct values", pt.intArray[0] == 4 && pt.intArray[1] == 5); assertTrue("correct values", pt.intArray[0] == 4 && pt.intArray[1] == 5);
} }
@Test
public void testIndividualAllValid() { public void testIndividualAllValid() {
TestBean t = new TestBean(); TestBean t = new TestBean();
String newName = "tony"; String newName = "tony";
@ -602,6 +635,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void test2Invalid() { public void test2Invalid() {
TestBean t = new TestBean(); TestBean t = new TestBean();
String newName = "tony"; String newName = "tony";
@ -625,6 +659,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testPossibleMatches() { public void testPossibleMatches() {
TestBean tb = new TestBean(); TestBean tb = new TestBean();
try { try {
@ -639,6 +674,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testTypeMismatch() { public void testTypeMismatch() {
TestBean t = new TestBean(); TestBean t = new TestBean();
try { try {
@ -651,6 +687,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testEmptyValueForPrimitiveProperty() { public void testEmptyValueForPrimitiveProperty() {
TestBean t = new TestBean(); TestBean t = new TestBean();
try { try {
@ -666,6 +703,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testSetPropertyValuesIgnoresInvalidNestedOnRequest() { public void testSetPropertyValuesIgnoresInvalidNestedOnRequest() {
ITestBean rod = new TestBean(); ITestBean rod = new TestBean();
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
@ -685,6 +723,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testGetNestedProperty() { public void testGetNestedProperty() {
ITestBean rod = new TestBean("rod", 31); ITestBean rod = new TestBean("rod", 31);
ITestBean kerry = new TestBean("kerry", 35); ITestBean kerry = new TestBean("kerry", 35);
@ -699,6 +738,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("spousesSpouse = initial point", rod == spousesSpouse); assertTrue("spousesSpouse = initial point", rod == spousesSpouse);
} }
@Test
public void testGetNestedPropertyNullValue() throws Exception { public void testGetNestedPropertyNullValue() throws Exception {
ITestBean rod = new TestBean("rod", 31); ITestBean rod = new TestBean("rod", 31);
ITestBean kerry = new TestBean("kerry", 35); ITestBean kerry = new TestBean("kerry", 35);
@ -716,6 +756,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testSetNestedProperty() throws Exception { public void testSetNestedProperty() throws Exception {
ITestBean rod = new TestBean("rod", 31); ITestBean rod = new TestBean("rod", 31);
ITestBean kerry = new TestBean("kerry", 0); ITestBean kerry = new TestBean("kerry", 0);
@ -735,6 +776,7 @@ public class BeanWrapperTests extends TestCase {
assertEquals(rod, bw.getPropertyValue("spouse.spouse")); assertEquals(rod, bw.getPropertyValue("spouse.spouse"));
} }
@Test
public void testSetNestedPropertyNullValue() throws Exception { public void testSetNestedPropertyNullValue() throws Exception {
ITestBean rod = new TestBean("rod", 31); ITestBean rod = new TestBean("rod", 31);
BeanWrapper bw = new BeanWrapperImpl(rod); BeanWrapper bw = new BeanWrapperImpl(rod);
@ -749,6 +791,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testSetNestedPropertyPolymorphic() throws Exception { public void testSetNestedPropertyPolymorphic() throws Exception {
ITestBean rod = new TestBean("rod", 31); ITestBean rod = new TestBean("rod", 31);
ITestBean kerry = new Employee(); ITestBean kerry = new Employee();
@ -770,6 +813,7 @@ public class BeanWrapperTests extends TestCase {
"Lewisham".equals(kbw.getPropertyValue("spouse.spouse.spouse.spouse.company"))); "Lewisham".equals(kbw.getPropertyValue("spouse.spouse.spouse.spouse.company")));
} }
@Test
public void testNullObject() { public void testNullObject() {
try { try {
new BeanWrapperImpl((Object) null); new BeanWrapperImpl((Object) null);
@ -780,6 +824,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testNestedProperties() { public void testNestedProperties() {
String doctorCompany = ""; String doctorCompany = "";
String lawyerCompany = "Dr. Sueem"; String lawyerCompany = "Dr. Sueem";
@ -791,6 +836,7 @@ public class BeanWrapperTests extends TestCase {
assertEquals(lawyerCompany, tb.getLawyer().getCompany()); assertEquals(lawyerCompany, tb.getLawyer().getCompany());
} }
@Test
public void testIndexedProperties() { public void testIndexedProperties() {
IndexedTestBean bean = new IndexedTestBean(); IndexedTestBean bean = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(bean); BeanWrapper bw = new BeanWrapperImpl(bean);
@ -853,6 +899,7 @@ public class BeanWrapperTests extends TestCase {
assertEquals("nameB", bw.getPropertyValue("map[key4][1].name")); assertEquals("nameB", bw.getPropertyValue("map[key4][1].name"));
} }
@Test
public void testIndexedPropertiesWithDirectAccess() { public void testIndexedPropertiesWithDirectAccess() {
IndexedTestBean bean = new IndexedTestBean(); IndexedTestBean bean = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(bean); BeanWrapper bw = new BeanWrapperImpl(bean);
@ -911,6 +958,7 @@ public class BeanWrapperTests extends TestCase {
assertEquals(tb5, bw.getPropertyValue("map['key9']")); assertEquals(tb5, bw.getPropertyValue("map['key9']"));
} }
@Test
public void testMapAccessWithTypeConversion() { public void testMapAccessWithTypeConversion() {
IndexedTestBean bean = new IndexedTestBean(); IndexedTestBean bean = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(bean); BeanWrapper bw = new BeanWrapperImpl(bean);
@ -943,6 +991,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testMapAccessWithUnmodifiableMap() { public void testMapAccessWithUnmodifiableMap() {
IndexedTestBean bean = new IndexedTestBean(); IndexedTestBean bean = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(bean); BeanWrapper bw = new BeanWrapperImpl(bean);
@ -955,7 +1004,7 @@ public class BeanWrapperTests extends TestCase {
} }
}); });
Map inputMap = new HashMap(); Map<Integer, String> inputMap = new HashMap<Integer, String>();
inputMap.put(new Integer(1), "rod"); inputMap.put(new Integer(1), "rod");
inputMap.put(new Integer(2), "rob"); inputMap.put(new Integer(2), "rob");
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
@ -965,6 +1014,7 @@ public class BeanWrapperTests extends TestCase {
assertEquals("rob", ((TestBean) bean.getMap().get(new Integer(2))).getName()); assertEquals("rob", ((TestBean) bean.getMap().get(new Integer(2))).getName());
} }
@Test
public void testMapAccessWithCustomUnmodifiableMap() { public void testMapAccessWithCustomUnmodifiableMap() {
IndexedTestBean bean = new IndexedTestBean(); IndexedTestBean bean = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(bean); BeanWrapper bw = new BeanWrapperImpl(bean);
@ -977,7 +1027,7 @@ public class BeanWrapperTests extends TestCase {
} }
}); });
Map inputMap = new HashMap(); Map<Object, Object> inputMap = new HashMap<Object, Object>();
inputMap.put(new Integer(1), "rod"); inputMap.put(new Integer(1), "rod");
inputMap.put(new Integer(2), "rob"); inputMap.put(new Integer(2), "rob");
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
@ -987,6 +1037,8 @@ public class BeanWrapperTests extends TestCase {
assertEquals("rob", ((TestBean) bean.getMap().get(new Integer(2))).getName()); assertEquals("rob", ((TestBean) bean.getMap().get(new Integer(2))).getName());
} }
@SuppressWarnings("unchecked") // must work with raw map in this test
@Test
public void testRawMapAccessWithNoEditorRegistered() { public void testRawMapAccessWithNoEditorRegistered() {
IndexedTestBean bean = new IndexedTestBean(); IndexedTestBean bean = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(bean); BeanWrapper bw = new BeanWrapperImpl(bean);
@ -1001,6 +1053,7 @@ public class BeanWrapperTests extends TestCase {
assertFalse(readOnlyMap.isAccessed()); assertFalse(readOnlyMap.isAccessed());
} }
@Test
public void testPrimitiveArray() { public void testPrimitiveArray() {
PrimitiveArrayBean tb = new PrimitiveArrayBean(); PrimitiveArrayBean tb = new PrimitiveArrayBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
@ -1010,6 +1063,7 @@ public class BeanWrapperTests extends TestCase {
assertEquals(2, tb.getArray()[1]); assertEquals(2, tb.getArray()[1]);
} }
@Test
public void testLargeMatchingPrimitiveArray() { public void testLargeMatchingPrimitiveArray() {
if (LogFactory.getLog(BeanWrapperTests.class).isTraceEnabled()) { if (LogFactory.getLog(BeanWrapperTests.class).isTraceEnabled()) {
// Skip this test: Trace logging blows the time limit. // Skip this test: Trace logging blows the time limit.
@ -1065,6 +1119,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1); assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1);
} }
@Test
public void testLargeMatchingPrimitiveArrayWithSpecificEditor() { public void testLargeMatchingPrimitiveArrayWithSpecificEditor() {
PrimitiveArrayBean tb = new PrimitiveArrayBean(); PrimitiveArrayBean tb = new PrimitiveArrayBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
@ -1082,6 +1137,7 @@ public class BeanWrapperTests extends TestCase {
assertEquals(1, tb.getArray()[1]); assertEquals(1, tb.getArray()[1]);
} }
@Test
public void testLargeMatchingPrimitiveArrayWithIndexSpecificEditor() { public void testLargeMatchingPrimitiveArrayWithIndexSpecificEditor() {
PrimitiveArrayBean tb = new PrimitiveArrayBean(); PrimitiveArrayBean tb = new PrimitiveArrayBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
@ -1099,6 +1155,7 @@ public class BeanWrapperTests extends TestCase {
assertEquals(1, tb.getArray()[1]); assertEquals(1, tb.getArray()[1]);
} }
@Test
public void testPropertiesInProtectedBaseBean() { public void testPropertiesInProtectedBaseBean() {
DerivedFromProtectedBaseBean bean = new DerivedFromProtectedBaseBean(); DerivedFromProtectedBaseBean bean = new DerivedFromProtectedBaseBean();
BeanWrapper bw = new BeanWrapperImpl(bean); BeanWrapper bw = new BeanWrapperImpl(bean);
@ -1107,6 +1164,7 @@ public class BeanWrapperTests extends TestCase {
assertEquals("someValue", bean.getSomeProperty()); assertEquals("someValue", bean.getSomeProperty());
} }
@Test
public void testErrorMessageOfNestedProperty() { public void testErrorMessageOfNestedProperty() {
ITestBean parent = new TestBean(); ITestBean parent = new TestBean();
ITestBean child = new DifferentTestBean(); ITestBean child = new DifferentTestBean();
@ -1121,19 +1179,20 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testMatchingCollections() { public void testMatchingCollections() {
IndexedTestBean tb = new IndexedTestBean(); IndexedTestBean tb = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
Collection coll = new HashSet(); Collection<String> coll = new HashSet<String>();
coll.add("coll1"); coll.add("coll1");
bw.setPropertyValue("collection", coll); bw.setPropertyValue("collection", coll);
Set set = new HashSet(); Set<String> set = new HashSet<String>();
set.add("set1"); set.add("set1");
bw.setPropertyValue("set", set); bw.setPropertyValue("set", set);
SortedSet sortedSet = new TreeSet(); SortedSet<String> sortedSet = new TreeSet<String>();
sortedSet.add("sortedSet1"); sortedSet.add("sortedSet1");
bw.setPropertyValue("sortedSet", sortedSet); bw.setPropertyValue("sortedSet", sortedSet);
List list = new LinkedList(); List<String> list = new LinkedList<String>();
list.add("list1"); list.add("list1");
bw.setPropertyValue("list", list); bw.setPropertyValue("list", list);
assertSame(coll, tb.getCollection()); assertSame(coll, tb.getCollection());
@ -1142,19 +1201,21 @@ public class BeanWrapperTests extends TestCase {
assertSame(list, tb.getList()); assertSame(list, tb.getList());
} }
@SuppressWarnings("unchecked") // list cannot be properly parameterized as it breaks other tests
@Test
public void testNonMatchingCollections() { public void testNonMatchingCollections() {
IndexedTestBean tb = new IndexedTestBean(); IndexedTestBean tb = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
Collection coll = new ArrayList(); Collection<String> coll = new ArrayList<String>();
coll.add("coll1"); coll.add("coll1");
bw.setPropertyValue("collection", coll); bw.setPropertyValue("collection", coll);
List set = new LinkedList(); List<String> set = new LinkedList<String>();
set.add("set1"); set.add("set1");
bw.setPropertyValue("set", set); bw.setPropertyValue("set", set);
List sortedSet = new ArrayList(); List<String> sortedSet = new ArrayList<String>();
sortedSet.add("sortedSet1"); sortedSet.add("sortedSet1");
bw.setPropertyValue("sortedSet", sortedSet); bw.setPropertyValue("sortedSet", sortedSet);
Set list = new HashSet(); Set<String> list = new HashSet<String>();
list.add("list1"); list.add("list1");
bw.setPropertyValue("list", list); bw.setPropertyValue("list", list);
assertEquals(1, tb.getCollection().size()); assertEquals(1, tb.getCollection().size());
@ -1167,19 +1228,21 @@ public class BeanWrapperTests extends TestCase {
assertTrue(tb.getList().containsAll(list)); assertTrue(tb.getList().containsAll(list));
} }
@SuppressWarnings("unchecked") // list cannot be properly parameterized as it breaks other tests
@Test
public void testCollectionsWithArrayValues() { public void testCollectionsWithArrayValues() {
IndexedTestBean tb = new IndexedTestBean(); IndexedTestBean tb = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
Collection coll = new HashSet(); Collection<String> coll = new HashSet<String>();
coll.add("coll1"); coll.add("coll1");
bw.setPropertyValue("collection", coll.toArray()); bw.setPropertyValue("collection", coll.toArray());
List set = new LinkedList(); List<String> set = new LinkedList<String>();
set.add("set1"); set.add("set1");
bw.setPropertyValue("set", set.toArray()); bw.setPropertyValue("set", set.toArray());
List sortedSet = new ArrayList(); List<String> sortedSet = new ArrayList<String>();
sortedSet.add("sortedSet1"); sortedSet.add("sortedSet1");
bw.setPropertyValue("sortedSet", sortedSet.toArray()); bw.setPropertyValue("sortedSet", sortedSet.toArray());
Set list = new HashSet(); Set<String> list = new HashSet<String>();
list.add("list1"); list.add("list1");
bw.setPropertyValue("list", list.toArray()); bw.setPropertyValue("list", list.toArray());
assertEquals(1, tb.getCollection().size()); assertEquals(1, tb.getCollection().size());
@ -1192,19 +1255,21 @@ public class BeanWrapperTests extends TestCase {
assertTrue(tb.getList().containsAll(list)); assertTrue(tb.getList().containsAll(list));
} }
@SuppressWarnings("unchecked") // list cannot be properly parameterized as it breaks other tests
@Test
public void testCollectionsWithIntArrayValues() { public void testCollectionsWithIntArrayValues() {
IndexedTestBean tb = new IndexedTestBean(); IndexedTestBean tb = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
Collection coll = new HashSet(); Collection<Integer> coll = new HashSet<Integer>();
coll.add(new Integer(0)); coll.add(new Integer(0));
bw.setPropertyValue("collection", new int[] {0}); bw.setPropertyValue("collection", new int[] {0});
List set = new LinkedList(); List<Integer> set = new LinkedList<Integer>();
set.add(new Integer(1)); set.add(new Integer(1));
bw.setPropertyValue("set", new int[] {1}); bw.setPropertyValue("set", new int[] {1});
List sortedSet = new ArrayList(); List<Integer> sortedSet = new ArrayList<Integer>();
sortedSet.add(new Integer(2)); sortedSet.add(new Integer(2));
bw.setPropertyValue("sortedSet", new int[] {2}); bw.setPropertyValue("sortedSet", new int[] {2});
Set list = new HashSet(); Set<Integer> list = new HashSet<Integer>();
list.add(new Integer(3)); list.add(new Integer(3));
bw.setPropertyValue("list", new int[] {3}); bw.setPropertyValue("list", new int[] {3});
assertEquals(1, tb.getCollection().size()); assertEquals(1, tb.getCollection().size());
@ -1217,19 +1282,21 @@ public class BeanWrapperTests extends TestCase {
assertTrue(tb.getList().containsAll(list)); assertTrue(tb.getList().containsAll(list));
} }
@SuppressWarnings("unchecked") // list cannot be properly parameterized as it breaks other tests
@Test
public void testCollectionsWithIntegerValues() { public void testCollectionsWithIntegerValues() {
IndexedTestBean tb = new IndexedTestBean(); IndexedTestBean tb = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
Collection coll = new HashSet(); Collection<Integer> coll = new HashSet<Integer>();
coll.add(new Integer(0)); coll.add(new Integer(0));
bw.setPropertyValue("collection", new Integer(0)); bw.setPropertyValue("collection", new Integer(0));
List set = new LinkedList(); List<Integer> set = new LinkedList<Integer>();
set.add(new Integer(1)); set.add(new Integer(1));
bw.setPropertyValue("set", new Integer(1)); bw.setPropertyValue("set", new Integer(1));
List sortedSet = new ArrayList(); List<Integer> sortedSet = new ArrayList<Integer>();
sortedSet.add(new Integer(2)); sortedSet.add(new Integer(2));
bw.setPropertyValue("sortedSet", new Integer(2)); bw.setPropertyValue("sortedSet", new Integer(2));
Set list = new HashSet(); Set<Integer> list = new HashSet<Integer>();
list.add(new Integer(3)); list.add(new Integer(3));
bw.setPropertyValue("list", new Integer(3)); bw.setPropertyValue("list", new Integer(3));
assertEquals(1, tb.getCollection().size()); assertEquals(1, tb.getCollection().size());
@ -1242,16 +1309,18 @@ public class BeanWrapperTests extends TestCase {
assertTrue(tb.getList().containsAll(list)); assertTrue(tb.getList().containsAll(list));
} }
@SuppressWarnings("unchecked") // list cannot be properly parameterized as it breaks other tests
@Test
public void testCollectionsWithStringValues() { public void testCollectionsWithStringValues() {
IndexedTestBean tb = new IndexedTestBean(); IndexedTestBean tb = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
List set = new LinkedList(); List<String> set = new LinkedList<String>();
set.add("set1"); set.add("set1");
bw.setPropertyValue("set", "set1"); bw.setPropertyValue("set", "set1");
List sortedSet = new ArrayList(); List<String> sortedSet = new ArrayList<String>();
sortedSet.add("sortedSet1"); sortedSet.add("sortedSet1");
bw.setPropertyValue("sortedSet", "sortedSet1"); bw.setPropertyValue("sortedSet", "sortedSet1");
Set list = new HashSet(); Set<String> list = new HashSet<String>();
list.add("list1"); list.add("list1");
bw.setPropertyValue("list", "list1"); bw.setPropertyValue("list", "list1");
assertEquals(1, tb.getSet().size()); assertEquals(1, tb.getSet().size());
@ -1262,6 +1331,7 @@ public class BeanWrapperTests extends TestCase {
assertTrue(tb.getList().containsAll(list)); assertTrue(tb.getList().containsAll(list));
} }
@Test
public void testCollectionsWithStringValuesAndCustomEditor() { public void testCollectionsWithStringValuesAndCustomEditor() {
IndexedTestBean tb = new IndexedTestBean(); IndexedTestBean tb = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
@ -1282,26 +1352,28 @@ public class BeanWrapperTests extends TestCase {
assertTrue(tb.getList().contains("list1")); assertTrue(tb.getList().contains("list1"));
} }
@Test
public void testMatchingMaps() { public void testMatchingMaps() {
IndexedTestBean tb = new IndexedTestBean(); IndexedTestBean tb = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
Map map = new HashMap(); Map<String, String> map = new HashMap<String, String>();
map.put("key", "value"); map.put("key", "value");
bw.setPropertyValue("map", map); bw.setPropertyValue("map", map);
SortedMap sortedMap = new TreeMap(); SortedMap<?, ?> sortedMap = new TreeMap<Object, Object>();
map.put("sortedKey", "sortedValue"); map.put("sortedKey", "sortedValue");
bw.setPropertyValue("sortedMap", sortedMap); bw.setPropertyValue("sortedMap", sortedMap);
assertSame(map, tb.getMap()); assertSame(map, tb.getMap());
assertSame(sortedMap, tb.getSortedMap()); assertSame(sortedMap, tb.getSortedMap());
} }
@Test
public void testNonMatchingMaps() { public void testNonMatchingMaps() {
IndexedTestBean tb = new IndexedTestBean(); IndexedTestBean tb = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
Map map = new TreeMap(); Map<String, String> map = new TreeMap<String, String>();
map.put("key", "value"); map.put("key", "value");
bw.setPropertyValue("map", map); bw.setPropertyValue("map", map);
Map sortedMap = new HashMap(); Map<String, String> sortedMap = new TreeMap<String, String>();
sortedMap.put("sortedKey", "sortedValue"); sortedMap.put("sortedKey", "sortedValue");
bw.setPropertyValue("sortedMap", sortedMap); bw.setPropertyValue("sortedMap", sortedMap);
assertEquals(1, tb.getMap().size()); assertEquals(1, tb.getMap().size());
@ -1310,6 +1382,7 @@ public class BeanWrapperTests extends TestCase {
assertEquals("sortedValue", tb.getSortedMap().get("sortedKey")); assertEquals("sortedValue", tb.getSortedMap().get("sortedKey"));
} }
@Test
public void testSetNumberProperties() { public void testSetNumberProperties() {
NumberPropertyBean bean = new NumberPropertyBean(); NumberPropertyBean bean = new NumberPropertyBean();
BeanWrapper bw = new BeanWrapperImpl(bean); BeanWrapper bw = new BeanWrapperImpl(bean);
@ -1359,6 +1432,7 @@ public class BeanWrapperTests extends TestCase {
} }
@Test
public void testAlternativesForTypo() { public void testAlternativesForTypo() {
IntelliBean ib = new IntelliBean(); IntelliBean ib = new IntelliBean();
BeanWrapper bw = new BeanWrapperImpl(ib); BeanWrapper bw = new BeanWrapperImpl(ib);
@ -1371,6 +1445,7 @@ public class BeanWrapperTests extends TestCase {
} }
} }
@Test
public void testAlternativesForTypos() { public void testAlternativesForTypos() {
IntelliBean ib = new IntelliBean(); IntelliBean ib = new IntelliBean();
BeanWrapper bw = new BeanWrapperImpl(ib); BeanWrapper bw = new BeanWrapperImpl(ib);
@ -1398,14 +1473,14 @@ public class BeanWrapperTests extends TestCase {
private static class EnumTester { private static class EnumTester {
private FlushMode flushMode; private Autowire autowire;
public void setFlushMode(FlushMode flushMode) { public void setAutowire(Autowire autowire) {
this.flushMode = flushMode; this.autowire = autowire;
} }
public FlushMode getFlushMode() { public Autowire getAutowire() {
return flushMode; return autowire;
} }
} }
@ -1608,8 +1683,29 @@ public class BeanWrapperTests extends TestCase {
public void setMyStringss(String string) {} public void setMyStringss(String string) {}
} }
private static class Employee extends TestBean {
public static class ReadOnlyMap extends HashMap { private String co;
/**
* Constructor for Employee.
*/
public Employee() {
super();
}
public String getCompany() {
return co;
}
public void setCompany(String co) {
this.co = co;
}
}
@SuppressWarnings("serial")
public static class ReadOnlyMap extends HashMap<Object, Object> {
private boolean frozen = false; private boolean frozen = false;
@ -1619,7 +1715,7 @@ public class BeanWrapperTests extends TestCase {
this.frozen = true; this.frozen = true;
} }
public ReadOnlyMap(Map map) { public ReadOnlyMap(Map<Object, Object> map) {
super(map); super(map);
this.frozen = true; this.frozen = true;
} }
@ -1633,12 +1729,12 @@ public class BeanWrapperTests extends TestCase {
} }
} }
public Set entrySet() { public Set<Entry<Object, Object>> entrySet() {
this.accessed = true; this.accessed = true;
return super.entrySet(); return super.entrySet();
} }
public Set keySet() { public Set<Object> keySet() {
this.accessed = true; this.accessed = true;
return super.keySet(); return super.keySet();
} }

View File

@ -16,15 +16,18 @@
package org.springframework.beans; package org.springframework.beans;
import junit.framework.TestCase; import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.core.OverridingClassLoader; import org.springframework.core.OverridingClassLoader;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams
*/ */
public class CachedIntrospectionResultsTests extends TestCase { public final class CachedIntrospectionResultsTests {
@Test
public void testAcceptClassLoader() throws Exception { public void testAcceptClassLoader() throws Exception {
BeanWrapper bw = new BeanWrapperImpl(TestBean.class); BeanWrapper bw = new BeanWrapperImpl(TestBean.class);
assertTrue(bw.isWritableProperty("name")); assertTrue(bw.isWritableProperty("name"));
@ -32,7 +35,7 @@ public class CachedIntrospectionResultsTests extends TestCase {
assertTrue(CachedIntrospectionResults.classCache.containsKey(TestBean.class)); assertTrue(CachedIntrospectionResults.classCache.containsKey(TestBean.class));
ClassLoader child = new OverridingClassLoader(getClass().getClassLoader()); ClassLoader child = new OverridingClassLoader(getClass().getClassLoader());
Class tbClass = child.loadClass("org.springframework.beans.TestBean"); Class<?> tbClass = child.loadClass("org.springframework.beans.TestBean");
assertFalse(CachedIntrospectionResults.classCache.containsKey(tbClass)); assertFalse(CachedIntrospectionResults.classCache.containsKey(tbClass));
CachedIntrospectionResults.acceptClassLoader(child); CachedIntrospectionResults.acceptClassLoader(child);
bw = new BeanWrapperImpl(tbClass); bw = new BeanWrapperImpl(tbClass);

View File

@ -16,6 +16,8 @@
package org.springframework.beans; package org.springframework.beans;
import static org.junit.Assert.*;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
@ -24,29 +26,32 @@ import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.junit.Test;
/** /**
* @author Guillaume Poirier * @author Guillaume Poirier
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams
* @since 08.03.2004 * @since 08.03.2004
*/ */
public class ConcurrentBeanWrapperTests extends TestCase { public final class ConcurrentBeanWrapperTests {
private final Log logger = LogFactory.getLog(getClass()); private final Log logger = LogFactory.getLog(getClass());
private Set set = Collections.synchronizedSet(new HashSet()); private Set<TestRun> set = Collections.synchronizedSet(new HashSet<TestRun>());
private Throwable ex = null; private Throwable ex = null;
@Test
public void testSingleThread() { public void testSingleThread() {
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
performSet(); performSet();
} }
} }
@Test
public void testConcurrent() { public void testConcurrent() {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
TestRun run = new TestRun(this); TestRun run = new TestRun(this);
@ -79,7 +84,7 @@ public class ConcurrentBeanWrapperTests extends TestCase {
assertTrue("The System properties must not be empty", p.size() != 0); assertTrue("The System properties must not be empty", p.size() != 0);
for (Iterator i = p.entrySet().iterator(); i.hasNext();) { for (Iterator<?> i = p.entrySet().iterator(); i.hasNext();) {
i.next(); i.next();
if (Math.random() > 0.9) { if (Math.random() > 0.9) {
i.remove(); i.remove();

View File

@ -1,39 +0,0 @@
/*
* Copyright 2002-2005 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.
* 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 org.springframework.beans;
public class Employee extends TestBean {
private String co;
/**
* Constructor for Employee.
*/
public Employee() {
super();
}
public String getCompany() {
return co;
}
public void setCompany(String co) {
this.co = co;
}
}

View File

@ -16,6 +16,8 @@
package org.springframework.beans; package org.springframework.beans;
import test.beans.GenericBean;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */

View File

@ -18,6 +18,8 @@ package org.springframework.beans;
import java.util.Set; import java.util.Set;
import test.beans.GenericBean;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */

View File

@ -34,13 +34,13 @@ public class IndexedTestBean {
private TestBean[] array; private TestBean[] array;
private Collection collection; private Collection<?> collection;
private List list; private List list;
private Set set; private Set<? super Object> set;
private SortedSet sortedSet; private SortedSet<? super Object> sortedSet;
private Map map; private Map map;
@ -69,13 +69,13 @@ public class IndexedTestBean {
TestBean tbX = new TestBean("nameX", 0); TestBean tbX = new TestBean("nameX", 0);
TestBean tbY = new TestBean("nameY", 0); TestBean tbY = new TestBean("nameY", 0);
this.array = new TestBean[] {tb0, tb1}; this.array = new TestBean[] {tb0, tb1};
this.list = new ArrayList(); this.list = new ArrayList<Object>();
this.list.add(tb2); this.list.add(tb2);
this.list.add(tb3); this.list.add(tb3);
this.set = new TreeSet(); this.set = new TreeSet<Object>();
this.set.add(tb6); this.set.add(tb6);
this.set.add(tb7); this.set.add(tb7);
this.map = new HashMap(); this.map = new HashMap<Object, Object>();
this.map.put("key1", tb4); this.map.put("key1", tb4);
this.map.put("key2", tb5); this.map.put("key2", tb5);
this.map.put("key.3", tb5); this.map.put("key.3", tb5);
@ -94,11 +94,11 @@ public class IndexedTestBean {
this.array = array; this.array = array;
} }
public Collection getCollection() { public Collection<?> getCollection() {
return collection; return collection;
} }
public void setCollection(Collection collection) { public void setCollection(Collection<?> collection) {
this.collection = collection; this.collection = collection;
} }
@ -110,19 +110,19 @@ public class IndexedTestBean {
this.list = list; this.list = list;
} }
public Set getSet() { public Set<?> getSet() {
return set; return set;
} }
public void setSet(Set set) { public void setSet(Set<? super Object> set) {
this.set = set; this.set = set;
} }
public SortedSet getSortedSet() { public SortedSet<? super Object> getSortedSet() {
return sortedSet; return sortedSet;
} }
public void setSortedSet(SortedSet sortedSet) { public void setSortedSet(SortedSet<? super Object> sortedSet) {
this.sortedSet = sortedSet; this.sortedSet = sortedSet;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,15 +16,19 @@
package org.springframework.beans; package org.springframework.beans;
import static org.junit.Assert.*;
import java.util.Arrays; import java.util.Arrays;
import junit.framework.TestCase; import org.junit.Test;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams
*/ */
public class PropertyAccessorUtilsTests extends TestCase { public final class PropertyAccessorUtilsTests {
@Test
public void testCanonicalPropertyName() { public void testCanonicalPropertyName() {
assertEquals("map", PropertyAccessorUtils.canonicalPropertyName("map")); assertEquals("map", PropertyAccessorUtils.canonicalPropertyName("map"));
assertEquals("map[key1]", PropertyAccessorUtils.canonicalPropertyName("map[key1]")); assertEquals("map[key1]", PropertyAccessorUtils.canonicalPropertyName("map[key1]"));
@ -37,6 +41,7 @@ public class PropertyAccessorUtilsTests extends TestCase {
assertEquals("map[key1].name", PropertyAccessorUtils.canonicalPropertyName("map[\"key1\"].name")); assertEquals("map[key1].name", PropertyAccessorUtils.canonicalPropertyName("map[\"key1\"].name"));
} }
@Test
public void testCanonicalPropertyNames() { public void testCanonicalPropertyNames() {
String[] original = String[] original =
new String[] {"map", "map[key1]", "map['key1']", "map[\"key1\"]", "map[key1][key2]", new String[] {"map", "map[key1]", "map['key1']", "map[\"key1\"]", "map[key1][key2]",

View File

@ -39,7 +39,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.DerivedTestBean;
import org.springframework.beans.ITestBean; import org.springframework.beans.ITestBean;
import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.NestedTestBean; import org.springframework.beans.NestedTestBean;
@ -73,6 +72,8 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource; import org.springframework.core.io.UrlResource;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
import test.beans.DerivedTestBean;
import common.beans.core.SideEffectBean; import common.beans.core.SideEffectBean;
/** /**

View File

@ -21,10 +21,11 @@ import java.util.Arrays;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.DerivedTestBean;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry; import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry;
import test.beans.DerivedTestBean;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 04.07.2006 * @since 04.07.2006

View File

@ -31,7 +31,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.GenericBean;
import org.springframework.beans.GenericIntegerBean; import org.springframework.beans.GenericIntegerBean;
import org.springframework.beans.GenericSetOfIntegerBean; import org.springframework.beans.GenericSetOfIntegerBean;
import org.springframework.beans.PropertyEditorRegistrar; import org.springframework.beans.PropertyEditorRegistrar;
@ -41,6 +40,8 @@ import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.UrlResource; import org.springframework.core.io.UrlResource;
import test.beans.GenericBean;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams

View File

@ -3,7 +3,7 @@
<beans> <beans>
<bean id="listOfArrays" class="org.springframework.beans.GenericBean"> <bean id="listOfArrays" class="test.beans.GenericBean">
<property name="listOfArrays"> <property name="listOfArrays">
<list> <list>
<list> <list>

View File

@ -42,7 +42,6 @@ import org.junit.Test;
import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl; import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.BooleanTestBean;
import org.springframework.beans.ITestBean; import org.springframework.beans.ITestBean;
import org.springframework.beans.IndexedTestBean; import org.springframework.beans.IndexedTestBean;
import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.MutablePropertyValues;
@ -50,6 +49,8 @@ import org.springframework.beans.NumberTestBean;
import org.springframework.beans.PropertyValue; import org.springframework.beans.PropertyValue;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import test.beans.BooleanTestBean;
/** /**
* Unit tests for the various PropertyEditors in Spring. * Unit tests for the various PropertyEditors in Spring.
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005 the original author or authors. * Copyright 2002-2008 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -14,10 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.beans; package test.beans;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams
* @since 10.06.2003 * @since 10.06.2003
*/ */
public class BooleanTestBean { public class BooleanTestBean {

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.beans; package test.beans;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller

View File

@ -14,10 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.beans; package test.beans;
import java.io.Serializable; import java.io.Serializable;
import org.springframework.beans.TestBean;
import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.beans; package test.beans;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;

View File

@ -22,6 +22,6 @@
</property> </property>
</bean> </bean>
<bean id="derivedSally" class="org.springframework.beans.DerivedTestBean" p:name="Sally Greenwood" p:spouseRef="r"/> <bean id="derivedSally" class="test.beans.DerivedTestBean" p:name="Sally Greenwood" p:spouseRef="r"/>
</beans> </beans>