Skip to content

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

@JavaDevaraj

Description

@JavaDevaraj

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: testIssues in the test module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions