Class FieldInitializer
java.lang.Object
org.mockito.internal.util.reflection.FieldInitializer
Initialize a field with type instance if a default constructor can be found.
If the given field is already initialized, then the actual instance is returned. This initializer doesn't work with inner classes, local classes, interfaces or abstract types.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Represents the strategy used to resolve actual instances to be given to a constructor given the argument types.private static interface
(package private) static class
Constructor instantiating strategy for no-arg constructor.(package private) static class
Constructor instantiating strategy for parameterized constructors. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Field
private final Object
private final FieldInitializer.ConstructorInstantiator
-
Constructor Summary
ConstructorsModifierConstructorDescriptionFieldInitializer
(Object fieldOwner, Field field) Prepare initializer with the given field on the given instance.FieldInitializer
(Object fieldOwner, Field field, FieldInitializer.ConstructorArgumentResolver argResolver) Prepare initializer with the given field on the given instance.private
FieldInitializer
(Object fieldOwner, Field field, FieldInitializer.ConstructorInstantiator instantiator) -
Method Summary
Modifier and TypeMethodDescriptionprivate FieldInitializationReport
private void
checkNotAbstract
(Field field) private void
checkNotEnum
(Field field) private void
checkNotInner
(Field field) private void
checkNotInterface
(Field field) private void
checkNotLocal
(Field field) Initialize field if not initialized and return the actual instance.
-
Field Details
-
fieldOwner
-
field
-
instantiator
-
-
Constructor Details
-
FieldInitializer
Prepare initializer with the given field on the given instance.This constructor fail fast if the field type cannot be handled.
- Parameters:
fieldOwner
- Instance of the test.field
- Field to be initialize.
-
FieldInitializer
public FieldInitializer(Object fieldOwner, Field field, FieldInitializer.ConstructorArgumentResolver argResolver) Prepare initializer with the given field on the given instance.This constructor fail fast if the field type cannot be handled.
- Parameters:
fieldOwner
- Instance of the test.field
- Field to be initialize.argResolver
- Constructor parameters resolver
-
FieldInitializer
private FieldInitializer(Object fieldOwner, Field field, FieldInitializer.ConstructorInstantiator instantiator)
-
-
Method Details
-
initialize
Initialize field if not initialized and return the actual instance.- Returns:
- Actual field instance.
-
checkNotLocal
-
checkNotInner
-
checkNotInterface
-
checkNotAbstract
-
checkNotEnum
-
acquireFieldInstance
- Throws:
IllegalAccessException
-