Skip to content

Spring Framework 6.2.0-RC2 no longer creates a spy for @MockitoSpyBean #33803

@JKatzwinkel

Description

@JKatzwinkel

Upgrading from Spring Boot 3.4.0-M3 (Spring Framework 6.2.0-RC1) to Spring Boot 3.4.0-RC1 (Spring Framework 6.2.0-RC3) breaks my use of a @MockitoSpyBean of the form doReturn(results).when(spyBean).method(argumentMatchers...).

That form is the one recommend by Mockito.

The error thrown says Argument passed to when() is not a mock!: https://github.com/JKatzwinkel/tla-es/actions/runs/11541063711/job/32122614536?pr=382#step:9:188 .

This problem did not occur with Spring Boot 3.4.0-M3 (Spring Framework 6.2.0-RC1).

This is where the spy (operations) gets stubbed:

https://github.com/JKatzwinkel/tla-es/blob/dependabot/gradle/spring-boot-bf23beedc8/src/test/java/tla/backend/service/SentenceServiceTest.java#L99-L103

        doReturn(hits).when(operations).search(
            any(org.springframework.data.elasticsearch.core.query.Query.class),
            eq(SentenceEntity.class),
            any()
        );

Please let me know if you need further information or if this is not an issue with spring boot. Thanks!

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulestatus: duplicateA duplicate of another issuetype: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions