@ -22,6 +22,9 @@ import org.junit.Rule;
import org.junit.Test ;
import org.junit.rules.ExpectedException ;
import org.springframework.aop.framework.ProxyCreatorSupport ;
import org.springframework.aop.framework.ProxyFactory ;
import org.springframework.aop.support.AopUtils ;
import org.springframework.test.util.subpackage.Component ;
import org.springframework.test.util.subpackage.LegacyEntity ;
import org.springframework.test.util.subpackage.Person ;
@ -359,4 +362,35 @@ public class ReflectionTestUtilsTests {
invokeMethod ( component , "configure" , new Integer ( 42 ) , "enigma" , "baz" , "quux" ) ;
}
@Test
public void setAndGetFieldOnProxiedInstance ( ) throws Exception {
ProxyFactory pf = new ProxyFactory ( this . person ) ;
pf . setProxyTargetClass ( true ) ;
Person proxyPerson = ( Person ) pf . getProxy ( ) ;
setField ( proxyPerson , "id" , new Long ( 99 ) , long . class ) ;
setField ( proxyPerson , "name" , "Tom" ) ;
setField ( proxyPerson , "age" , new Integer ( 42 ) ) ;
setField ( proxyPerson , "eyeColor" , "blue" , String . class ) ;
setField ( proxyPerson , "likesPets" , Boolean . TRUE ) ;
setField ( proxyPerson , "favoriteNumber" , PI , Number . class ) ;
assertEquals ( "ID (private field in a superclass)" , 99 , person . getId ( ) ) ;
assertEquals ( "name (protected field)" , "Tom" , person . getName ( ) ) ;
assertEquals ( "age (private field)" , 42 , person . getAge ( ) ) ;
assertEquals ( "eye color (package private field)" , "blue" , person . getEyeColor ( ) ) ;
assertEquals ( "'likes pets' flag (package private boolean field)" , true , person . likesPets ( ) ) ;
assertEquals ( "'favorite number' (package field)" , PI , person . getFavoriteNumber ( ) ) ;
assertEquals ( new Long ( 99 ) , getField ( proxyPerson , "id" ) ) ;
assertEquals ( "Tom" , getField ( proxyPerson , "name" ) ) ;
assertEquals ( new Integer ( 42 ) , getField ( proxyPerson , "age" ) ) ;
assertEquals ( "blue" , getField ( proxyPerson , "eyeColor" ) ) ;
assertEquals ( Boolean . TRUE , getField ( proxyPerson , "likesPets" ) ) ;
assertEquals ( PI , getField ( proxyPerson , "favoriteNumber" ) ) ;
}
}