Skip to content

A @SpyBean on the output of a FactoryBean is not reset #31204

Closed

Description

@nightswimmings

Repository SpyBeans seem to keep stubs when context is reused on other test class, since 2.6.x up to 2.7.0, at least

This does not seem to happen with regular beans (i.e, not JPA proxies Repository interfaces), and it seems caused by MockReset.get(bean) not returning AFTER in objectResetMocksTestExecutionListener.resetMocks, when it should. It returns NONE because SpringBootMockResolver does not find the target, apparently
test.zip
.

Activity

  1. added
    status: waiting-for-triage
    on May 30, 2022
  2. self-assigned this
    on May 30, 2022
  3. changed the title [-]Repository SpyBeans not reseting between tests[/-] [+]A @SpyBean on the output of a FactoryBean is not reset[/+] on May 30, 2022
  4. wilkinsona commented on May 30, 2022

    @wilkinsona
    Member

    Thanks for the sample, @nightswimmings. As far as I can tell, the problem is broader than proxied Spring Data Repository interfaces. It appears to apply whenever @SpyBean is used on the output of a FactoryBean.

    @MockBean is not affected as when the mock is created, it's added to MockitoBeans from where it can be retrieved and reset. Also adding spies to MockitoBeans may be a solution but I'll need to give it and any potential unwanted side-effects some more thought.

  5. added this to the 2.6.x milestone on May 30, 2022
  6. added
    type: bug
    and removed
    status: waiting-for-triage
    on May 30, 2022
  7. modified the milestones: 2.6.x, 2.7.x on Nov 24, 2022
  8. added a commit that references this issue on Mar 8, 2023
    e3da85a
  9. removed their assignment
    on Oct 26, 2023
  10. modified the milestones: 2.7.x, 3.0.x on Oct 26, 2023
  11. modified the milestones: 3.0.x, 3.1.x on Nov 8, 2023
  12. modified the milestones: 3.1.x, 3.2.x on Apr 26, 2024
  13. simonbasle commented on Aug 13, 2024

    @simonbasle

    Just chiming in to note that this is what's done for Spring Framework 6.2's @MockitoSpyBean, as the @MockitoBean and @MockitoSpyBean are covered by the same code for tracking in the framework version of MockitoBeans.

  14. modified the milestones: 3.2.x, 3.3.x on Nov 4, 2024
  15. wilkinsona commented on Nov 6, 2024

    @wilkinsona
    Member

    Moved to 3.3.x to avoid potentially destabilising 3.2.x before its final OSS release.

  16. self-assigned this
    on Nov 6, 2024
  17. modified the milestones: 3.3.x, 3.3.6 on Nov 6, 2024
  18. added a commit that references this issue on Nov 6, 2024
    4900ca1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions