Merge pull request #25375 from cdalexndr

* gh-25375:
  Polish "Improve documentaion of Mockito test execution listeners"
  Improve documentaion of Mockito test execution listeners

Closes gh-25375
pull/25620/head
Andy Wilkinson 4 years ago
commit c62367e8c4

@ -6589,11 +6589,11 @@ Mock beans are automatically reset after each test method.
[NOTE]
====
If your test uses one of Spring Boot's test annotations (such as `@SpringBootTest`), this feature is automatically enabled.
To use this feature with a different arrangement, a listener must be explicitly added, as shown in the following example:
To use this feature with a different arrangement, listeners must be explicitly added, as shown in the following example:
[source,java,indent=0]
----
@TestExecutionListeners(MockitoTestExecutionListener.class)
@TestExecutionListeners({ MockitoTestExecutionListener.class, ResetMocksTestExecutionListener.class })
----
====

@ -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.
* <p>
* 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 {

@ -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 {

Loading…
Cancel
Save