Skip to content
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

@SpyBean can be stubbed, but @MockitoSpyBean cannot be stubbed #34516

Open
JavaDevaraj opened this issue Feb 28, 2025 · 0 comments
Open

@SpyBean can be stubbed, but @MockitoSpyBean cannot be stubbed #34516

JavaDevaraj opened this issue Feb 28, 2025 · 0 comments
Assignees
Labels
in: test Issues in the test module status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@JavaDevaraj
Copy link

JavaDevaraj commented Feb 28, 2025

In Spring Boot 3.3:

@SpyBean
private ReprocessBackOffImpl reprocessBackOffImpl;
doThrow(exception).when(reprocessBackOffImpl).assertPreConditions(context);

It's working fine....

but after upgrading to Spring Boot 3.4:

@MockitoSpyBean
private ReprocessBackOffImpl reprocessBackOffImpl;
doThrow(exception).when(reprocessBackOffImpl).assertPreConditions(context);

I'm getting the following exception.

Argument passed to when() is not a mock!
Example of correct stubbing:
    doThrow(new RuntimeException()).when(mock).someMethod();
org.mockito.exceptions.misusing.NotAMockException: 
Argument passed to when() is not a mock!
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 28, 2025
@JavaDevaraj JavaDevaraj changed the title In SpringBoot 3.3 @SpyBean can able to mock and spy but @MockitoSpyBean can able to spy but cannot able to mock In SpringBoot 3.3 @SpyBean can able to mock and spy but after upgrading to Springboot 3.4 @MockitoSpyBean can able to spy but cannot able to mock Feb 28, 2025
@bclozel bclozel added the in: test Issues in the test module label Feb 28, 2025
@sbrannen sbrannen self-assigned this Feb 28, 2025
@sbrannen sbrannen changed the title In SpringBoot 3.3 @SpyBean can able to mock and spy but after upgrading to Springboot 3.4 @MockitoSpyBean can able to spy but cannot able to mock @SpyBean can be stubbed, but @MockitoSpyBean cannot be stubbed Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

4 participants