-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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 [SPR-14701] #19265
Comments
Igor Mukhin commented The project that shows the issue: https://github.com/igormukhin/spring-boot-issue-6871 |
Stéphane Nicoll commented In the meantime, it turns out you were using Spring Boot and that Looking at the original project you've reported, you're spying on the bean directly (i.e. the proxy) so if you want to pursue that way (i.e. not using |
Sam Brannen commented I have admittedly not looked at the sample project in detail, but.... Have you considered using |
Igor Mukhin commented You mean like |
Sam Brannen commented Yes, that's exactly what I meant. I just tested it locally, and the following works fine: @Test
public void testTransactionalMethod() throws Exception {
SomeServiceWithTransact ultimateTargetObject = AopTestUtils.getUltimateTargetObject(
someServiceWithTransact);
SomeServiceWithTransact serviceSpy = spy(ultimateTargetObject);
// when
serviceSpy.transactionalMethod(1);
// then
verify(serviceSpy, times(1)).transactionalMethod(1);
verify(serviceSpy, times(1)).transactionalMethod(anyInt());
} I am therefore closing this issue as Invalid. Regards, Sam |
Igor Mukhin commented Thanks, ))) I was testing it right now the same time with you. igormukhin/spring-boot-issue-6871@448cb1e Both |
Sam Brannen commented Great! I'm glad it works for you. By the way, although |
Igor Mukhin opened SPR-14701 and commented
I discovered this bug by using
@SpyBean
in a Spring Boot 1.4.0 web application. But the bug is reproducable without Spring Boot and@SpyBean
, so snicoll said I should file the bug here.It looks like there is an issue with verifying 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!
@Transactional
form the bean under test, the test will become green.verify
, the test will become green.Affects: 4.3.2
The text was updated successfully, but these errors were encountered: