Interface Injections

All Known Implementing Classes:
InjectionsImpl

public interface Injections
Defines some standard injection utilities. Random Value Objects. If the value object passed into the injection methods is an instance of a Randomizer, that randomizer will be used to randomly generate the value.
  • Method Details

    • setField

      default Injections setField(String name, Object value)
      Injects a value directly into an object field, if it exists, it not, an error is thrown.
      Parameters:
      name - the name of the field to be injected
      value - the value (may be a Randomizer).
      Returns:
      the configured Injections instance
    • set

      Injections set(String name, Object value, boolean preferSetter)
      If preferSetter is true, an attempt will be made to inject the value using a setter method for the named property, otherwise the field itself will be injected. If the preferSetter value is false the field will be directly injected.
      Parameters:
      name - the name of the property or field
      value - the value (may be a Randomizer).
      preferSetter - whether to prefer the setter over direct injection
      Returns:
      the configured Injections instance
    • setProperty

      default Injections setProperty(String name, Object value)
      Trys to inject the value using a setter, if it exists, otherwise direct field injection is performed.
      Parameters:
      name - the property name
      value - the value
      Returns:
      the configured injections instance
    • setField

      default Injections setField(Class<?> type, Object value)
      Injects a value directly into all of the fields of the specified type.
      Parameters:
      type - the field type
      value - the value to inject
      Returns:
      the configured injections instance
    • setProperty

      default Injections setProperty(Class<?> type, Object value)
      Injects a value into the setters setting the specified type - if a setter does not exist, it will try to inject directly into a field of the type. If a setter and a field both match, it will only inject one of them, not both.
      Parameters:
      type - the field type
      value - the value to inject
      Returns:
      the configured injections instance
    • set

      Injections set(Class<?> type, Object value, boolean setter)
      Injects a value into the setters setting the specified type - if a setter does not exist, it will try to inject directly into a field of the type. If a setter and a field both match, it will only inject one of them, not both.
      Parameters:
      type - the field type
      value - the value to inject
      setter - prefers using the setter if it exists
      Returns:
      the configured injections instance
    • updateField

      default Injections updateField(String name, Function<Object,Object> updater)
      Updates a field value by applying given function to the current value.

      If the updater function returns a Randomizer, it will be used to generate the updated value.

      Parameters:
      name - the property or field name
      updater - the updater function
      Returns:
      the instance to the Injections implementation
    • updateProperty

      default Injections updateProperty(String name, Function<Object,Object> updater)
      Updates a field value by applying given function to the current value of the field. The getter and setter method will be used, if they exist.

      If the updater function returns a Randomizer, it will be used to generate the updated value.

      Parameters:
      name - the property or field name
      updater - the updater function
      Returns:
      the instance to the Injections implementation
    • update

      default Injections update(String name, Function<Object,Object> updater, boolean preferProps)
      Updates a field value by applying given function to the current value. If the preferProps parameter is true, the injector will first attempt to use the named property before defaulting update the field directly.

      If the updater function returns a Randomizer, it will be used to generate the updated value.

      Parameters:
      name - the property or field name
      updater - the updater function
      preferProps - prefer the use of the getter and setter methods over direct field access
      Returns:
      the instance to the Injections implementation
    • update

      Injections update(String name, Function<Object,Object> updater, boolean preferSetter, boolean preferGetter)
      Updates a field value by applying given function to the current value. If the preferProps parameter is true, the injector will first attempt to use the named property before defaulting update the field directly.

      If the updater function returns a Randomizer, it will be used to generate the updated value.

      Parameters:
      name - the property or field name
      updater - the updater function
      preferSetter - will try to use the setter rather than go directly to the field
      preferGetter - will try to use the getter rather than go directly to the field
      Returns:
      the instance to the Injections implementation
    • modifyField

      default Injections modifyField(String name, Consumer<Object> modifier)
      Allows in-place modification of a value reference from the target instance. The target instance will be passed to the provided consumer for modification.
      Parameters:
      name - the name
      modifier - the modifier
      Returns:
      the instance of the Injections implementation
    • modifyProperty

      default Injections modifyProperty(String name, Consumer<Object> modifier)
      Allows in-place modification of a value reference from the target instance. The target instance will be passed to the provided consumer for modification. The getter will be used, if it exists.
      Parameters:
      name - the name
      modifier - the modifier
      Returns:
      the instance of the Injections implementation
    • modify

      Injections modify(String name, Consumer<Object> modifier, boolean preferGetter)
      Allows in-place modification of a value reference from the target instance. The target instance will be passed to the provided consumer for modification.
      Parameters:
      name - the name
      modifier - the modifier
      preferGetter - will try to use the getter rather than going directly to the field
      Returns:
      the instance of the Injections implementation