-
Notifications
You must be signed in to change notification settings - Fork 40.9k
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
Mockito fails to verify the second time on the proxied bean #6871
Comments
@igormukhin there's nothing specific to Spring Boot in your project. I have the feeling that it could be a mockito usage problem. Please create an issue in the Spring Framework issue tracker. Also, rather than pasting the full code in the description, please create a project that one can run, it's much more convenient. |
@igormukhin We faced a very similar issue with the new |
@igormukhin In that case the code above isn't much help as it doesn't use |
@igormukhin Also, please ensure you're using |
@wilkinsona @philwebb Here is the project you requested with @SpyBean - https://github.com/igormukhin/spring-boot-issue-6871 |
Thanks! I think we need to refine our |
FYI: the solution to the original code example is simply to invoke For example, the following works fine: @Test
public void testTransactionalMethod() throws Exception {
SomeServiceWithTransact ultimateTargetObject = AopTestUtils.<SomeServiceWithTransact> getUltimateTargetObject(
someServiceWithTransact);
SomeServiceWithTransact serviceSpy = spy(ultimateTargetObject);
// when
serviceSpy.transactionalMethod(1);
// then
verify(serviceSpy, times(1)).transactionalMethod(1);
verify(serviceSpy, times(1)).transactionalMethod(anyInt());
} Regards, Sam |
Thanks @sbrannen for the workaround, I just used it in order to answer StackOverflow question #62698827. (BTW, I never used Spring, I am just interested in AOP topics and stumbled upon the question.) There you can also find a link to yet another GitHub sample project. I am mentioning this in order to remind any possibly involved maintainers that this is still an open issue which ought to be addressed eventually. |
Thanks, @kriegaex. While you can use the same technique to avoid the problem described on Stack Overflow, it is a different problem to the one fixed in this issue. I'm not sure if we'll be able to automatically avoid the advice being executed when setting up expectations on the spy but we can certainly take a look. I've opened #22281. |
Version: Spring Boot 1.4.0-RELEASE
It looks like there is an issue with verifing multiple times with Mockito on a proxied bean.
Test-case:
Now:
testNormalMethod()
will be green and all righttestTransactionalMethod()
will be red and it is not all right. The only difference to the first test in the code is that the method unter test is annotated with@Transactional
testTransactionalMethod()
fails with:But!
verify
, the test will become green.The text was updated successfully, but these errors were encountered: