Class FieldInitializer
- java.lang.Object
-
- org.mockito.internal.util.reflection.FieldInitializer
-
public class FieldInitializer extends java.lang.Object
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 Classes Modifier and Type Class Description static interface
FieldInitializer.ConstructorArgumentResolver
Represents the strategy used to resolve actual instances to be given to a constructor given the argument types.private static interface
FieldInitializer.ConstructorInstantiator
(package private) static class
FieldInitializer.NoArgConstructorInstantiator
Constructor instantiating strategy for no-arg constructor.(package private) static class
FieldInitializer.ParameterizedConstructorInstantiator
Constructor instantiating strategy for parameterized constructors.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.reflect.Field
field
private java.lang.Object
fieldOwner
private FieldInitializer.ConstructorInstantiator
instantiator
-
Constructor Summary
Constructors Modifier Constructor Description FieldInitializer(java.lang.Object fieldOwner, java.lang.reflect.Field field)
Prepare initializer with the given field on the given instance.FieldInitializer(java.lang.Object fieldOwner, java.lang.reflect.Field field, FieldInitializer.ConstructorArgumentResolver argResolver)
Prepare initializer with the given field on the given instance.private
FieldInitializer(java.lang.Object fieldOwner, java.lang.reflect.Field field, FieldInitializer.ConstructorInstantiator instantiator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private FieldInitializationReport
acquireFieldInstance()
private void
checkNotAbstract(java.lang.reflect.Field field)
private void
checkNotEnum(java.lang.reflect.Field field)
private void
checkNotInner(java.lang.reflect.Field field)
private void
checkNotInterface(java.lang.reflect.Field field)
private void
checkNotLocal(java.lang.reflect.Field field)
FieldInitializationReport
initialize()
Initialize field if not initialized and return the actual instance.
-
-
-
Field Detail
-
fieldOwner
private final java.lang.Object fieldOwner
-
field
private final java.lang.reflect.Field field
-
instantiator
private final FieldInitializer.ConstructorInstantiator instantiator
-
-
Constructor Detail
-
FieldInitializer
public FieldInitializer(java.lang.Object fieldOwner, java.lang.reflect.Field field)
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(java.lang.Object fieldOwner, java.lang.reflect.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(java.lang.Object fieldOwner, java.lang.reflect.Field field, FieldInitializer.ConstructorInstantiator instantiator)
-
-
Method Detail
-
initialize
public FieldInitializationReport initialize()
Initialize field if not initialized and return the actual instance.- Returns:
- Actual field instance.
-
checkNotLocal
private void checkNotLocal(java.lang.reflect.Field field)
-
checkNotInner
private void checkNotInner(java.lang.reflect.Field field)
-
checkNotInterface
private void checkNotInterface(java.lang.reflect.Field field)
-
checkNotAbstract
private void checkNotAbstract(java.lang.reflect.Field field)
-
checkNotEnum
private void checkNotEnum(java.lang.reflect.Field field)
-
acquireFieldInstance
private FieldInitializationReport acquireFieldInstance() throws java.lang.IllegalAccessException
- Throws:
java.lang.IllegalAccessException
-
-