Class SpyAnnotationEngine
java.lang.Object
org.mockito.internal.configuration.SpyAnnotationEngine
- All Implemented Interfaces:
AnnotationEngine
,AnnotationEngine
Process fields annotated with @Spy.
Will try transform the field in a spy as with Mockito.spy()
.
If the field is not initialized, will try to initialize it, with a no-arg constructor.
If the field is also annotated with the compatible @InjectMocks then the field will be ignored, The injection engine will handle this specific case.
This engine will fail, if the field is also annotated with incompatible Mockito annotations.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.mockito.plugins.AnnotationEngine
AnnotationEngine.NoAction
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
assertNoIncompatibleAnnotations
(Class<? extends Annotation> annotation, Field field, Class<? extends Annotation>... undesiredAnnotations) private static Constructor<?>
noArgConstructorOf
(Class<?> type) Processes the test instance to configure annotated members.private static Object
spyInstance
(Field field, Object instance) private static Object
spyNewInstance
(Object testInstance, Field field) private static boolean
typeIsNonStaticInnerClass
(Class<?> type, int modifiers) private static boolean
typeIsPrivateAbstractInnerClass
(Class<?> type, int modifiers)
-
Constructor Details
-
SpyAnnotationEngine
public SpyAnnotationEngine()
-
-
Method Details
-
process
Description copied from interface:AnnotationEngine
Processes the test instance to configure annotated members.- Specified by:
process
in interfaceAnnotationEngine
- Parameters:
context
- Class where to extract field information, check implementation for detailstestInstance
- Test instance
-
spyInstance
-
spyNewInstance
private static Object spyNewInstance(Object testInstance, Field field) throws InstantiationException, IllegalAccessException, InvocationTargetException -
noArgConstructorOf
-
typeIsNonStaticInnerClass
-
typeIsPrivateAbstractInnerClass
-
assertNoIncompatibleAnnotations
private static void assertNoIncompatibleAnnotations(Class<? extends Annotation> annotation, Field field, Class<? extends Annotation>... undesiredAnnotations)
-