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

Introduce enforceOverride flag in @TestBean and @MockitoBean #33613

Closed
sbrannen opened this issue Sep 30, 2024 · 1 comment
Closed

Introduce enforceOverride flag in @TestBean and @MockitoBean #33613

sbrannen opened this issue Sep 30, 2024 · 1 comment
Assignees
Labels
in: test Issues in the test module type: enhancement A general enhancement
Milestone

Comments

@sbrannen
Copy link
Member

sbrannen commented Sep 30, 2024

Currently, @MockitoBean can be used to create or replace a bean definition, and @TestBean can only be used to replace a bean definition.

The reason is that the @MockitoBean support is hard coded to use the REPLACE_OR_CREATE_DEFINITION strategy; whereas, the @TestBean support is hard coded to use the REPLACE_DEFINITION strategy.

Instead of hard coding those strategies, we should introduce a new enforceOverride attribute in @TestBean and @MockitoBean that defaults to true but allows the user to decide if it's OK to create a bean for a nonexistent bean definition. TestBeanOverrideProcessor and MockitoBeanOverrideProcessor can then dynamically decide whether to use the REPLACE_DEFINITION or REPLACE_OR_CREATE_DEFINITION strategy based on the enforceOverride flag.

@sbrannen sbrannen added in: test Issues in the test module type: enhancement A general enhancement labels Sep 30, 2024
@sbrannen sbrannen added this to the 6.2.0-RC2 milestone Sep 30, 2024
@sbrannen sbrannen self-assigned this Sep 30, 2024
@sbrannen
Copy link
Member Author

sbrannen commented Oct 9, 2024

Reopening to switch the default values for enforceOverride attributes to false, to align with the existing behavior for @MockBean in Spring Boot and to simplify the programming model for common use cases.

@sbrannen sbrannen reopened this Oct 9, 2024
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 type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant