Class InjectionsImpl

java.lang.Object
io.github.cjstehno.testthings.inject.InjectionsImpl
All Implemented Interfaces:
Injections

public class InjectionsImpl extends Object implements Injections
Default Injections implementation.
  • Constructor Details

    • InjectionsImpl

      public InjectionsImpl()
  • Method Details

    • set

      public Injections set(String name, Object value, boolean preferSetter)
      Description copied from interface: Injections
      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.
      Specified by:
      set in interface Injections
      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
    • set

      public Injections set(Class<?> type, Object value, boolean setter)
      Description copied from interface: Injections
      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.
      Specified by:
      set in interface Injections
      Parameters:
      type - the field type
      value - the value to inject
      setter - prefers using the setter if it exists
      Returns:
      the configured injections instance
    • update

      public Injections update(String name, Function<Object,Object> updater, boolean preferSetter, boolean preferGetter)
      Description copied from interface: Injections
      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.

      Specified by:
      update in interface Injections
      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
    • modify

      public Injections modify(String name, Consumer<Object> modifier, boolean preferGetter)
      Description copied from interface: Injections
      Allows in-place modification of a value reference from the target instance. The target instance will be passed to the provided consumer for modification.
      Specified by:
      modify in interface Injections
      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
    • apply

      public <T> T apply(T instance) throws ReflectiveOperationException
      Applies the configured injections to the given instance.
      Type Parameters:
      T - the type of the target instance
      Parameters:
      instance - the target instance
      Returns:
      the updated instance (reference to the incoming instance)
      Throws:
      ReflectiveOperationException - if there is a problem injecting