Class BeanPropertySetter
java.lang.Object
org.mockito.internal.util.reflection.BeanPropertySetter
This utility class will call the setter of the property to inject a new value.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBeanPropertySetter
(Object target, Field propertyField) New BeanPropertySetter that don't report failureBeanPropertySetter
(Object target, Field propertyField, boolean reportNoSetterFound) New BeanPropertySetter -
Method Summary
Modifier and TypeMethodDescriptionprivate void
boolean
Set the value to the property represented by thisBeanPropertySetter
private String
setterName
(String fieldName) Retrieve the setter name from the field name.
-
Field Details
-
SET_PREFIX
- See Also:
-
target
-
reportNoSetterFound
private final boolean reportNoSetterFound -
field
-
-
Constructor Details
-
BeanPropertySetter
New BeanPropertySetter- Parameters:
target
- The target on which the setter must be invokedpropertyField
- The field that should be accessed with the setterreportNoSetterFound
- Allow the set method to raise an Exception if the setter cannot be found
-
BeanPropertySetter
New BeanPropertySetter that don't report failure- Parameters:
target
- The target on which the setter must be invokedpropertyField
- The propertyField that must be accessed through a setter
-
-
Method Details
-
set
Set the value to the property represented by thisBeanPropertySetter
- Parameters:
value
- the new value to pass to the property setter- Returns:
true
if the value has been injected,false
otherwise- Throws:
RuntimeException
- Can be thrown if the setter threw an exception, if the setter is not accessible or, ifreportNoSetterFound
and setter could not be found.
-
setterName
Retrieve the setter name from the field name.Implementation is based on the code of
Introspector
.- Parameters:
fieldName
- the Field name- Returns:
- Setter name.
-
reportNoSetterFound
private void reportNoSetterFound()
-