Class BeanPropertySetter
- java.lang.Object
-
- org.mockito.internal.util.reflection.BeanPropertySetter
-
public class BeanPropertySetter extends java.lang.Object
This utility class will call the setter of the property to inject a new value.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.reflect.Field
field
private boolean
reportNoSetterFound
private static java.lang.String
SET_PREFIX
private java.lang.Object
target
-
Constructor Summary
Constructors Constructor Description BeanPropertySetter(java.lang.Object target, java.lang.reflect.Field propertyField)
New BeanPropertySetter that don't report failureBeanPropertySetter(java.lang.Object target, java.lang.reflect.Field propertyField, boolean reportNoSetterFound)
New BeanPropertySetter
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
reportNoSetterFound()
boolean
set(java.lang.Object value)
Set the value to the property represented by thisBeanPropertySetter
private java.lang.String
setterName(java.lang.String fieldName)
Retrieve the setter name from the field name.
-
-
-
Field Detail
-
SET_PREFIX
private static final java.lang.String SET_PREFIX
- See Also:
- Constant Field Values
-
target
private final java.lang.Object target
-
reportNoSetterFound
private final boolean reportNoSetterFound
-
field
private final java.lang.reflect.Field field
-
-
Constructor Detail
-
BeanPropertySetter
public BeanPropertySetter(java.lang.Object target, java.lang.reflect.Field propertyField, boolean reportNoSetterFound)
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
public BeanPropertySetter(java.lang.Object target, java.lang.reflect.Field propertyField)
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 Detail
-
set
public boolean set(java.lang.Object value)
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:
java.lang.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
private java.lang.String setterName(java.lang.String fieldName)
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()
-
-