Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 489 by
yuanju...@gmail.com: @InjectMocks and @Spy cannot be used
together when object initialized by mockito
http://code.google.com/p/mockito/issues/detail?id=489
What steps will reproduce the problem?
1. use @InjectMocks and @Spy annotation on the same object A.
2. use @InjectMocks annotation on object B to inject A.
3. after initMocks(this), the reference of B within A is null.
code example:
@InjectMocks
@Spy
A a;
@InjectMocks
B b;
What is the expected output? What do you see instead?
The expect result is I have a spy object A inside B after initMocks(). But
inside B I have A refers to null.
What version of the product are you using? On what operating system?
Mockito 1.9.5, windows 7.
Please provide any additional information below.
The following code will be working as expected:
@InjectMocks
@Spy
A a = new A();
@InjectMocks
B b;
I think the problem might be in the class SpyAnnotationEngine's method
process(Class<?> context, Object testInstance), as it will ignore the
initialization of field annotated by both @Spy and @InjectMocks.
Although the javadoc says "If the field is also annotated with the
compatible @InjectMocks then the field will be ignored, The injection
engine will handle this specific case." In my test it seems the injection
engine doesn't handle this case after all.
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings