Polishing javadoc
This commit is contained in:
@@ -29,11 +29,11 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Reset strategy used on a mock bean. Usually applied to a mock through the
|
||||
* {@link MockitoBean @MockitoBean} annotation but can also be directly applied to any mock in
|
||||
* the {@code ApplicationContext} using the static methods.
|
||||
* {@link MockitoBean @MockitoBean} annotation but can also be directly applied
|
||||
* to any mock in the {@code ApplicationContext} using the static methods.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 1.4.0
|
||||
* @since 6.2
|
||||
* @see MockitoResetTestExecutionListener
|
||||
*/
|
||||
public enum MockReset {
|
||||
@@ -54,8 +54,8 @@ public enum MockReset {
|
||||
NONE;
|
||||
|
||||
/**
|
||||
* Create {@link MockSettings settings} to be used with mocks where reset should occur
|
||||
* before each test method runs.
|
||||
* Create {@link MockSettings settings} to be used with mocks where reset
|
||||
* should occur before each test method runs.
|
||||
* @return mock settings
|
||||
*/
|
||||
public static MockSettings before() {
|
||||
@@ -63,8 +63,8 @@ public enum MockReset {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create {@link MockSettings settings} to be used with mocks where reset should occur
|
||||
* after each test method runs.
|
||||
* Create {@link MockSettings settings} to be used with mocks where reset
|
||||
* should occur after each test method runs.
|
||||
* @return mock settings
|
||||
*/
|
||||
public static MockSettings after() {
|
||||
@@ -72,8 +72,8 @@ public enum MockReset {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create {@link MockSettings settings} to be used with mocks where a specific reset
|
||||
* should occur.
|
||||
* Create {@link MockSettings settings} to be used with mocks where a
|
||||
* specific reset should occur.
|
||||
* @param reset the reset type
|
||||
* @return mock settings
|
||||
*/
|
||||
|
||||
@@ -31,9 +31,7 @@ import org.springframework.test.bean.override.BeanOverride;
|
||||
* Mark a field to trigger a bean override using a Mockito mock. If no explicit
|
||||
* {@link #name()} is specified, the annotated field's name is interpreted to
|
||||
* be the target of the override. In either case, if no existing bean is defined
|
||||
* a new one will be added to the context. In order to ensure mocks are set up
|
||||
* and reset correctly, the test class must itself be annotated with
|
||||
* {@link MockitoBeanOverrideTestListeners}.
|
||||
* a new one will be added to the context.
|
||||
*
|
||||
* <p>Dependencies that are known to the application context but are not beans
|
||||
* (such as those {@link org.springframework.beans.factory.config.ConfigurableListableBeanFactory#registerResolvableDependency(Class, Object)
|
||||
@@ -57,8 +55,8 @@ public @interface MockitoBean {
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* Any extra interfaces that should also be declared on the mock. See
|
||||
* {@link MockSettings#extraInterfaces(Class...)} for details.
|
||||
* Any extra interfaces that should also be declared on the mock.
|
||||
* See {@link MockSettings#extraInterfaces(Class...)} for details.
|
||||
* @return any extra interfaces
|
||||
*/
|
||||
Class<?>[] extraInterfaces() default {};
|
||||
@@ -70,15 +68,16 @@ public @interface MockitoBean {
|
||||
Answers answers() default Answers.RETURNS_DEFAULTS;
|
||||
|
||||
/**
|
||||
* If the generated mock is serializable. See {@link MockSettings#serializable()} for
|
||||
* details.
|
||||
* If the generated mock is serializable.
|
||||
* See {@link MockSettings#serializable()} for details.
|
||||
* @return if the mock is serializable
|
||||
*/
|
||||
boolean serializable() default false;
|
||||
|
||||
/**
|
||||
* The reset mode to apply to the mock bean. The default is {@link MockReset#AFTER}
|
||||
* meaning that mocks are automatically reset after each test method is invoked.
|
||||
* The reset mode to apply to the mock bean.
|
||||
* The default is {@link MockReset#AFTER} meaning that mocks are
|
||||
* automatically reset after each test method is invoked.
|
||||
* @return the reset mode
|
||||
*/
|
||||
MockReset reset() default MockReset.AFTER;
|
||||
|
||||
@@ -23,8 +23,16 @@ import org.springframework.core.ResolvableType;
|
||||
import org.springframework.test.bean.override.BeanOverrideProcessor;
|
||||
import org.springframework.test.bean.override.OverrideMetadata;
|
||||
|
||||
/**
|
||||
* A {@link BeanOverrideProcessor} for mockito-related annotations
|
||||
* ({@link MockitoBean} and {@link MockitoSpyBean}).
|
||||
*
|
||||
* @author Simon Baslé
|
||||
* @since 6.2
|
||||
*/
|
||||
public class MockitoBeanOverrideProcessor implements BeanOverrideProcessor {
|
||||
|
||||
@Override
|
||||
public OverrideMetadata createMetadata(Field field, Annotation overrideAnnotation, ResolvableType typeToMock) {
|
||||
if (overrideAnnotation instanceof MockitoBean mockBean) {
|
||||
return new MockDefinition(mockBean, field, typeToMock);
|
||||
|
||||
@@ -36,8 +36,8 @@ import org.springframework.test.context.TestExecutionListener;
|
||||
import org.springframework.test.context.support.AbstractTestExecutionListener;
|
||||
|
||||
/**
|
||||
* {@link TestExecutionListener} to reset any mock beans that have been marked with a
|
||||
* {@link MockReset}. Typically used alongside {@link MockitoTestExecutionListener}.
|
||||
* {@link TestExecutionListener} to reset any mock beans that have been marked
|
||||
* with a {@link MockReset}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 6.2
|
||||
|
||||
@@ -26,22 +26,12 @@ import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.test.bean.override.BeanOverride;
|
||||
|
||||
/**
|
||||
* Mark a field to trigger the override of the bean of the same name with a
|
||||
* Mockito spy, which will wrap the original instance.
|
||||
* In order to ensure mocks are set up and reset correctly, the test class must
|
||||
* itself be annotated with {@link MockitoBeanOverrideTestListeners}.
|
||||
*
|
||||
* @author Simon Baslé
|
||||
* @since 6.2
|
||||
*/
|
||||
/**
|
||||
* Mark a field to trigger a bean override using a Mockito spy, which will wrap
|
||||
* the original instance. If no explicit {@link #name()} is specified, the
|
||||
* annotated field's name is interpreted to be the target of the override.
|
||||
* In either case, it is required that the target bean is previously registered
|
||||
* in the context. In order to ensure spies are set up and reset correctly,
|
||||
* the test class must itself be annotated with {@link MockitoBeanOverrideTestListeners}.
|
||||
* in the context.
|
||||
*
|
||||
* <p>Dependencies that are known to the application context but are not beans
|
||||
* (such as those {@link org.springframework.beans.factory.config.ConfigurableListableBeanFactory#registerResolvableDependency(Class, Object)
|
||||
@@ -64,20 +54,22 @@ public @interface MockitoSpyBean {
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* The reset mode to apply to the spied bean. The default is {@link MockReset#AFTER}
|
||||
* meaning that spies are automatically reset after each test method is invoked.
|
||||
* The reset mode to apply to the spied bean. The default is
|
||||
* {@link MockReset#AFTER} meaning that spies are automatically reset after
|
||||
* each test method is invoked.
|
||||
* @return the reset mode
|
||||
*/
|
||||
MockReset reset() default MockReset.AFTER;
|
||||
|
||||
/**
|
||||
* Indicates that Mockito methods such as {@link Mockito#verify(Object) verify(mock)}
|
||||
* should use the {@code target} of AOP advised beans, rather than the proxy itself.
|
||||
* Indicates that Mockito methods such as {@link Mockito#verify(Object)
|
||||
* verify(mock)} should use the {@code target} of AOP advised beans,
|
||||
* rather than the proxy itself.
|
||||
* If set to {@code false} you may need to use the result of
|
||||
* {@link org.springframework.test.util.AopTestUtils#getUltimateTargetObject(Object)
|
||||
* AopTestUtils.getUltimateTargetObject(...)} when calling Mockito methods.
|
||||
* @return {@code true} if the target of AOP advised beans is used or {@code false} if
|
||||
* the proxy is used directly
|
||||
* @return {@code true} if the target of AOP advised beans is used or
|
||||
* {@code false} if the proxy is used directly
|
||||
*/
|
||||
boolean proxyTargetAware() default true;
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ import org.springframework.util.ReflectionUtils.FieldCallback;
|
||||
/**
|
||||
* {@link TestExecutionListener} to enable {@link MockitoBean @MockitoBean} and
|
||||
* {@link MockitoSpyBean @MockitoSpyBean} support. Also triggers
|
||||
* {@link MockitoAnnotations#openMocks(Object)} when any Mockito annotations used,
|
||||
* primarily to allow {@link Captor @Captor} annotations.
|
||||
* {@link MockitoAnnotations#openMocks(Object)} when any Mockito annotations are
|
||||
* used, primarily to allow {@link Captor @Captor} annotations.
|
||||
* <p>
|
||||
* The automatic reset support of {@code @MockBean} and {@code @SpyBean} is
|
||||
* handled by sibling {@link MockitoResetTestExecutionListener}.
|
||||
|
||||
@@ -130,8 +130,8 @@ class SpyDefinition extends Definition {
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link VerificationStartedListener} that bypasses any proxy created by Spring AOP
|
||||
* when the verification of a spy starts.
|
||||
* A {@link VerificationStartedListener} that bypasses any proxy created by
|
||||
* Spring AOP when the verification of a spy starts.
|
||||
*/
|
||||
private static final class SpringAopBypassingVerificationStartedListener implements VerificationStartedListener {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Support case-by-case Bean overriding in Spring tests.
|
||||
* Bean overriding mechanism based on Mockito mocking and spying.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
|
||||
Reference in New Issue
Block a user