From: Juergen H. <jho...@us...> - 2006-08-14 23:54:45
|
Update of /cvsroot/springframework/spring/test/org/springframework/beans In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv23973/test/org/springframework/beans Modified Files: BeanWrapperTests.java Log Message: always use a valid read-write type for a converted collection/map (never use original class) Index: BeanWrapperTests.java =================================================================== RCS file: /cvsroot/springframework/spring/test/org/springframework/beans/BeanWrapperTests.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** BeanWrapperTests.java 28 Jul 2006 15:15:03 -0000 1.26 --- BeanWrapperTests.java 14 Aug 2006 23:54:43 -0000 1.27 *************** *** 23,29 **** --- 23,32 ---- import java.util.Arrays; import java.util.Collection; + import java.util.Collections; + import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; + import java.util.Map; import java.util.Properties; import java.util.Set; *************** *** 753,757 **** public void testNullObject() { try { ! BeanWrapper bw = new BeanWrapperImpl((Object) null); fail("Must throw an exception when constructed with null object"); } --- 756,760 ---- public void testNullObject() { try { ! new BeanWrapperImpl((Object) null); fail("Must throw an exception when constructed with null object"); } *************** *** 924,927 **** --- 927,974 ---- } + public void testMapAccessWithUnmodifiableMap() { + IndexedTestBean bean = new IndexedTestBean(); + BeanWrapper bw = new BeanWrapperImpl(bean); + bw.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() { + public void setAsText(String text) throws IllegalArgumentException { + if (!StringUtils.hasLength(text)) { + throw new IllegalArgumentException(); + } + setValue(new TestBean(text)); + } + }); + + Map inputMap = new HashMap(); + inputMap.put(new Integer(1), "rod"); + inputMap.put(new Integer(2), "rob"); + MutablePropertyValues pvs = new MutablePropertyValues(); + pvs.addPropertyValue("map", Collections.unmodifiableMap(inputMap)); + bw.setPropertyValues(pvs); + assertEquals("rod", ((TestBean) bean.getMap().get(new Integer(1))).getName()); + assertEquals("rob", ((TestBean) bean.getMap().get(new Integer(2))).getName()); + } + + public void testMapAccessWithCustomUnmodifiableMap() { + IndexedTestBean bean = new IndexedTestBean(); + BeanWrapper bw = new BeanWrapperImpl(bean); + bw.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() { + public void setAsText(String text) throws IllegalArgumentException { + if (!StringUtils.hasLength(text)) { + throw new IllegalArgumentException(); + } + setValue(new TestBean(text)); + } + }); + + Map inputMap = new HashMap(); + inputMap.put(new Integer(1), "rod"); + inputMap.put(new Integer(2), "rob"); + MutablePropertyValues pvs = new MutablePropertyValues(); + pvs.addPropertyValue("map", new ReadOnlyMap(inputMap)); + bw.setPropertyValues(pvs); + assertEquals("rod", ((TestBean) bean.getMap().get(new Integer(1))).getName()); + assertEquals("rob", ((TestBean) bean.getMap().get(new Integer(2))).getName()); + } + public void testPrimitiveArray() { PrimitiveArrayBean tb = new PrimitiveArrayBean(); *************** *** 1416,1418 **** --- 1463,1480 ---- } + + public static class ReadOnlyMap extends HashMap { + + public ReadOnlyMap() { + } + + public ReadOnlyMap(Map map) { + super(map); + } + + public Object put(Object key, Object value) { + throw new UnsupportedOperationException(); + } + } + } |