diff --git a/framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-mockitobean.adoc b/framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-mockitobean.adoc index 6aa5ddd9c2b3..d46508f3d9a4 100644 --- a/framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-mockitobean.adoc +++ b/framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-mockitobean.adoc @@ -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... diff --git a/framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-testbean.adoc b/framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-testbean.adoc index f814e50c00c6..9f294606f2e0 100644 --- a/framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-testbean.adoc +++ b/framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-testbean.adoc @@ -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(); } } diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBean.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBean.java index b4c11f8b4aa6..3b870f1dcb97 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBean.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBean.java @@ -105,6 +105,11 @@ * FactoryBean}, the {@code FactoryBean} will be replaced with a singleton bean * corresponding to the value returned from the {@code @TestBean} factory method. * + *

There are no restrictions on the visibility of {@code @TestBean} fields or + * factory methods. Such fields and methods can therefore be {@code public}, + * {@code protected}, package-private (default visibility), or {@code private} + * depending on the needs or coding practices of the project. + * * @author Simon Baslé * @author Stephane Nicoll * @author Sam Brannen diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoBean.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoBean.java index 111f07638a7b..f01d0fc10b53 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoBean.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoBean.java @@ -58,6 +58,11 @@ * FactoryBean}, the {@code FactoryBean} will be replaced with a singleton mock * of the type of object created by the {@code FactoryBean}. * + *

There are no restrictions on the visibility of a {@code @MockitoBean} field. + * Such fields can therefore be {@code public}, {@code protected}, package-private + * (default visibility), or {@code private} depending on the needs or coding + * practices of the project. + * * @author Simon Baslé * @author Sam Brannen * @since 6.2 diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBean.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBean.java index b465347b0dfa..6320a54845b1 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBean.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBean.java @@ -51,6 +51,11 @@ * a spy will be created for the object created by the {@code FactoryBean}, not * for the {@code FactoryBean} itself. * + *

There are no restrictions on the visibility of a {@code @MockitoSpyBean} field. + * Such fields can therefore be {@code public}, {@code protected}, package-private + * (default visibility), or {@code private} depending on the needs or coding + * practices of the project. + * * @author Simon Baslé * @author Sam Brannen * @since 6.2