abstract class ReflectionTestUtils
ReflectionTestUtils is a collection of reflection-based utility methods for use in unit and integration testing scenarios.
There are often times when it would be beneficial to be able to set a non-public field, invoke a non-public setter method, or invoke a non-public configuration or lifecycle callback method when testing code involving, for example:
private or protected field access as opposed to public setter methods for properties in a domain entity.private or protected fields, setter methods, and configuration methods.In addition, several methods in this class provide support for static fields — for example, #setField(Class, String, Object), #getField(Class, String), etc.
Author
Sam Brannen
Author
Juergen Hoeller
Since
2.5
See Also
ReflectionUtilsAopTestUtils
ReflectionTestUtils()
There are often times when it would be beneficial to be able to set a non-
In addition, several methods in this class provide support for |
open static fun getField(targetObject: Any, name: String): Any
Get the value of the Field with the given This method delegates to open static fun getField(targetClass: Class<*>, name: String): Any
Get the value of the static Field with the given This method delegates to open static fun getField(targetObject: Any, targetClass: Class<*>, name: String): Any
Get the value of the Field with the given If the supplied This method traverses the class hierarchy in search of the desired field. In addition, an attempt will be made to make non- |
|
open static fun invokeGetterMethod(target: Any, name: String): Any
Invoke the getter method with the given This method traverses the class hierarchy in search of the desired method. In addition, an attempt will be made to make non- In addition, this method supports JavaBean-style property names. For example, if you wish to get the |
|
open static fun <T : Any> invokeMethod(target: Any, name: String, vararg args: Any): T
Invoke the method with the given This method traverses the class hierarchy in search of the desired method. In addition, an attempt will be made to make non- |
|
open static fun invokeSetterMethod(target: Any, name: String, value: Any): Unitopen static fun invokeSetterMethod(target: Any, name: String, value: Any, type: Class<*>): Unit
Invoke the setter method with the given This method traverses the class hierarchy in search of the desired method. In addition, an attempt will be made to make non- In addition, this method supports JavaBean-style property names. For example, if you wish to set the |
|
open static fun setField(targetObject: Any, name: String, value: Any): Unit
Set the Field with the given This method delegates to open static fun setField(targetObject: Any, name: String, value: Any, type: Class<*>): Unit
Set the Field with the given This method delegates to open static fun setField(targetClass: Class<*>, name: String, value: Any): Unit
Set the static Field with the given This method delegates to open static fun setField(targetClass: Class<*>, name: String, value: Any, type: Class<*>): Unit
Set the static Field with the given This method delegates to open static fun setField(targetObject: Any, targetClass: Class<*>, name: String, value: Any, type: Class<*>): Unit
Set the Field with the given If the supplied This method traverses the class hierarchy in search of the desired field. In addition, an attempt will be made to make non- |