Deprecate @MockBean and @SpyBean
- Deprecate Deprecate @MockBean and @SpyBean in favor of Spring Framework 6.2's @MockitoBean and @MockitoSpy - Migrate usages of @MockBean and @SpyBean to @MockitoBean and @MockitoSpy Signed-off-by: Jakob Wanger <jakobwanger@gmail.com> See gh-39864
This commit is contained in:
committed by
Andy Wilkinson
parent
acdaa6dc35
commit
24763940a0
@@ -23,7 +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")
|
||||
abstract class Definition {
|
||||
|
||||
private static final int MULTIPLIER = 31;
|
||||
|
||||
@@ -41,7 +41,10 @@ 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")
|
||||
class DefinitionsParser {
|
||||
|
||||
private final Set<Definition> definitions;
|
||||
|
||||
@@ -91,11 +91,14 @@ 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}
|
||||
*/
|
||||
@Target({ ElementType.TYPE, ElementType.FIELD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Repeatable(MockBeans.class)
|
||||
@Deprecated(since = "3.4.0")
|
||||
public @interface MockBean {
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,10 +33,13 @@ 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}
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@Documented
|
||||
@Deprecated(since = "3.4.0")
|
||||
public @interface MockBeans {
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +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")
|
||||
class MockDefinition extends Definition {
|
||||
|
||||
private static final int MULTIPLIER = 31;
|
||||
|
||||
@@ -35,7 +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")
|
||||
public enum MockReset {
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,9 @@ 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<>();
|
||||
|
||||
@@ -28,7 +28,10 @@ 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")
|
||||
class MockitoContextCustomizer implements ContextCustomizer {
|
||||
|
||||
private final Set<Definition> definitions;
|
||||
|
||||
@@ -27,7 +27,10 @@ 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")
|
||||
class MockitoContextCustomizerFactory implements ContextCustomizerFactory {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -76,7 +76,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")
|
||||
public class MockitoPostProcessor implements InstantiationAwareBeanPostProcessor, BeanClassLoaderAware,
|
||||
BeanFactoryAware, BeanFactoryPostProcessor, Ordered {
|
||||
|
||||
|
||||
@@ -37,7 +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")
|
||||
public class MockitoTestExecutionListener extends AbstractTestExecutionListener {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,7 +34,10 @@ 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")
|
||||
class QualifierDefinition {
|
||||
|
||||
private final Field field;
|
||||
|
||||
@@ -43,7 +43,10 @@ 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")
|
||||
public class ResetMocksTestExecutionListener extends AbstractTestExecutionListener {
|
||||
|
||||
private static final boolean MOCKITO_IS_PRESENT = ClassUtils.isPresent("org.mockito.MockSettings",
|
||||
|
||||
@@ -89,7 +89,10 @@ 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")
|
||||
@Target({ ElementType.TYPE, ElementType.FIELD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
|
||||
@@ -33,10 +33,13 @@ 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}
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@Documented
|
||||
@Deprecated(since = "3.4.0")
|
||||
public @interface SpyBeans {
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,10 @@ 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")
|
||||
class SpyDefinition extends Definition {
|
||||
|
||||
private static final int MULTIPLIER = 31;
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.boot.test.context.nestedtests.InheritedNestedTestConf
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.test.bean.override.mockito.MockitoBean;
|
||||
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -41,7 +42,7 @@ import static org.mockito.Mockito.times;
|
||||
@Import(ActionPerformer.class)
|
||||
class InheritedNestedTestConfigurationTests {
|
||||
|
||||
@MockBean
|
||||
@MockitoBean
|
||||
Action action;
|
||||
|
||||
@Autowired
|
||||
|
||||
Reference in New Issue
Block a user