Class ReflectionTestUtils

java.lang.Object
fr.paris.lutece.test.ReflectionTestUtils

public class ReflectionTestUtils extends Object
  • Constructor Details

    • ReflectionTestUtils

      public ReflectionTestUtils()
  • Method Details

    • setField

      public static void setField(Object targetObject, String name, Object value)
      Set the field with the given name on the provided targetObject to the supplied value.

      This method delegates to setField(Object, String, Object, Class), supplying null for the type argument.

      Parameters:
      targetObject - the target object on which to set the field; never null
      name - the name of the field to set; never null
      value - the value to set
    • setField

      public static void setField(Object targetObject, String name, Object value, Class<?> type)
      Set the field with the given name/type on the provided targetObject to the supplied value.

      This method delegates to setField(Object, Class, String, Object, Class), supplying null for the targetClass argument.

      Parameters:
      targetObject - the target object on which to set the field; never null
      name - the name of the field to set; may be null if type is specified
      value - the value to set
      type - the type of the field to set; may be null if name is specified
    • setField

      public static void setField(Class<?> targetClass, String name, Object value)
      Set the static field with the given name on the provided targetClass to the supplied value.

      This method delegates to setField(Object, Class, String, Object, Class), supplying null for the targetObject and type arguments.

      This method does not support setting static final fields.

      Parameters:
      targetClass - the target class on which to set the static field; never null
      name - the name of the field to set; never null
      value - the value to set
      Since:
      4.2
    • setField

      public static void setField(Class<?> targetClass, String name, Object value, Class<?> type)
      Set the static field with the given name/type on the provided targetClass to the supplied value.

      This method delegates to setField(Object, Class, String, Object, Class), supplying null for the targetObject argument.

      This method does not support setting static final fields.

      Parameters:
      targetClass - the target class on which to set the static field; never null
      name - the name of the field to set; may be null if type is specified
      value - the value to set
      type - the type of the field to set; may be null if name is specified
      Since:
      4.2
    • setField

      public static void setField(Object targetObject, Class<?> targetClass, String name, Object value, Class<?> type)
      Set the field with the given name/type on the provided targetObject/targetClass to the supplied value.

      If the supplied targetObject is a proxy, it will be unwrapped allowing the field to be set on the ultimate target of the proxy.

      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.

      This method does not support setting static final fields.

      Parameters:
      targetObject - the target object on which to set the field; may be null if the field is static
      targetClass - the target class on which to set the field; may be null if the field is an instance field
      name - the name of the field to set; may be null if type is specified
      value - the value to set
      type - the type of the field to set; may be null if name is specified
      Since:
      4.2
      See Also:
      • ReflectionUtils#findField(Class, String, Class)
      • ReflectionUtils#makeAccessible(Field)
      • ReflectionUtils#setField(Field, Object, Object)
      • AopTestUtils#getUltimateTargetObject(Object)