From 22b73f3020c5089f2653a4616f0709c59b52d9eb Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 5 Mar 2021 14:14:36 +0000 Subject: [PATCH] Polish "Improve documentaion of Mockito test execution listeners" See gh-25375 --- .../src/docs/asciidoc/spring-boot-features.adoc | 2 +- .../mock/mockito/MockitoTestExecutionListener.java | 11 ++++++++--- .../mock/mockito/ResetMocksTestExecutionListener.java | 5 +++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc index 4db3eba5c2..d2c86ca71f 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc @@ -6593,7 +6593,7 @@ To use this feature with a different arrangement, listeners must be explicitly a [source,java,indent=0] ---- - @TestExecutionListeners({MockitoTestExecutionListener.class, ResetMocksTestExecutionListener.class}) + @TestExecutionListeners({ MockitoTestExecutionListener.class, ResetMocksTestExecutionListener.class }) ---- ==== diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoTestExecutionListener.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoTestExecutionListener.java index 674ea672f7..5239b15ec7 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoTestExecutionListener.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoTestExecutionListener.java @@ -33,13 +33,18 @@ import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils.FieldCallback; /** - * {@link TestExecutionListener} to trigger {@link MockitoAnnotations#initMocks(Object)} - * when {@link MockBean @MockBean} annotations are used. Primarily to allow - * {@link Captor @Captor} annotations. + * {@link TestExecutionListener} to enable {@link MockBean @MockBean} and + * {@link SpyBean @SpyBean} support. Also triggers + * {@link MockitoAnnotations#initMocks(Object)} when any Mockito annotations used, + * primarily to allow {@link Captor @Captor} annotations. + *

+ * To use the automatic reset support of {@code @MockBean} and {@code @SpyBean}, configure + * {@link ResetMocksTestExecutionListener} as well. * * @author Phillip Webb * @author Andy Wilkinson * @since 1.4.2 + * @see ResetMocksTestExecutionListener */ public class MockitoTestExecutionListener extends AbstractTestExecutionListener { diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/ResetMocksTestExecutionListener.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/ResetMocksTestExecutionListener.java index 27cce2d866..2033c2e648 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/ResetMocksTestExecutionListener.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/ResetMocksTestExecutionListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,10 +35,11 @@ import org.springframework.util.ClassUtils; /** * {@link TestExecutionListener} to reset any mock beans that have been marked with a - * {@link MockReset}. + * {@link MockReset}. Typically used alongside {@link MockitoTestExecutionListener}. * * @author Phillip Webb * @since 1.4.0 + * @see MockitoTestExecutionListener */ public class ResetMocksTestExecutionListener extends AbstractTestExecutionListener {