Deprecate JUnit 4 support in the TestContext framework

Closes gh-34794
This commit is contained in:
Sam Brannen
2025-04-26 08:53:24 +02:00
parent 2db1a63a92
commit c74fc7ec90
61 changed files with 215 additions and 65 deletions

View File

@@ -31,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Sam Brannen
* @since 3.0
*/
@SuppressWarnings("deprecation")
class ProfileValueUtilsTests {
private static final String NON_ANNOTATED_METHOD = "nonAnnotatedMethod";
@@ -140,7 +141,6 @@ class ProfileValueUtilsTests {
@Test
void isTestEnabledInThisEnvironmentForProvidedProfileValueSourceMethodAndClass() throws Exception {
ProfileValueSource profileValueSource = SystemProfileValueSource.getInstance();
assertMethodIsEnabled(profileValueSource, NON_ANNOTATED_METHOD, NonAnnotated.class);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@@ -46,6 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
// Override the default loader configured by the CustomXmlBootstrapper
@ContextConfiguration(classes = BasicTestConfiguration.class, loader = AnnotationConfigContextLoader.class)
@TestPropertySource
@SuppressWarnings("deprecation")
public class BasicSpringVintageTests {
@Autowired

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2025 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,6 +41,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC
@ContextConfiguration(classes = WebTestConfiguration.class)
@WebAppConfiguration
@TestPropertySource(properties = "test.engine = vintage")
@SuppressWarnings("deprecation")
public class WebSpringVintageTests {
MockMvc mockMvc;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2025 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,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@ContextConfiguration("test-config.xml")
@TestPropertySource(properties = "test.engine = vintage")
@SuppressWarnings("deprecation")
public class XmlSpringVintageTests {
@Autowired

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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,6 +35,7 @@ import static org.assertj.core.api.Assertions.fail;
@TestExecutionListeners(ClassLevelDisabledSpringRunnerTests.CustomTestExecutionListener.class)
@IfProfileValue(name = "ClassLevelDisabledSpringRunnerTests.profile_value.name", value = "enigmaX")
@DisabledInAotMode("@IfProfileValue is not supported for AOT processing")
@SuppressWarnings("deprecation")
public class ClassLevelDisabledSpringRunnerTests {
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@@ -44,6 +44,7 @@ import static org.springframework.transaction.support.TransactionSynchronization
* @since 2.5
*/
@ContextConfiguration
@SuppressWarnings("deprecation")
public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTransactionalJUnit4SpringContextTests
implements BeanNameAware, InitializingBean {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -49,6 +49,7 @@ import static org.assertj.core.api.Assertions.fail;
@RunWith(SpringRunner.class)
@TestExecutionListeners({})
@DisabledInAotMode("Does not load an ApplicationContext and thus not supported for AOT processing")
@SuppressWarnings("deprecation")
public class EnabledAndIgnoredSpringRunnerTests {
protected static final String NAME = "EnabledAndIgnoredSpringRunnerTests.profile_value.name";

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2025 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,13 +28,14 @@ import org.springframework.test.context.TestExecutionListeners;
import static org.springframework.test.context.junit4.JUnitTestingUtils.runTestsAndAssertCounters;
/**
* Verifies proper handling of JUnit's {@link Test#expected() @Test(expected = ...)}
* Verifies proper handling of JUnit's {@link Test#expected() @Test(expected = ...)}
* support in conjunction with the {@link SpringRunner}.
*
* @author Sam Brannen
* @since 3.0
*/
@RunWith(JUnit4.class)
@SuppressWarnings("deprecation")
public class ExpectedExceptionSpringRunnerTests {
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@@ -50,6 +50,7 @@ import static org.springframework.test.context.junit4.JUnitTestingUtils.runTests
* @since 2.5
*/
@RunWith(Parameterized.class)
@SuppressWarnings("deprecation")
public class FailingBeforeAndAfterMethodsSpringRunnerTests {
protected final Class<?> clazz;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -38,6 +38,7 @@ import org.springframework.test.context.aot.DisabledInAotMode;
*/
@ProfileValueSourceConfiguration(HardCodedProfileValueSourceSpringRunnerTests.HardCodedProfileValueSource.class)
@DisabledInAotMode("Because EnabledAndIgnoredSpringRunnerTests is disabled in AOT mode")
@SuppressWarnings("deprecation")
public class HardCodedProfileValueSourceSpringRunnerTests extends EnabledAndIgnoredSpringRunnerTests {
@BeforeClass

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -47,6 +47,7 @@ import static org.springframework.test.context.junit4.JUnitTestingUtils.runTests
* @since 3.0
*/
@RunWith(Parameterized.class)
@SuppressWarnings("deprecation")
public class RepeatedSpringRunnerTests {
protected static final AtomicInteger invocationCount = new AtomicInteger();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@@ -38,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@TestExecutionListeners({})
@DisabledInAotMode("Does not load an ApplicationContext and thus not supported for AOT processing")
@SuppressWarnings("deprecation")
public class SpringJUnit47ClassRunnerRuleTests {
@Rule
@@ -53,4 +54,5 @@ public class SpringJUnit47ClassRunnerRuleTests {
public void testB() {
assertThat(name.getMethodName()).isEqualTo("testB");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -36,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThatException;
* @author Rick Evans
* @since 2.5
*/
@SuppressWarnings("deprecation")
public class SpringJUnit4ClassRunnerTests {
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@@ -22,15 +22,12 @@ import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.aot.DisabledInAotMode;
/**
* <p>
* Simple unit test to verify that {@link SpringRunner} does not
* hinder correct functionality of standard JUnit 4.4+ testing features.
* </p>
* <p>
* Note that {@link TestExecutionListeners @TestExecutionListeners} is
* Simple unit test to verify that the {@link SpringRunner} does not
* hinder correct functionality of standard JUnit 4 testing features.
*
* <p>Note that {@link TestExecutionListeners @TestExecutionListeners} is
* explicitly configured with an empty list, thus disabling all default
* listeners.
* </p>
*
* @author Sam Brannen
* @since 2.5
@@ -39,6 +36,7 @@ import org.springframework.test.context.aot.DisabledInAotMode;
@RunWith(SpringRunner.class)
@TestExecutionListeners({})
@DisabledInAotMode("Does not load an ApplicationContext and thus not supported for AOT processing")
@SuppressWarnings("deprecation")
public class StandardJUnit4FeaturesSpringRunnerTests extends StandardJUnit4FeaturesTests {
/* All tests are in the parent class... */

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2025 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.
@@ -43,6 +43,7 @@ import static org.springframework.test.context.junit4.JUnitTestingUtils.runTests
* @since 3.0
*/
@RunWith(JUnit4.class)
@SuppressWarnings("deprecation")
public class TimedSpringRunnerTests {
protected Class<?> getTestCase() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2025 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.
@@ -40,6 +40,7 @@ import static org.springframework.test.transaction.TransactionAssert.assertThatT
@RunWith(SpringRunner.class)
@ContextConfiguration("/org/springframework/test/context/transaction/transactionalTests-context.xml")
@Transactional
@SuppressWarnings("deprecation")
public class TimedTransactionalSpringRunnerTests {
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -44,6 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringRunner.class)
@RecordApplicationEvents
@SuppressWarnings("deprecation")
public class JUnit4ApplicationEventsAsyncIntegrationTests {
@Rule

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2025 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,6 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringRunner.class)
@RecordApplicationEvents
@SuppressWarnings("deprecation")
public class JUnit4ApplicationEventsIntegrationTests {
@Rule

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2025 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.
@@ -29,6 +29,7 @@ import org.springframework.test.context.junit4.rules.SpringMethodRule;
* @author Sam Brannen
* @since 5.0
*/
@SuppressWarnings("deprecation")
public abstract class SpringRuleConfigurer {
@ClassRule

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Sam Brannen
* @since 5.0
*/
@SuppressWarnings("deprecation")
public class AutowiredRuleSpr15927Tests {
@ClassRule

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2025 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,6 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @see Subclass2AppCtxRuleTests
*/
@ContextConfiguration
@SuppressWarnings("deprecation")
public class BaseAppCtxRuleTests {
@ClassRule

View File

@@ -41,6 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(JUnit4.class)
@ContextConfiguration
@SuppressWarnings("deprecation")
public class BasicAnnotationConfigWacSpringRuleTests extends AbstractBasicWacTests {
@ClassRule

View File

@@ -51,6 +51,7 @@ import static org.springframework.test.transaction.TransactionAssert.assertThatT
@RunWith(JUnit4.class)
@ContextConfiguration("/org/springframework/test/context/transaction/transactionalTests-context.xml")
@Transactional
@SuppressWarnings("deprecation")
public class BeforeAndAfterTransactionAnnotationSpringRuleTests {
private static final String JANE = "jane";

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2025 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.
@@ -32,6 +32,7 @@ import org.springframework.test.context.junit4.ClassLevelDisabledSpringRunnerTes
* @since 4.2
*/
@RunWith(JUnit4.class)
@SuppressWarnings("deprecation")
public class ClassLevelDisabledSpringRuleTests extends ClassLevelDisabledSpringRunnerTests {
@ClassRule

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2025 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.
@@ -32,6 +32,7 @@ import org.springframework.test.context.junit4.EnabledAndIgnoredSpringRunnerTest
* @since 4.2
*/
@RunWith(JUnit4.class)
@SuppressWarnings("deprecation")
public class EnabledAndIgnoredSpringRuleTests extends EnabledAndIgnoredSpringRunnerTests {
@ClassRule

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@@ -42,6 +42,7 @@ import static org.assertj.core.api.Assertions.fail;
* @author Sam Brannen
* @since 4.2
*/
@SuppressWarnings("deprecation")
public class FailingBeforeAndAfterMethodsSpringRuleTests extends FailingBeforeAndAfterMethodsSpringRunnerTests {
@Parameters(name = "{0}")

View File

@@ -35,6 +35,7 @@ import static org.mockito.Mockito.when;
* @author Sam Brannen
* @see <a href="https://github.com/spring-projects/spring-boot/issues/27693">gh-27693</a>
*/
@SuppressWarnings("deprecation")
public class MockitoBeanAndSpringMethodRuleWithRepeatJUnit4IntegrationTests {
private static int invocations;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@@ -47,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(Parameterized.class)
@ContextConfiguration("../ParameterizedDependencyInjectionTests-context.xml")
@SuppressWarnings("deprecation")
public class ParameterizedSpringRuleTests {
private static final AtomicInteger invocationCount = new AtomicInteger();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@@ -65,6 +65,7 @@ import static org.springframework.test.transaction.TransactionAssert.assertThatT
@RunWith(JUnit4.class)
@ContextConfiguration
@Transactional
@SuppressWarnings("deprecation")
public class ProgrammaticTxMgmtSpringRuleTests {
@ClassRule

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -40,6 +40,7 @@ import org.springframework.test.context.junit4.RepeatedSpringRunnerTests;
* @author Sam Brannen
* @since 4.2
*/
@SuppressWarnings("deprecation")
public class RepeatedSpringRuleTests extends RepeatedSpringRunnerTests {
@Parameters(name = "{0}")

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2025 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,6 +35,7 @@ import static org.assertj.core.api.Assertions.fail;
* @author Sam Brannen
* @since 4.2
*/
@SuppressWarnings("deprecation")
public class TimedSpringRuleTests extends TimedSpringRunnerTests {
// All tests are in superclass.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2025 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.
@@ -39,6 +39,7 @@ import static org.springframework.test.transaction.TransactionAssert.assertThatT
* @since 4.2
*/
@RunWith(JUnit4.class)
@SuppressWarnings("deprecation")
public class TimedTransactionalSpringRuleTests extends TimedTransactionalSpringRunnerTests {
@ClassRule

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2025 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.
@@ -50,6 +50,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Sql({ "../../jdbc/schema.sql", "../../jdbc/data.sql" })
@DirtiesContext
@SuppressWarnings("deprecation")
public class TransactionalSqlScriptsSpringRuleTests {
@ClassRule

View File

@@ -36,6 +36,7 @@ import static org.mockito.Mockito.mock;
* @author Sam Brannen
* @since 4.3.17
*/
@SuppressWarnings("deprecation")
public class SpringFailOnTimeoutTests {
private final Statement statement = mock();

View File

@@ -46,6 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@ContextConfiguration
@WebAppConfiguration
@SuppressWarnings("deprecation")
public class JUnit4SpringContextWebTests extends AbstractJUnit4SpringContextTests implements ServletContextAware {
@Configuration