Class SpyAnnotationEngine
- java.lang.Object
-
- org.mockito.internal.configuration.SpyAnnotationEngine
-
- All Implemented Interfaces:
AnnotationEngine
,AnnotationEngine
public class SpyAnnotationEngine extends java.lang.Object implements 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 Constructor Description SpyAnnotationEngine()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
assertNoIncompatibleAnnotations(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.reflect.Field field, java.lang.Class<? extends java.lang.annotation.Annotation>... undesiredAnnotations)
private static java.lang.reflect.Constructor<?>
noArgConstructorOf(java.lang.Class<?> type)
java.lang.AutoCloseable
process(java.lang.Class<?> context, java.lang.Object testInstance)
Processes the test instance to configure annotated members.private static java.lang.Object
spyInstance(java.lang.reflect.Field field, java.lang.Object instance)
private static java.lang.Object
spyNewInstance(java.lang.Object testInstance, java.lang.reflect.Field field)
private static boolean
typeIsNonStaticInnerClass(java.lang.Class<?> type, int modifiers)
private static boolean
typeIsPrivateAbstractInnerClass(java.lang.Class<?> type, int modifiers)
-
-
-
Method Detail
-
process
public java.lang.AutoCloseable process(java.lang.Class<?> context, java.lang.Object testInstance)
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
private static java.lang.Object spyInstance(java.lang.reflect.Field field, java.lang.Object instance)
-
spyNewInstance
private static java.lang.Object spyNewInstance(java.lang.Object testInstance, java.lang.reflect.Field field) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
- Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
noArgConstructorOf
private static java.lang.reflect.Constructor<?> noArgConstructorOf(java.lang.Class<?> type)
-
typeIsNonStaticInnerClass
private static boolean typeIsNonStaticInnerClass(java.lang.Class<?> type, int modifiers)
-
typeIsPrivateAbstractInnerClass
private static boolean typeIsPrivateAbstractInnerClass(java.lang.Class<?> type, int modifiers)
-
assertNoIncompatibleAnnotations
private static void assertNoIncompatibleAnnotations(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.reflect.Field field, java.lang.Class<? extends java.lang.annotation.Annotation>... undesiredAnnotations)
-
-