-
Couldn't load subscription status.
- Fork 38.8k
Description
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.