|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2013 the original author or authors. |
|
|
|
* Copyright 2002-2014 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,13 +16,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.beans; |
|
|
|
package org.springframework.beans; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
|
|
import static org.junit.Assert.assertFalse; |
|
|
|
|
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
|
|
|
|
import static org.junit.Assert.assertSame; |
|
|
|
|
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
|
|
|
|
import static org.junit.Assert.fail; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.beans.PropertyEditorSupport; |
|
|
|
import java.beans.PropertyEditorSupport; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.BigInteger; |
|
|
|
import java.math.BigInteger; |
|
|
|
@ -44,11 +37,16 @@ import java.util.TreeSet; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowire; |
|
|
|
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; |
|
|
|
import org.springframework.beans.support.DerivedFromProtectedBaseBean; |
|
|
|
import org.springframework.beans.support.DerivedFromProtectedBaseBean; |
|
|
|
|
|
|
|
import org.springframework.core.convert.ConversionFailedException; |
|
|
|
|
|
|
|
import org.springframework.core.convert.TypeDescriptor; |
|
|
|
|
|
|
|
import org.springframework.core.convert.support.DefaultConversionService; |
|
|
|
|
|
|
|
import org.springframework.core.convert.support.GenericConversionService; |
|
|
|
import org.springframework.tests.Assume; |
|
|
|
import org.springframework.tests.Assume; |
|
|
|
import org.springframework.tests.TestGroup; |
|
|
|
import org.springframework.tests.TestGroup; |
|
|
|
import org.springframework.tests.sample.beans.BooleanTestBean; |
|
|
|
import org.springframework.tests.sample.beans.BooleanTestBean; |
|
|
|
@ -56,15 +54,10 @@ import org.springframework.tests.sample.beans.ITestBean; |
|
|
|
import org.springframework.tests.sample.beans.IndexedTestBean; |
|
|
|
import org.springframework.tests.sample.beans.IndexedTestBean; |
|
|
|
import org.springframework.tests.sample.beans.NumberTestBean; |
|
|
|
import org.springframework.tests.sample.beans.NumberTestBean; |
|
|
|
import org.springframework.tests.sample.beans.TestBean; |
|
|
|
import org.springframework.tests.sample.beans.TestBean; |
|
|
|
import org.springframework.core.convert.ConversionFailedException; |
|
|
|
|
|
|
|
import org.springframework.core.convert.TypeDescriptor; |
|
|
|
|
|
|
|
import org.springframework.core.convert.support.DefaultConversionService; |
|
|
|
|
|
|
|
import org.springframework.core.convert.support.GenericConversionService; |
|
|
|
|
|
|
|
import org.springframework.util.StopWatch; |
|
|
|
import org.springframework.util.StopWatch; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.*; |
|
|
|
import static org.hamcrest.Matchers.*; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -1556,28 +1549,37 @@ public final class BeanWrapperTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void cornerSpr10115() { |
|
|
|
public void cornerSpr10115() { |
|
|
|
Spr10115Bean foo = new Spr10115Bean(); |
|
|
|
Spr10115Bean foo = new Spr10115Bean(); |
|
|
|
BeanWrapperImpl bwi = new BeanWrapperImpl(); |
|
|
|
BeanWrapperImpl bwi = new BeanWrapperImpl(foo); |
|
|
|
bwi.setWrappedInstance(foo); |
|
|
|
|
|
|
|
bwi.setPropertyValue("prop1", "val1"); |
|
|
|
bwi.setPropertyValue("prop1", "val1"); |
|
|
|
assertEquals("val1", Spr10115Bean.prop1); |
|
|
|
assertEquals("val1", Spr10115Bean.prop1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testArrayToObject() throws Exception { |
|
|
|
public void testArrayToObject() { |
|
|
|
ArrayToObject foo = new ArrayToObject(); |
|
|
|
ArrayToObject foo = new ArrayToObject(); |
|
|
|
BeanWrapperImpl bwi = new BeanWrapperImpl(); |
|
|
|
BeanWrapperImpl bwi = new BeanWrapperImpl(foo); |
|
|
|
bwi.setWrappedInstance(foo); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object[] array = new Object[] {"1","2"}; |
|
|
|
Object[] array = new Object[] {"1","2"}; |
|
|
|
bwi.setPropertyValue("object", array ); |
|
|
|
bwi.setPropertyValue("object", array); |
|
|
|
assertThat(foo.getObject(), equalTo((Object) array)); |
|
|
|
assertThat(foo.getObject(), equalTo((Object) array)); |
|
|
|
|
|
|
|
|
|
|
|
array = new Object[] {"1"}; |
|
|
|
array = new Object[] {"1"}; |
|
|
|
bwi.setPropertyValue("object", array ); |
|
|
|
bwi.setPropertyValue("object", array); |
|
|
|
assertThat(foo.getObject(), equalTo((Object) array)); |
|
|
|
assertThat(foo.getObject(), equalTo((Object) array)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testPropertyTypeMismatch() { |
|
|
|
|
|
|
|
PropertyTypeMismatch foo = new PropertyTypeMismatch(); |
|
|
|
|
|
|
|
BeanWrapperImpl bwi = new BeanWrapperImpl(foo); |
|
|
|
|
|
|
|
bwi.setPropertyValue("object", "a String"); |
|
|
|
|
|
|
|
assertEquals("a String", foo.value); |
|
|
|
|
|
|
|
assertEquals(8, bwi.getPropertyValue("object")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class Spr10115Bean { |
|
|
|
static class Spr10115Bean { |
|
|
|
|
|
|
|
|
|
|
|
private static String prop1; |
|
|
|
private static String prop1; |
|
|
|
|
|
|
|
|
|
|
|
public static void setProp1(String prop1) { |
|
|
|
public static void setProp1(String prop1) { |
|
|
|
@ -1962,11 +1964,10 @@ public final class BeanWrapperTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class ArrayToObject { |
|
|
|
public static class ArrayToObject { |
|
|
|
|
|
|
|
|
|
|
|
private Object object; |
|
|
|
private Object object; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setObject(Object object) { |
|
|
|
public void setObject(Object object) { |
|
|
|
this.object = object; |
|
|
|
this.object = object; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1974,6 +1975,20 @@ public final class BeanWrapperTests { |
|
|
|
public Object getObject() { |
|
|
|
public Object getObject() { |
|
|
|
return object; |
|
|
|
return object; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class PropertyTypeMismatch { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String value; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setObject(String object) { |
|
|
|
|
|
|
|
this.value = object; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Integer getObject() { |
|
|
|
|
|
|
|
return (this.value != null ? this.value.length() : null); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|