Merge branch '6.2.x'
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.
|
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:
|
The following example shows how to use the default behavior of the `@MockitoBean` annotation:
|
||||||
|
|
||||||
[tabs]
|
[tabs]
|
||||||
@@ -62,7 +71,7 @@ Java::
|
|||||||
----
|
----
|
||||||
class OverrideBeanTests {
|
class OverrideBeanTests {
|
||||||
@MockitoBean // <1>
|
@MockitoBean // <1>
|
||||||
private CustomService customService;
|
CustomService customService;
|
||||||
|
|
||||||
// test case body...
|
// test case body...
|
||||||
}
|
}
|
||||||
@@ -86,7 +95,7 @@ Java::
|
|||||||
----
|
----
|
||||||
class OverrideBeanTests {
|
class OverrideBeanTests {
|
||||||
@MockitoBean("service") // <1>
|
@MockitoBean("service") // <1>
|
||||||
private CustomService customService;
|
CustomService customService;
|
||||||
|
|
||||||
// test case body...
|
// test case body...
|
||||||
|
|
||||||
@@ -107,7 +116,7 @@ Java::
|
|||||||
----
|
----
|
||||||
class OverrideBeanTests {
|
class OverrideBeanTests {
|
||||||
@MockitoSpyBean // <1>
|
@MockitoSpyBean // <1>
|
||||||
private CustomService customService;
|
CustomService customService;
|
||||||
|
|
||||||
// test case body...
|
// test case body...
|
||||||
}
|
}
|
||||||
@@ -130,7 +139,7 @@ Java::
|
|||||||
----
|
----
|
||||||
class OverrideBeanTests {
|
class OverrideBeanTests {
|
||||||
@MockitoSpyBean("service") // <1>
|
@MockitoSpyBean("service") // <1>
|
||||||
private CustomService customService;
|
CustomService customService;
|
||||||
|
|
||||||
// test case body...
|
// test case body...
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,14 @@ same bean in several tests, make sure to name the field consistently to avoid cr
|
|||||||
unnecessary contexts.
|
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:
|
The following example shows how to use the default behavior of the `@TestBean` annotation:
|
||||||
|
|
||||||
[tabs]
|
[tabs]
|
||||||
@@ -40,11 +48,11 @@ Java::
|
|||||||
----
|
----
|
||||||
class OverrideBeanTests {
|
class OverrideBeanTests {
|
||||||
@TestBean // <1>
|
@TestBean // <1>
|
||||||
private CustomService customService;
|
CustomService customService;
|
||||||
|
|
||||||
// test case body...
|
// test case body...
|
||||||
|
|
||||||
private static CustomService customService() { // <2>
|
static CustomService customService() { // <2>
|
||||||
return new MyFakeCustomService();
|
return new MyFakeCustomService();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,11 +76,11 @@ Java::
|
|||||||
----
|
----
|
||||||
class OverrideBeanTests {
|
class OverrideBeanTests {
|
||||||
@TestBean(name = "service", methodName = "createCustomService") // <1>
|
@TestBean(name = "service", methodName = "createCustomService") // <1>
|
||||||
private CustomService customService;
|
CustomService customService;
|
||||||
|
|
||||||
// test case body...
|
// test case body...
|
||||||
|
|
||||||
private static CustomService createCustomService() { // <2>
|
static CustomService createCustomService() { // <2>
|
||||||
return new MyFakeCustomService();
|
return new MyFakeCustomService();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,11 @@ import org.springframework.test.context.bean.override.BeanOverride;
|
|||||||
* FactoryBean}, the {@code FactoryBean} will be replaced with a singleton bean
|
* FactoryBean}, the {@code FactoryBean} will be replaced with a singleton bean
|
||||||
* corresponding to the value returned from the {@code @TestBean} factory method.
|
* corresponding to the value returned from the {@code @TestBean} factory method.
|
||||||
*
|
*
|
||||||
|
* <p>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 Simon Baslé
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
|
|||||||
@@ -58,6 +58,11 @@ import org.springframework.test.context.bean.override.BeanOverride;
|
|||||||
* FactoryBean}, the {@code FactoryBean} will be replaced with a singleton mock
|
* FactoryBean}, the {@code FactoryBean} will be replaced with a singleton mock
|
||||||
* of the type of object created by the {@code FactoryBean}.
|
* of the type of object created by the {@code FactoryBean}.
|
||||||
*
|
*
|
||||||
|
* <p>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 Simon Baslé
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @since 6.2
|
* @since 6.2
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ import org.springframework.test.context.bean.override.BeanOverride;
|
|||||||
* a spy will be created for the object created by the {@code FactoryBean}, not
|
* a spy will be created for the object created by the {@code FactoryBean}, not
|
||||||
* for the {@code FactoryBean} itself.
|
* for the {@code FactoryBean} itself.
|
||||||
*
|
*
|
||||||
|
* <p>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 Simon Baslé
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @since 6.2
|
* @since 6.2
|
||||||
|
|||||||
Reference in New Issue
Block a user