|
1 | 1 | /* |
2 | | - * Copyright 2002-2013 the original author or authors. |
| 2 | + * Copyright 2002-2014 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
16 | 16 |
|
17 | 17 | package org.springframework.beans; |
18 | 18 |
|
19 | | -import static org.junit.Assert.assertEquals; |
20 | | -import static org.junit.Assert.assertFalse; |
21 | | -import static org.junit.Assert.assertNotNull; |
22 | | -import static org.junit.Assert.assertSame; |
23 | | -import static org.junit.Assert.assertTrue; |
24 | | -import static org.junit.Assert.fail; |
25 | | - |
26 | 19 | import java.beans.PropertyEditorSupport; |
27 | 20 | import java.math.BigDecimal; |
28 | 21 | import java.math.BigInteger; |
|
44 | 37 |
|
45 | 38 | import org.apache.commons.logging.LogFactory; |
46 | 39 | import org.junit.Test; |
| 40 | + |
47 | 41 | import org.springframework.beans.factory.annotation.Autowire; |
48 | 42 | import org.springframework.beans.propertyeditors.CustomNumberEditor; |
49 | 43 | import org.springframework.beans.propertyeditors.StringArrayPropertyEditor; |
50 | 44 | import org.springframework.beans.propertyeditors.StringTrimmerEditor; |
51 | 45 | import org.springframework.beans.support.DerivedFromProtectedBaseBean; |
| 46 | +import org.springframework.core.convert.ConversionFailedException; |
| 47 | +import org.springframework.core.convert.TypeDescriptor; |
| 48 | +import org.springframework.core.convert.support.DefaultConversionService; |
| 49 | +import org.springframework.core.convert.support.GenericConversionService; |
52 | 50 | import org.springframework.tests.Assume; |
53 | 51 | import org.springframework.tests.TestGroup; |
54 | 52 | import org.springframework.tests.sample.beans.BooleanTestBean; |
55 | 53 | import org.springframework.tests.sample.beans.ITestBean; |
56 | 54 | import org.springframework.tests.sample.beans.IndexedTestBean; |
57 | 55 | import org.springframework.tests.sample.beans.NumberTestBean; |
58 | 56 | import org.springframework.tests.sample.beans.TestBean; |
59 | | -import org.springframework.core.convert.ConversionFailedException; |
60 | | -import org.springframework.core.convert.TypeDescriptor; |
61 | | -import org.springframework.core.convert.support.DefaultConversionService; |
62 | | -import org.springframework.core.convert.support.GenericConversionService; |
63 | 57 | import org.springframework.util.StopWatch; |
64 | 58 | import org.springframework.util.StringUtils; |
65 | 59 |
|
66 | 60 | import static org.hamcrest.Matchers.*; |
67 | | - |
68 | 61 | import static org.junit.Assert.*; |
69 | 62 |
|
70 | 63 | /** |
@@ -1556,28 +1549,37 @@ public void testWildcardedGenericEnum() { |
1556 | 1549 | @Test |
1557 | 1550 | public void cornerSpr10115() { |
1558 | 1551 | Spr10115Bean foo = new Spr10115Bean(); |
1559 | | - BeanWrapperImpl bwi = new BeanWrapperImpl(); |
1560 | | - bwi.setWrappedInstance(foo); |
| 1552 | + BeanWrapperImpl bwi = new BeanWrapperImpl(foo); |
1561 | 1553 | bwi.setPropertyValue("prop1", "val1"); |
1562 | 1554 | assertEquals("val1", Spr10115Bean.prop1); |
1563 | 1555 | } |
1564 | 1556 |
|
1565 | 1557 | @Test |
1566 | | - public void testArrayToObject() throws Exception { |
| 1558 | + public void testArrayToObject() { |
1567 | 1559 | ArrayToObject foo = new ArrayToObject(); |
1568 | | - BeanWrapperImpl bwi = new BeanWrapperImpl(); |
1569 | | - bwi.setWrappedInstance(foo); |
| 1560 | + BeanWrapperImpl bwi = new BeanWrapperImpl(foo); |
1570 | 1561 |
|
1571 | 1562 | Object[] array = new Object[] {"1","2"}; |
1572 | | - bwi.setPropertyValue("object", array ); |
| 1563 | + bwi.setPropertyValue("object", array); |
1573 | 1564 | assertThat(foo.getObject(), equalTo((Object) array)); |
1574 | 1565 |
|
1575 | 1566 | array = new Object[] {"1"}; |
1576 | | - bwi.setPropertyValue("object", array ); |
| 1567 | + bwi.setPropertyValue("object", array); |
1577 | 1568 | assertThat(foo.getObject(), equalTo((Object) array)); |
1578 | | -} |
| 1569 | + } |
| 1570 | + |
| 1571 | + @Test |
| 1572 | + public void testPropertyTypeMismatch() { |
| 1573 | + PropertyTypeMismatch foo = new PropertyTypeMismatch(); |
| 1574 | + BeanWrapperImpl bwi = new BeanWrapperImpl(foo); |
| 1575 | + bwi.setPropertyValue("object", "a String"); |
| 1576 | + assertEquals("a String", foo.value); |
| 1577 | + assertEquals(8, bwi.getPropertyValue("object")); |
| 1578 | + } |
| 1579 | + |
1579 | 1580 |
|
1580 | 1581 | static class Spr10115Bean { |
| 1582 | + |
1581 | 1583 | private static String prop1; |
1582 | 1584 |
|
1583 | 1585 | public static void setProp1(String prop1) { |
@@ -1962,18 +1964,31 @@ public enum TestEnum { |
1962 | 1964 | } |
1963 | 1965 |
|
1964 | 1966 |
|
1965 | | - static class ArrayToObject { |
| 1967 | + public static class ArrayToObject { |
1966 | 1968 |
|
1967 | 1969 | private Object object; |
1968 | 1970 |
|
1969 | | - |
1970 | 1971 | public void setObject(Object object) { |
1971 | 1972 | this.object = object; |
1972 | 1973 | } |
1973 | 1974 |
|
1974 | 1975 | public Object getObject() { |
1975 | 1976 | return object; |
1976 | 1977 | } |
| 1978 | + } |
| 1979 | + |
1977 | 1980 |
|
| 1981 | + public static class PropertyTypeMismatch { |
| 1982 | + |
| 1983 | + public String value; |
| 1984 | + |
| 1985 | + public void setObject(String object) { |
| 1986 | + this.value = object; |
| 1987 | + } |
| 1988 | + |
| 1989 | + public Integer getObject() { |
| 1990 | + return (this.value != null ? this.value.length() : null); |
| 1991 | + } |
1978 | 1992 | } |
| 1993 | + |
1979 | 1994 | } |
0 commit comments