Class ReflectionTestUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidstatic voidstatic voidSet the field with the givenname/typeon the providedtargetObject/targetClassto the suppliedvalue.static voidstatic void
-
Constructor Details
-
ReflectionTestUtils
public ReflectionTestUtils()
-
-
Method Details
-
setField
Set the field with the givennameon the providedtargetObjectto the suppliedvalue.This method delegates to
setField(Object, String, Object, Class), supplyingnullfor thetypeargument.- Parameters:
targetObject- the target object on which to set the field; nevernullname- the name of the field to set; nevernullvalue- the value to set
-
setField
Set the field with the givenname/typeon the providedtargetObjectto the suppliedvalue.This method delegates to
setField(Object, Class, String, Object, Class), supplyingnullfor thetargetClassargument.- Parameters:
targetObject- the target object on which to set the field; nevernullname- the name of the field to set; may benulliftypeis specifiedvalue- the value to settype- the type of the field to set; may benullifnameis specified
-
setField
Set the static field with the givennameon the providedtargetClassto the suppliedvalue.This method delegates to
setField(Object, Class, String, Object, Class), supplyingnullfor thetargetObjectandtypearguments.This method does not support setting
static finalfields.- Parameters:
targetClass- the target class on which to set the static field; nevernullname- the name of the field to set; nevernullvalue- the value to set- Since:
- 4.2
-
setField
Set the static field with the givenname/typeon the providedtargetClassto the suppliedvalue.This method delegates to
setField(Object, Class, String, Object, Class), supplyingnullfor thetargetObjectargument.This method does not support setting
static finalfields.- Parameters:
targetClass- the target class on which to set the static field; nevernullname- the name of the field to set; may benulliftypeis specifiedvalue- the value to settype- the type of the field to set; may benullifnameis specified- Since:
- 4.2
-
setField
public static void setField(Object targetObject, Class<?> targetClass, String name, Object value, Class<?> type) Set the field with the givenname/typeon the providedtargetObject/targetClassto the suppliedvalue.If the supplied
targetObjectis a proxy, it will be unwrapped allowing the field to be set on the ultimate target of the proxy.This method traverses the class hierarchy in search of the desired field. In addition, an attempt will be made to make non-
publicfields accessible, thus allowing one to setprotected,private, and package-private fields.This method does not support setting
static finalfields.- Parameters:
targetObject- the target object on which to set the field; may benullif the field is statictargetClass- the target class on which to set the field; may benullif the field is an instance fieldname- the name of the field to set; may benulliftypeis specifiedvalue- the value to settype- the type of the field to set; may benullifnameis specified- Since:
- 4.2
- See Also:
-
ReflectionUtils#findField(Class, String, Class)ReflectionUtils#makeAccessible(Field)ReflectionUtils#setField(Field, Object, Object)AopTestUtils#getUltimateTargetObject(Object)
-