|
36 | 36 | import java.util.Set; |
37 | 37 | import java.util.TreeSet; |
38 | 38 |
|
| 39 | +import org.junit.Rule; |
39 | 40 | import org.junit.Test; |
40 | 41 |
|
| 42 | +import org.junit.rules.ExpectedException; |
41 | 43 | import org.springframework.beans.InvalidPropertyException; |
42 | 44 | import org.springframework.beans.MutablePropertyValues; |
43 | 45 | import org.springframework.beans.NotWritablePropertyException; |
|
69 | 71 | * @author Rod Johnson |
70 | 72 | * @author Juergen Hoeller |
71 | 73 | * @author Rob Harrop |
| 74 | + * @author Kazuki Shimizu |
72 | 75 | */ |
73 | 76 | public class DataBinderTests { |
74 | 77 |
|
| 78 | + @Rule |
| 79 | + public ExpectedException expectedException = ExpectedException.none(); |
| 80 | + |
75 | 81 | @Test |
76 | 82 | public void testBindingNoErrors() throws Exception { |
77 | 83 | TestBean rod = new TestBean(); |
@@ -1982,6 +1988,30 @@ public void testFieldErrorAccessVariations() throws Exception { |
1982 | 1988 | assertEquals("age", binder.getBindingResult().getFieldError("age").getField()); |
1983 | 1989 | } |
1984 | 1990 |
|
| 1991 | + @Test // SPR-14888 |
| 1992 | + public void testSetAutoGrowCollectionLimit() { |
| 1993 | + BeanWithIntegerList tb = new BeanWithIntegerList(); |
| 1994 | + DataBinder binder = new DataBinder(tb); |
| 1995 | + binder.setAutoGrowCollectionLimit(257); |
| 1996 | + MutablePropertyValues pvs = new MutablePropertyValues(); |
| 1997 | + pvs.add("integerList[256]", "1"); |
| 1998 | + |
| 1999 | + binder.bind(pvs); |
| 2000 | + assertEquals(257, tb.getIntegerList().size()); |
| 2001 | + assertEquals(Integer.valueOf(1), tb.getIntegerList().get(256)); |
| 2002 | + assertEquals(Integer.valueOf(1), binder.getBindingResult().getFieldValue("integerList[256]")); |
| 2003 | + } |
| 2004 | + |
| 2005 | + @Test // SPR-14888 |
| 2006 | + public void testSetAutoGrowCollectionLimitAfterInitialization() { |
| 2007 | + |
| 2008 | + expectedException.expect(IllegalStateException.class); |
| 2009 | + expectedException.expectMessage("DataBinder is already initialized - call setAutoGrowCollectionLimit before other configuration methods"); |
| 2010 | + |
| 2011 | + DataBinder binder = new DataBinder(new BeanWithIntegerList()); |
| 2012 | + binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); |
| 2013 | + binder.setAutoGrowCollectionLimit(257); |
| 2014 | + } |
1985 | 2015 |
|
1986 | 2016 | @SuppressWarnings("unused") |
1987 | 2017 | private static class BeanWithIntegerList { |
|
0 commit comments