Document visibility requirements for Bean Overrides
This commit makes it clear that there are no visibility requirements for @TestBean fields or factory methods as well as @MockitoBean or @MockitoSpyBean fields. Closes gh-33923
This commit is contained in:
@@ -52,6 +52,15 @@ When using `@MockitoSpyBean` to create a spy for a `FactoryBean`, a spy will be
|
||||
for the object created by the `FactoryBean`, not for the `FactoryBean` itself.
|
||||
====
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
There are no restrictions on the visibility of `@MockitoBean` and `@MockitoSpyBean`
|
||||
fields.
|
||||
|
||||
Such fields can therefore be `public`, `protected`, package-private (default visibility),
|
||||
or `private` depending on the needs or coding practices of the project.
|
||||
====
|
||||
|
||||
The following example shows how to use the default behavior of the `@MockitoBean` annotation:
|
||||
|
||||
[tabs]
|
||||
@@ -62,7 +71,7 @@ Java::
|
||||
----
|
||||
class OverrideBeanTests {
|
||||
@MockitoBean // <1>
|
||||
private CustomService customService;
|
||||
CustomService customService;
|
||||
|
||||
// test case body...
|
||||
}
|
||||
@@ -86,7 +95,7 @@ Java::
|
||||
----
|
||||
class OverrideBeanTests {
|
||||
@MockitoBean("service") // <1>
|
||||
private CustomService customService;
|
||||
CustomService customService;
|
||||
|
||||
// test case body...
|
||||
|
||||
@@ -107,7 +116,7 @@ Java::
|
||||
----
|
||||
class OverrideBeanTests {
|
||||
@MockitoSpyBean // <1>
|
||||
private CustomService customService;
|
||||
CustomService customService;
|
||||
|
||||
// test case body...
|
||||
}
|
||||
@@ -130,7 +139,7 @@ Java::
|
||||
----
|
||||
class OverrideBeanTests {
|
||||
@MockitoSpyBean("service") // <1>
|
||||
private CustomService customService;
|
||||
CustomService customService;
|
||||
|
||||
// test case body...
|
||||
|
||||
|
||||
@@ -30,6 +30,14 @@ same bean in several tests, make sure to name the field consistently to avoid cr
|
||||
unnecessary contexts.
|
||||
====
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
There are no restrictions on the visibility of `@TestBean` fields or factory methods.
|
||||
|
||||
Such fields and methods can therefore be `public`, `protected`, package-private (default
|
||||
visibility), or `private` depending on the needs or coding practices of the project.
|
||||
====
|
||||
|
||||
The following example shows how to use the default behavior of the `@TestBean` annotation:
|
||||
|
||||
[tabs]
|
||||
@@ -40,11 +48,11 @@ Java::
|
||||
----
|
||||
class OverrideBeanTests {
|
||||
@TestBean // <1>
|
||||
private CustomService customService;
|
||||
CustomService customService;
|
||||
|
||||
// test case body...
|
||||
|
||||
private static CustomService customService() { // <2>
|
||||
static CustomService customService() { // <2>
|
||||
return new MyFakeCustomService();
|
||||
}
|
||||
}
|
||||
@@ -68,11 +76,11 @@ Java::
|
||||
----
|
||||
class OverrideBeanTests {
|
||||
@TestBean(name = "service", methodName = "createCustomService") // <1>
|
||||
private CustomService customService;
|
||||
CustomService customService;
|
||||
|
||||
// test case body...
|
||||
|
||||
private static CustomService createCustomService() { // <2>
|
||||
static CustomService createCustomService() { // <2>
|
||||
return new MyFakeCustomService();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user