spring-framework/framework-docs/modules/ROOT/pages/testing/annotations/integration-spring
Sam Brannen 9181cce65f Support @⁠MockitoBean at the type level on test classes
Prior to this commit, @⁠MockitoBean could only be declared on fields
within test classes, which prevented developers from being able to
easily reuse mock configuration across a test suite.

With this commit, @⁠MockitoBean is now supported at the type level on
test classes, their superclasses, and interfaces implemented by those
classes. @⁠MockitoBean is also supported on enclosing classes for
@⁠Nested test classes, their superclasses, and interfaces implemented
by those classes, while honoring @⁠NestedTestConfiguration semantics.

In addition, @⁠MockitoBean:

- has a new `types` attribute that can be used to declare the type or
  types to mock when @⁠MockitoBean is declared at the type level

- can be declared as a repeatable annotation at the type level

- can be declared as a meta-annotation on a custom composed annotation
  which can be reused across a test suite (see the @⁠SharedMocks
  example in the reference manual)

To support these new features, this commit also includes the following
changes.

- The `field` property in BeanOverrideHandler is now @⁠Nullable.

- BeanOverrideProcessor has a new `default` createHandlers() method
  which is invoked when a @⁠BeanOverride annotation is found at the
  type level.

- MockitoBeanOverrideProcessor implements the new createHandlers()
  method.

- The internal findHandlers() method in BeanOverrideHandler has been
  completely overhauled.

- The @⁠MockitoBean and @⁠MockitoSpyBean section of the reference
  manual has been completely overhauled.

Closes gh-33925
2025-01-15 17:13:35 +01:00
..
annotation-activeprofiles.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-aftertransaction.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-beforetransaction.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-bootstrapwith.adoc Clarify supported targets for annotations in the TestContext framework 2024-05-07 16:45:12 +03:00
annotation-commit.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-contextconfiguration.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-contextcustomizerfactories.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-contexthierarchy.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-dirtiescontext.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-disabledinaotmode.adoc Clarify supported targets for annotations in the TestContext framework 2024-05-07 16:45:12 +03:00
annotation-dynamicpropertysource.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-mockitobean.adoc Support @⁠MockitoBean at the type level on test classes 2025-01-15 17:13:35 +01:00
annotation-recordapplicationevents.adoc Clarify supported targets for annotations in the TestContext framework 2024-05-07 16:45:12 +03:00
annotation-rollback.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-sql.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-sqlconfig.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-sqlgroup.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-sqlmergemode.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-testbean.adoc Properly resolve @⁠TestBean factory method within class hierarchy 2025-01-07 17:20:52 +02:00
annotation-testexecutionlisteners.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-testpropertysource.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00
annotation-webappconfiguration.adoc Remove obsolete role attributes for tab groups in the reference manual 2024-09-08 17:20:10 +02:00