java.lang.Object | |
↳ | org.springframework.test.util.ReflectionTestUtils |
ReflectionTestUtils is a collection of reflection-based utility methods for use in unit and integration testing scenarios.
There are often situations in which it would be beneficial to be able to set
a non-public
field or invoke a non-public
setter
method when testing code involving, for example:
private
or protected
field access as opposed to
public
setter methods for properties in a domain entity.@Autowired
and
javax.annotation.Resource @Resource which provides dependency
injection for private
or protected
fields, setter
methods, and configuration methods.Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Get the field with the given
name from the provided target
object. | |||||||||||
Invoke the getter method with the given
name on the supplied
target object with the supplied value . | |||||||||||
Invoke the setter method with the given
name on the supplied
target object with the supplied value . | |||||||||||
Invoke the setter method with the given
name on the supplied
target object with the supplied value . | |||||||||||
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Get the field with the given name
from the provided target
object.
This method traverses the class hierarchy in search of the desired field.
In addition, an attempt will be made to make non-public
fields accessible, thus allowing one to get
protected
, private
, and
package-private fields.
target | the target object on which to set the field |
---|---|
name | the name of the field to get |
Invoke the getter method with the given name
on the supplied
target object with the supplied value
.
This method traverses the class hierarchy in search of the desired
method. In addition, an attempt will be made to make non-
public
methods accessible, thus allowing one to
invoke protected
, private
, and
package-private getter methods.
In addition, this method supports JavaBean-style property names.
For example, if you wish to get the name
property on the
target object, you may pass either "name" or
"getName" as the method name.
target | the target object on which to invoke the specified getter method |
---|---|
name | the name of the getter method to invoke or the corresponding property name |
Invoke the setter method with the given name
on the supplied
target object with the supplied value
.
This method traverses the class hierarchy in search of the desired
method. In addition, an attempt will be made to make non-
public
methods accessible, thus allowing one to
invoke protected
, private
, and
package-private setter methods.
In addition, this method supports JavaBean-style property names.
For example, if you wish to set the name
property on the
target object, you may pass either "name" or
"setName" as the method name.
target | the target object on which to invoke the specified setter method |
---|---|
name | the name of the setter method to invoke or the corresponding property name |
value | the value to provide to the setter method |
type | the formal parameter type declared by the setter method |
Invoke the setter method with the given name
on the supplied
target object with the supplied value
.
This method traverses the class hierarchy in search of the desired
method. In addition, an attempt will be made to make non-
public
methods accessible, thus allowing one to
invoke protected
, private
, and
package-private setter methods.
In addition, this method supports JavaBean-style property names.
For example, if you wish to set the name
property on the
target object, you may pass either "name" or
"setName" as the method name.
target | the target object on which to invoke the specified setter method |
---|---|
name | the name of the setter method to invoke or the corresponding property name |
value | the value to provide to the setter method |
Set the Field field with the given name
on the
provided target object
to the supplied value
.
This method traverses the class hierarchy in search of the desired field.
In addition, an attempt will be made to make non-public
fields accessible, thus allowing one to set
protected
, private
, and
package-private fields.
target | the target object on which to set the field |
---|---|
name | the name of the field to set |
value | the value to set |
Set the Field field with the given name
on the
provided target object
to the supplied value
.
This method traverses the class hierarchy in search of the desired field.
In addition, an attempt will be made to make non-public
fields accessible, thus allowing one to set
protected
, private
, and
package-private fields.
target | the target object on which to set the field |
---|---|
name | the name of the field to set |
value | the value to set |
type | the type of the field (may be null ) |