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 Summary
Modifier and TypeMethodDescriptionAllows in-place modification of a value reference from the target instance.default Injections
modifyField
(String name, Consumer<Object> modifier) Allows in-place modification of a value reference from the target instance.default Injections
modifyProperty
(String name, Consumer<Object> modifier) Allows in-place modification of a value reference from the target instance.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.IfpreferSetter
istrue
, an attempt will be made to inject the value using a setter method for the named property, otherwise the field itself will be injected.default Injections
Injects a value directly into all of the fields of the specified type.default Injections
Injects a value directly into an object field, if it exists, it not, an error is thrown.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.default Injections
setProperty
(String name, Object value) Trys to inject the value using a setter, if it exists, otherwise direct field injection is performed.default Injections
Updates a field value by applying given function to the current value.Updates a field value by applying given function to the current value.default Injections
updateField
(String name, Function<Object, Object> updater) Updates a field value by applying given function to the current value.default Injections
updateProperty
(String name, Function<Object, Object> updater) Updates a field value by applying given function to the current value of the field.
-
Method Details
-
setField
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 injectedvalue
- the value (may be a Randomizer).- Returns:
- the configured Injections instance
-
set
IfpreferSetter
istrue
, 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 thepreferSetter
value isfalse
the field will be directly injected.- Parameters:
name
- the name of the property or fieldvalue
- the value (may be a Randomizer).preferSetter
- whether to prefer the setter over direct injection- Returns:
- the configured Injections instance
-
setProperty
Trys to inject the value using a setter, if it exists, otherwise direct field injection is performed.- Parameters:
name
- the property namevalue
- the value- Returns:
- the configured injections instance
-
setField
Injects a value directly into all of the fields of the specified type.- Parameters:
type
- the field typevalue
- the value to inject- Returns:
- the configured injections instance
-
setProperty
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 typevalue
- the value to inject- Returns:
- the configured injections instance
-
set
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 typevalue
- the value to injectsetter
- prefers using the setter if it exists- Returns:
- the configured injections instance
-
updateField
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 nameupdater
- the updater function- Returns:
- the instance to the Injections implementation
-
updateProperty
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 nameupdater
- the updater function- Returns:
- the instance to the Injections implementation
-
update
Updates a field value by applying given function to the current value. If thepreferProps
parameter istrue
, 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 nameupdater
- the updater functionpreferProps
- 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 thepreferProps
parameter istrue
, 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 nameupdater
- the updater functionpreferSetter
- will try to use the setter rather than go directly to the fieldpreferGetter
- will try to use the getter rather than go directly to the field- Returns:
- the instance to the Injections implementation
-
modifyField
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 namemodifier
- the modifier- Returns:
- the instance of the Injections implementation
-
modifyProperty
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 namemodifier
- the modifier- Returns:
- the instance of the Injections implementation
-
modify
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 namemodifier
- the modifierpreferGetter
- will try to use the getter rather than going directly to the field- Returns:
- the instance of the Injections implementation
-