- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Open
Labels
in: testIssues in the test moduleIssues in the test modulestatus: waiting-for-triageAn issue we've not yet triaged or decided onAn issue we've not yet triaged or decided on
Description
Stubbing method calls on a @MockitoSpyBean in conjunction with ScopedProxyMode.TARGET_CLASS results in java.lang.IllegalStateException: Failed to unwrap proxied object.
Steps to reproduce:
- Write a Spring bean that uses @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS).
- In an integration test, make it a spy bean.
- Mock a call to the spy bean.
- Run the test.
I think the issue could be in org.springframework.test.context.bean.override.mockito.SpringMockResolver.getUltimateTargetObject. It invokes the method org.springframework.aop.framework.Advised#getTargetSource() on the spy bean and is (indirectly) called by org.mockito.internal.stubbing.StubberImpl#when(T mock), which means when(T mock) is not finished when getTargetSource() is called.
Please find the attached reproducer which has a full setup. Slightly more detailed information can be found in the contained README.md.
Metadata
Metadata
Assignees
Labels
in: testIssues in the test moduleIssues in the test modulestatus: waiting-for-triageAn issue we've not yet triaged or decided onAn issue we've not yet triaged or decided on