Add @MockitoBeanSettings, use MockitoSession with strict stubs default

This commit changes the way the `MockitoTestExecutionListener` sets up
mockito, now using the `MockitoSession` feature. Additionally, stubbing
now defaults to a STRICT mode which can be overruled with a newly
introduced annotation: `@MockitoBeanSettings`.

Closes gh-33318
This commit is contained in:
Simon Baslé
2024-08-07 14:57:15 +02:00
parent bc05474271
commit 1c893e6354
5 changed files with 239 additions and 13 deletions

View File

@@ -23,6 +23,9 @@ creating unnecessary contexts.
====
Each annotation also defines Mockito-specific attributes to fine-tune the mocking details.
During the test class lifecycle, Mockito is set up via the `Mockito#mockitoSession()`
mechanism. Notably, it enables `STRICT_STUBS` mode by default. This can be changed on
individual test classes with the `@MockitoBeanSettings` annotation.
The `@MockitoBean` annotation uses the `REPLACE_OR_CREATE_DEFINITION`
xref:testing/testcontext-framework/bean-overriding.adoc#testcontext-bean-overriding-custom[strategy for test bean overriding].