Class BeanPropertySetter

java.lang.Object
org.mockito.internal.util.reflection.BeanPropertySetter

public class BeanPropertySetter extends Object
This utility class will call the setter of the property to inject a new value.
  • Field Details

    • SET_PREFIX

      private static final String SET_PREFIX
      See Also:
    • target

      private final Object target
    • reportNoSetterFound

      private final boolean reportNoSetterFound
    • field

      private final Field field
  • Constructor Details

    • BeanPropertySetter

      public BeanPropertySetter(Object target, Field propertyField, boolean reportNoSetterFound)
      New BeanPropertySetter
      Parameters:
      target - The target on which the setter must be invoked
      propertyField - The field that should be accessed with the setter
      reportNoSetterFound - Allow the set method to raise an Exception if the setter cannot be found
    • BeanPropertySetter

      public BeanPropertySetter(Object target, Field propertyField)
      New BeanPropertySetter that don't report failure
      Parameters:
      target - The target on which the setter must be invoked
      propertyField - The propertyField that must be accessed through a setter
  • Method Details

    • set

      public boolean set(Object value)
      Set the value to the property represented by this BeanPropertySetter
      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, if reportNoSetterFound and setter could not be found.
    • setterName

      private String setterName(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()