Package org.easymock.internal
Class Injector
java.lang.Object
org.easymock.internal.Injector
Performs creation of mocks and injection into test subjects in accordance with annotations present in the host object.
- Since:
- 3.3
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
createMocksForAnnotations
(Class<?> hostClass, Object host, InjectionPlan injectionPlan) Create the mocks and find the fields annotated withTestSubject
private static Injection
findUniqueAssignable
(List<Injection> injections, InjectionTarget target) private static Field
getFieldByName
(Class<?> clazz, String fieldName) injectByName
(Class<?> clazz, Object obj, List<Injection> qualifiedInjections) private static void
private static InjectionTarget
static void
injectMocks
(Object host) Inject a mock to every fields annotated withMock
on the class passed in parameter.private static void
injectMocksOnClass
(Class<?> clazz, Object obj, InjectionPlan injectionPlan) Try to inject a mock to every fields in the class(package private) static <T> T
private static MockType
mockTypeFromAnnotation
(Mock annotation) private static boolean
-
Constructor Details
-
Injector
public Injector()
-
-
Method Details
-
injectMocks
Inject a mock to every fields annotated withMock
on the class passed in parameter. Then, inject these mocks to the fields of every class annotated withTestSubject
.The rules are
- Static and final fields are ignored
- If two mocks have the same field name, return an error
- If a mock has a field name and no matching field is found, return an error
- If a mock without field name can be assigned to a field, do it. The same mock can be assigned more than once
- If no mock can be assigned to a field, skip the field silently
- If the mock cannot be assigned to any field, skip the mock silently
- If two mocks can be assigned to the same field, return an error
Note: If the parameter extends
EasyMockSupport
, the mocks will be created using it to allowreplayAll/verifyAll
to work afterwards- Parameters:
host
- the object on which to inject mocks- Since:
- 3.2
-
instantiateTestSubject
-
createMocksForAnnotations
private static void createMocksForAnnotations(Class<?> hostClass, Object host, InjectionPlan injectionPlan) Create the mocks and find the fields annotated withTestSubject
- Parameters:
hostClass
- class to searchhost
- object of the classinjectionPlan
- output parameter where the created mocks and fields to inject are added
-
mockTypeFromAnnotation
-
injectMocksOnClass
Try to inject a mock to every fields in the class- Parameters:
clazz
- class where the fields are takenobj
- object being a instance of clazzinjectionPlan
- details of possible mocks for injection
-
injectByName
-
injectByType
-
fieldsOf
-
getFieldByName
-
injectionTargetWithField
-
shouldNotAssignTo
-
findUniqueAssignable
-