Skip to content

Introduce enforceOverride flag in @TestBean and @MockitoBean #33613

Closed
@sbrannen

Description

@sbrannen

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions