Polish "Deprecate @MockBean and @SpyBean"

See gh-39864
This commit is contained in:
Andy Wilkinson
2024-07-12 13:22:28 +01:00
parent 24763940a0
commit cddf92e047
122 changed files with 328 additions and 475 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2024 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.
@@ -23,9 +23,9 @@ import org.springframework.util.ObjectUtils;
*
* @author Phillip Webb
* @see DefinitionsParser
* @deprecated since 3.4.0. See {@link SpyBean} and {@link MockBean} for more details.
*/
@Deprecated(since = "3.4.0")
@SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
abstract class Definition {
private static final int MULTIPLIER = 31;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
@@ -41,10 +41,9 @@ import org.springframework.util.StringUtils;
*
* @author Phillip Webb
* @author Stephane Nicoll
* @deprecated since 3.4.0. See {@link SpyBean} and {@link MockBean} for more details.
*/
@Deprecated(since = "3.4.0")
@SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
class DefinitionsParser {
private final Set<Definition> definitions;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 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.
@@ -91,14 +91,15 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Phillip Webb
* @since 1.4.0
* @see MockitoPostProcessor
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.mockito.MockitoBean}
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of
* {@link org.springframework.test.context.bean.override.mockito.MockitoBean}
*/
@SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
@Target({ ElementType.TYPE, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Repeatable(MockBeans.class)
@Deprecated(since = "3.4.0")
public @interface MockBean {
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2024 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.
@@ -33,13 +33,14 @@ import java.lang.annotation.Target;
*
* @author Phillip Webb
* @since 1.4.0
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.mockito.MockitoBean}
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of
* {@link org.springframework.test.context.bean.override.mockito.MockitoBean}
*/
@SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Deprecated(since = "3.4.0")
public @interface MockBeans {
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
@@ -37,9 +37,9 @@ import static org.mockito.Mockito.mock;
* A complete definition that can be used to create a Mockito mock.
*
* @author Phillip Webb
* @deprecated since 3.4.0. See {@link MockBean} for more details.
*/
@Deprecated(since = "3.4.0")
@SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
class MockDefinition extends Definition {
private static final int MULTIPLIER = 31;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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,11 +35,11 @@ import org.springframework.util.Assert;
* @author Phillip Webb
* @since 1.4.0
* @see ResetMocksTestExecutionListener
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.mockito.MockReset}
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of
* {@link org.springframework.test.context.bean.override.mockito.MockReset}
*/
@Deprecated(since = "3.4.0")
@Deprecated(since = "3.4.0", forRemoval = true)
public enum MockReset {
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2024 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.
@@ -24,9 +24,7 @@ import java.util.List;
* Beans created using Mockito.
*
* @author Andy Wilkinson
* @deprecated since 3.4.0. See {@link MockBean} for more details.
*/
@Deprecated(since = "3.4.0")
class MockitoBeans implements Iterable<Object> {
private final List<Object> beans = new ArrayList<>();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 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.
@@ -28,10 +28,9 @@ import org.springframework.test.context.MergedContextConfiguration;
* A {@link ContextCustomizer} to add Mockito support.
*
* @author Phillip Webb
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.BeanOverrideContextCustomizerFactory}
*/
@Deprecated(since = "3.4.0")
@SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
class MockitoContextCustomizer implements ContextCustomizer {
private final Set<Definition> definitions;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2024 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.
@@ -27,10 +27,9 @@ import org.springframework.test.context.TestContextAnnotationUtils;
* A {@link ContextCustomizerFactory} to add Mockito support.
*
* @author Phillip Webb
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.BeanOverrideContextCustomizerFactory}
*/
@Deprecated(since = "3.4.0")
@SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
class MockitoContextCustomizerFactory implements ContextCustomizerFactory {
@Override

View File

@@ -57,6 +57,8 @@ import org.springframework.core.Conventions;
import org.springframework.core.Ordered;
import org.springframework.core.PriorityOrdered;
import org.springframework.core.ResolvableType;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -76,9 +78,10 @@ import org.springframework.util.StringUtils;
* @author Stephane Nicoll
* @author Andreas Neiser
* @since 1.4.0
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.BeanOverrideBeanPostProcessor}
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of Spring Framework's
* {@link MockitoBean} and {@link MockitoSpyBean} support
*/
@SuppressWarnings("removal")
@Deprecated(since = "3.4.0")
public class MockitoPostProcessor implements InstantiationAwareBeanPostProcessor, BeanClassLoaderAware,
BeanFactoryAware, BeanFactoryPostProcessor, Ordered {
@@ -423,7 +426,7 @@ public class MockitoPostProcessor implements InstantiationAwareBeanPostProcessor
RootBeanDefinition definition = new RootBeanDefinition(postProcessor);
definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
ConstructorArgumentValues constructorArguments = definition.getConstructorArgumentValues();
constructorArguments.addIndexedArgumentValue(0, new LinkedHashSet<MockDefinition>());
constructorArguments.addIndexedArgumentValue(0, new LinkedHashSet<>());
registry.registerBeanDefinition(BEAN_NAME, definition);
return definition;
}

View File

@@ -37,11 +37,11 @@ import org.springframework.util.ReflectionUtils;
* @author Moritz Halbritter
* @since 1.4.2
* @see ResetMocksTestExecutionListener
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.mockito.MockitoTestExecutionListener}
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of
* {@link org.springframework.test.context.bean.override.mockito.MockitoTestExecutionListener}
*/
@Deprecated(since = "3.4.0")
@SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
public class MockitoTestExecutionListener extends AbstractTestExecutionListener {
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 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.
@@ -34,10 +34,9 @@ import org.springframework.core.annotation.MergedAnnotations;
* @author Phillip Webb
* @author Stephane Nicoll
* @see Definition
* @deprecated since 3.4.0. See {@link SpyBean} and {@link MockBean} for more details.
*/
@Deprecated(since = "3.4.0")
@SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
class QualifierDefinition {
private final Field field;

View File

@@ -43,10 +43,11 @@ import org.springframework.util.ClassUtils;
* @author Phillip Webb
* @since 1.4.0
* @see MockitoTestExecutionListener
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.mockito.MockitoResetTestExecutionListener}
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of
* {@link org.springframework.test.context.bean.override.mockito.MockitoResetTestExecutionListener}
*/
@Deprecated(since = "3.4.0")
@SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
public class ResetMocksTestExecutionListener extends AbstractTestExecutionListener {
private static final boolean MOCKITO_IS_PRESENT = ClassUtils.isPresent("org.mockito.MockSettings",

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
@@ -21,6 +21,8 @@ import org.mockito.plugins.MockResolver;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
import org.springframework.util.Assert;
/**
@@ -29,7 +31,10 @@ import org.springframework.util.Assert;
*
* @author Andy Wilkinson
* @since 2.4.0
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of Spring Framework's
* {@link MockitoBean} and {@link MockitoSpyBean}
*/
@Deprecated(since = "3.4.0", forRemoval = true)
public class SpringBootMockResolver implements MockResolver {
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 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.
@@ -89,10 +89,11 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Phillip Webb
* @since 1.4.0
* @see MockitoPostProcessor
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.mockito.MockitoSpyBean}
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of
* {@link org.springframework.test.context.bean.override.mockito.MockitoSpyBean}
*/
@Deprecated(since = "3.4.0")
@SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
@Target({ ElementType.TYPE, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2024 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.
@@ -33,13 +33,14 @@ import java.lang.annotation.Target;
*
* @author Phillip Webb
* @since 1.4.0
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.mockito.MockitoSpyBean}
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of
* {@link org.springframework.test.context.bean.override.mockito.MockitoSpyBean}
*/
@SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Deprecated(since = "3.4.0")
public @interface SpyBeans {
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
@@ -37,10 +37,9 @@ import static org.mockito.Mockito.mock;
* A complete definition that can be used to create a Mockito spy.
*
* @author Phillip Webb
* @deprecated since 3.4.0. See {@link SpyBean} for more details.
*/
@Deprecated(since = "3.4.0")
@SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
class SpyDefinition extends Definition {
private static final int MULTIPLIER = 31;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2024 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.
@@ -16,5 +16,8 @@
/**
* Mockito integration for Spring Boot tests.
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of Spring Framework's
* {@link org.springframework.test.context.bean.override.mockito.MockitoBean} and
* {@link org.springframework.test.context.bean.override.mockito.MockitoSpyBean}
*/
package org.springframework.boot.test.mock.mockito;