-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@InjectMocks and @Spy on same field should cause MockitoException #169
Comments
Now seeing the other thest: MockInjectionUsingSetterOrPropertyTest, I got a bit confused as it suggests this combination is ok (only the injection of such created spy will not happen), which seems to be in conflict with WrongSetOfAnnotationsTest.shouldNotAllowSpyAndInjectMock(). Is it an obsolete test then? |
Hi thanks a lot for spotting this. So yes this is the combination of The combination of |
I have fixed the wrong unit test. Again thanks a lot for taking a look on the matter :) |
Some time ago there was @InjectMocks and @Spy cannot be used together when object initialized by mockito issue rejected.
Checking the codebase I found a test case
WrongSetOfAnnotationsTest.shouldNotAllowSpyAndInjectMock()
which, I guess, was supposed to cover Brice's explanation. The test passes because the MockitoException is thrown, but it's thrown for different reason: the test tries to instantiate an interface (List). The test was there at list since 2010, so I think the behavior could have been basically forgotten.So, although I find Brice's explanation convincing, I still think the exception should be thrown in that case, informing of wrong Mockito usage.
The text was updated successfully, but these errors were encountered: