Skip to content

Commit 006cb64

Browse files
committed
Merge branch '2.4.x'
Closes gh-25514
2 parents 2cffbc9 + 2f95c1e commit 006cb64

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -6678,11 +6678,11 @@ Mock beans are automatically reset after each test method.
66786678
[NOTE]
66796679
====
66806680
If your test uses one of Spring Boot's test annotations (such as `@SpringBootTest`), this feature is automatically enabled.
6681-
To use this feature with a different arrangement, a listener must be explicitly added, as shown in the following example:
6681+
To use this feature with a different arrangement, listeners must be explicitly added, as shown in the following example:
66826682
66836683
[source,java,pending-extract=true,indent=0]
66846684
----
6685-
@TestExecutionListeners(MockitoTestExecutionListener.class)
6685+
@TestExecutionListeners({ MockitoTestExecutionListener.class, ResetMocksTestExecutionListener.class })
66866686
----
66876687
66886688
====

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoTestExecutionListener.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@
3333
import org.springframework.util.ReflectionUtils.FieldCallback;
3434

3535
/**
36-
* {@link TestExecutionListener} to trigger {@link MockitoAnnotations#openMocks(Object)}
37-
* when {@link MockBean @MockBean} annotations are used. Primarily to allow
38-
* {@link Captor @Captor} annotations.
36+
* {@link TestExecutionListener} to enable {@link MockBean @MockBean} and
37+
* {@link SpyBean @SpyBean} support. Also triggers
38+
* {@link MockitoAnnotations#openMocks(Object)} when any Mockito annotations used,
39+
* primarily to allow {@link Captor @Captor} annotations.
40+
* <p>
41+
* To use the automatic reset support of {@code @MockBean} and {@code @SpyBean}, configure
42+
* {@link ResetMocksTestExecutionListener} as well.
3943
*
4044
* @author Phillip Webb
4145
* @author Andy Wilkinson
4246
* @since 1.4.2
47+
* @see ResetMocksTestExecutionListener
4348
*/
4449
public class MockitoTestExecutionListener extends AbstractTestExecutionListener {
4550

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/ResetMocksTestExecutionListener.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,10 +35,11 @@
3535

3636
/**
3737
* {@link TestExecutionListener} to reset any mock beans that have been marked with a
38-
* {@link MockReset}.
38+
* {@link MockReset}. Typically used alongside {@link MockitoTestExecutionListener}.
3939
*
4040
* @author Phillip Webb
4141
* @since 1.4.0
42+
* @see MockitoTestExecutionListener
4243
*/
4344
public class ResetMocksTestExecutionListener extends AbstractTestExecutionListener {
4445

0 commit comments

Comments
 (0)