diff --git a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/IntegrationTestFilter.java b/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/IntegrationTestFilter.java
index 4ff1ae3..e76b20a 100644
--- a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/IntegrationTestFilter.java
+++ b/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/IntegrationTestFilter.java
@@ -6,12 +6,9 @@
import java.util.ServiceLoader;
import java.util.Set;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.junit.runner.RunWith;
-import org.junit.runner.Runner;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.test.context.junit.jupiter.SpringExtension;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Integration Test class filter that should be ordered (as they use spring context). The logic of this class can be
@@ -56,10 +53,6 @@ protected boolean isIntegrationTest(Class> testClass) {
return true;
}
- if (JUnitPlatformSupport.isJunit4Present() && isIntegrationTestJUnit4(testClass)) {
- return true;
- }
-
//noinspection RedundantIfStatement
if (JUnitPlatformSupport.isJunit5JupiterApiPresent() && isIntegrationTestJUnit5Jupiter(testClass)) {
return true;
@@ -68,20 +61,6 @@ protected boolean isIntegrationTest(Class> testClass) {
return false;
}
- /**
- * This method should be only called if JUnit4 is on the classpath
- */
- protected boolean isIntegrationTestJUnit4(Class> testClass) {
- // can be inherited, but cannot be meta-annotation
- RunWith runWith = testClass.getAnnotation(RunWith.class);
- if (runWith == null) {
- return false;
- }
- Class extends Runner> runner = runWith.value();
- // includes org.springframework.test.context.junit4.SpringRunner
- return SpringJUnit4ClassRunner.class.isAssignableFrom(runner);
- }
-
/**
* This method should be only called if JUnit5 Jupiter API is on the classpath
*/
diff --git a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/JUnitPlatformSupport.java b/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/JUnitPlatformSupport.java
index 7ef9196..f74ef4c 100644
--- a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/JUnitPlatformSupport.java
+++ b/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/JUnitPlatformSupport.java
@@ -7,11 +7,6 @@
*/
final class JUnitPlatformSupport {
- @Deprecated
- private static final boolean JUNIT_VINTAGE_ENGINE_PRESENT = isClassPresent(
- "org.junit.vintage.engine.descriptor.RunnerTestDescriptor");
-
- @Deprecated
private static final boolean JUNIT4_PRESENT = isClassPresent(
"org.junit.runner.RunWith");
@@ -21,11 +16,6 @@ final class JUnitPlatformSupport {
private static final boolean JUNIT4_IDEA_TEST_RUNNER_PRESENT = isClassPresent(
"com.intellij.junit4.JUnit4IdeaTestRunner");
- @Deprecated
- static boolean isJUnitVintageEnginePresent() {
- return JUNIT_VINTAGE_ENGINE_PRESENT;
- }
-
@Deprecated
static boolean isJunit4Present() {
return JUNIT4_PRESENT;
@@ -35,11 +25,6 @@ static boolean isJunit5JupiterApiPresent() {
return JUNIT5_JUPITER_API_PRESENT;
}
- @Deprecated
- static boolean isJUnit4IdeaTestRunnerPresent() {
- return JUNIT4_IDEA_TEST_RUNNER_PRESENT;
- }
-
private static boolean isClassPresent(String className) {
return ClassUtils.isPresent(className, JUnitPlatformSupport.class.getClassLoader());
}
diff --git a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/SmartDirtiesContextTestExecutionListener.java b/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/SmartDirtiesContextTestExecutionListener.java
index 4915751..bcdf8cc 100644
--- a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/SmartDirtiesContextTestExecutionListener.java
+++ b/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/SmartDirtiesContextTestExecutionListener.java
@@ -12,7 +12,7 @@
* {@link org.springframework.test.context.support.DirtiesContextTestExecutionListener}. Based on known list (ordered)
* of tests to execute (reordered via {@link com.github.seregamorph.testsmartcontext.jupiter.SmartDirtiesClassOrderer}
* for Jupiter classes, {@link com.github.seregamorph.testsmartcontext.testng.SmartDirtiesSuiteListener} for TestNG
- * classes or {@link SmartDirtiesPostDiscoveryFilter} for JUnit 4 classes), the last test in each group that shares the
+ * classes, the last test in each group that shares the
* same configuration (=share the same spring context) will automatically close the ApplicationContext on after-class,
* which will release resources as well (like Docker containers defined as spring beans). See detailed explanation README.
diff --git a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/SmartDirtiesPostDiscoveryFilter.java b/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/SmartDirtiesPostDiscoveryFilter.java
deleted file mode 100644
index 2f62aa0..0000000
--- a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/SmartDirtiesPostDiscoveryFilter.java
+++ /dev/null
@@ -1,119 +0,0 @@
-package com.github.seregamorph.testsmartcontext;
-
-import static java.util.Collections.singletonList;
-
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-import org.junit.platform.engine.FilterResult;
-import org.junit.platform.engine.TestDescriptor;
-import org.junit.platform.launcher.PostDiscoveryFilter;
-import org.junit.vintage.engine.descriptor.RunnerTestDescriptor;
-import org.junit.vintage.engine.descriptor.VintageTestDescriptor;
-import org.springframework.lang.NonNull;
-import org.springframework.lang.Nullable;
-
-/**
- * Auto-discovered JUnit platform {@link PostDiscoveryFilter} which reorders and groups integration test classes
- * according to their configuration. Note: this class sorts only JUnit 4 tests executed via
- * vintage-engine.
- *
- * For TestNG test classes - see {@link com.github.seregamorph.testsmartcontext.testng.SmartDirtiesSuiteListener}, for
- * Jupiter test classes - see {@link com.github.seregamorph.testsmartcontext.jupiter.SmartDirtiesClassOrderer}.
- *
- * @author Sergey Chernov
- * @deprecated support of JUnit 4 will be removed in 1.0 release
- */
-@Deprecated
-public class SmartDirtiesPostDiscoveryFilter implements PostDiscoveryFilter {
-
- private static final String ENGINE = "junit-vintage";
-
- @Override
- public FilterResult apply(TestDescriptor testDescriptor) {
- List childrenToReorder = testDescriptor.getChildren().stream()
- .filter(childTestDescriptor -> {
- // If it is a testng-engine running TestNG test, rely on SmartDirtiesSuiteListener, because
- // TestNG will alphabetically reorder it first anyway.
- // Jupiter engine has its own sorting via SmartDirtiesClassOrderer, so skip them as well.
- // Reorder only JUnit4 here:
- return getTestClassOrNull(childTestDescriptor) != null;
- })
- .collect(Collectors.toList());
-
- if (childrenToReorder.isEmpty()) {
- return FilterResult.included("Empty list");
- }
-
- Set> uniqueClasses = childrenToReorder.stream()
- .map(SmartDirtiesPostDiscoveryFilter::getTestClass)
- .collect(Collectors.toSet());
- if (uniqueClasses.size() == 1) {
- // This filter is executed several times during discover and execute phases and
- // it's not possible to distinguish them here. Sometimes per single test is sent as argument,
- // sometimes - the whole suite. If it's a suite more than 1, we can save it and never update.
- // If it's 1 - we should also distinguish single test execution.
- if (SmartDirtiesTestsSupport.classOrderStateMapSize(ENGINE) <= 1) {
- Class> testClass = getTestClass(childrenToReorder.get(0));
- SmartDirtiesTestsSupport.setTestClassesLists(ENGINE, singletonList(singletonList(testClass)));
- }
-
- // the logic here may differ for JUnit 4 via Maven vs IntelliJ:
- // Maven calls this filter several times (first per each test, then with all tests)
- return FilterResult.included("Skipping single element");
- }
-
- childrenToReorder.forEach(testDescriptor::removeChild);
-
- SmartDirtiesTestsSorter sorter = SmartDirtiesTestsSorter.getInstance();
- List>> testClassesLists;
- try {
- testClassesLists = sorter.sort(childrenToReorder, SmartDirtiesPostDiscoveryFilter::getTestClass);
- } catch (Throwable e) {
- SmartDirtiesTestsSupport.setFailureCause(e);
- throw e;
- }
-
- childrenToReorder.forEach(testDescriptor::addChild);
-
- SmartDirtiesTestsSupport.setTestClassesLists(ENGINE, testClassesLists);
-
- return FilterResult.included("sorted");
- }
-
- @NonNull
- private static Class> getTestClass(TestDescriptor testDescriptor) {
- Class> testClass = getTestClassOrNull(testDescriptor);
- if (testClass == null) {
- throw new UnsupportedOperationException("Unsupported TestDescriptor type " + testDescriptor.getClass()
- + ", failed to obtain test class");
- }
- return testClass;
- }
-
- @SuppressWarnings("RedundantIfStatement")
- @Nullable
- private static Class> getTestClassOrNull(TestDescriptor testDescriptor) {
- if (JUnitPlatformSupport.isJUnitVintageEnginePresent()) {
- Class> testClass = getTestClassJUnitVintageEngine(testDescriptor);
- if (testClass != null) {
- return testClass;
- }
- }
-
- return null;
- }
-
- @Nullable
- private static Class> getTestClassJUnitVintageEngine(TestDescriptor testDescriptor) {
- if (testDescriptor instanceof RunnerTestDescriptor) {
- RunnerTestDescriptor runnerTestDescriptor = (RunnerTestDescriptor) testDescriptor;
- return runnerTestDescriptor.getDescription().getTestClass();
- }
- if (testDescriptor instanceof VintageTestDescriptor) {
- VintageTestDescriptor vintageTestDescriptor = (VintageTestDescriptor) testDescriptor;
- return vintageTestDescriptor.getDescription().getTestClass();
- }
- return null;
- }
-}
diff --git a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/SmartDirtiesTestsSupport.java b/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/SmartDirtiesTestsSupport.java
index 262473e..40c9123 100644
--- a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/SmartDirtiesTestsSupport.java
+++ b/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/SmartDirtiesTestsSupport.java
@@ -15,9 +15,12 @@
import java.util.Set;
import java.util.stream.Collectors;
import org.junit.jupiter.api.ClassOrderer;
+import org.junit.runner.RunWith;
+import org.junit.runner.Runner;
import org.springframework.lang.Nullable;
import org.springframework.test.context.BootstrapUtilsHelper;
import org.springframework.test.context.MergedContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* This class should only be used internally by the framework.
@@ -117,18 +120,9 @@ private static ClassOrderState getOrderState(Class> testClass) {
throw new UncheckedIOException(e);
}
}
- if (JUnitPlatformSupport.isJunit4Present() && JUnitPlatformSupport.isJUnit4IdeaTestRunnerPresent()) {
- System.err.println("The test is started via IDEA old JUnit 4 runner (not vintage), " +
- "the Smart DirtiesContext behaviour is disabled.");
- if (!JUnitPlatformSupport.isJunit5JupiterApiPresent()) {
- //@formatter:off
- System.err.println("If you add org.junit.jupiter:junit-jupiter-api test dependency, \n" +
- "it will allow to run packages/modules with tests with Smart DirtiesContext semantics via " +
- "IDEA. See \n" +
- "https://youtrack.jetbrains.com/issue/IDEA-343605/junit-vintage-engine-is-not-preferred-by-default\n" +
- "for details.");
- //@formatter:on
- }
+ if (JUnitPlatformSupport.isJunit4Present() && isIntegrationTestJUnit4(testClass)) {
+ System.err.println(testClass.getName() + " is a JUnit 4 test class, " +
+ "the Smart DirtiesContext behaviour is not supported. The last version supporting JUnit 4 is 0.9");
return null;
}
throw new IllegalStateException("engineClassOrderStateMap is not initialized", failureCause);
@@ -211,4 +205,15 @@ static Map, ClassOrderState>> setEngineClassOrderStateMap(
SmartDirtiesTestsSupport.engineClassOrderStateMap = engineClassOrderStateMap;
return prev;
}
+
+ private static boolean isIntegrationTestJUnit4(Class> testClass) {
+ // can be inherited, but cannot be meta-annotation
+ RunWith runWith = testClass.getAnnotation(RunWith.class);
+ if (runWith == null) {
+ return false;
+ }
+ Class extends Runner> runner = runWith.value();
+ // includes org.springframework.test.context.junit4.SpringRunner
+ return SpringJUnit4ClassRunner.class.isAssignableFrom(runner);
+ }
}
diff --git a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/junit4/AbstractJUnit4SpringIntegrationTest.java b/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/junit4/AbstractJUnit4SpringIntegrationTest.java
deleted file mode 100644
index 0bb9b46..0000000
--- a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/junit4/AbstractJUnit4SpringIntegrationTest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.github.seregamorph.testsmartcontext.junit4;
-
-import com.github.seregamorph.testsmartcontext.SmartDirtiesContextTestExecutionListener;
-import org.springframework.test.context.TestExecutionListeners;
-import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
-
-/**
- * Base class for JUnit 4 integration tests that create spring context. Supports
- * {@link SmartDirtiesContextTestExecutionListener} semantics to optimize IT suite execution.
- *
- * @author Sergey Chernov
- * @see SmartDirtiesContextTestExecutionListener
- * @deprecated support of JUnit 4 will be removed in 1.0 release
- */
-@Deprecated
-@TestExecutionListeners(listeners = {
- SmartDirtiesContextTestExecutionListener.class,
-}, mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
-public abstract class AbstractJUnit4SpringIntegrationTest extends AbstractJUnit4SpringContextTests {
-
-}
diff --git a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/jupiter/SmartDirtiesClassOrderer.java b/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/jupiter/SmartDirtiesClassOrderer.java
index 816df94..97eeab5 100644
--- a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/jupiter/SmartDirtiesClassOrderer.java
+++ b/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/jupiter/SmartDirtiesClassOrderer.java
@@ -18,8 +18,7 @@
* configuration. Also stores information about last integration class per configuration, which is used by
* {@link com.github.seregamorph.testsmartcontext.SmartDirtiesContextTestExecutionListener}.
*
- * For TestNG test classes - see {@link com.github.seregamorph.testsmartcontext.testng.SmartDirtiesSuiteListener}, for
- * JUnit 4 test classes - see {@link com.github.seregamorph.testsmartcontext.SmartDirtiesPostDiscoveryFilter}.
+ * For TestNG test classes - see {@link com.github.seregamorph.testsmartcontext.testng.SmartDirtiesSuiteListener}.
*
* @author Sergey Chernov
*/
diff --git a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/testng/SmartDirtiesSuiteListener.java b/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/testng/SmartDirtiesSuiteListener.java
index 6f6e1b5..f6654b4 100644
--- a/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/testng/SmartDirtiesSuiteListener.java
+++ b/spring-test-smart-context/src/main/java/com/github/seregamorph/testsmartcontext/testng/SmartDirtiesSuiteListener.java
@@ -17,8 +17,7 @@
* Reorders TestNG test classes in suite grouping ITs with the same context configuration to minimize number of parallel
* existing contexts.
*
- * For Jupiter test classes - see {@link com.github.seregamorph.testsmartcontext.jupiter.SmartDirtiesClassOrderer}, for
- * JUnit 4 test classes - see {@link com.github.seregamorph.testsmartcontext.SmartDirtiesPostDiscoveryFilter}.
+ * For Jupiter test classes - see {@link com.github.seregamorph.testsmartcontext.jupiter.SmartDirtiesClassOrderer}.
*
* @author Sergey Chernov
*/
diff --git a/spring-test-smart-context/src/main/resources/META-INF/services/org.junit.platform.launcher.PostDiscoveryFilter b/spring-test-smart-context/src/main/resources/META-INF/services/org.junit.platform.launcher.PostDiscoveryFilter
deleted file mode 100644
index 5b913ee..0000000
--- a/spring-test-smart-context/src/main/resources/META-INF/services/org.junit.platform.launcher.PostDiscoveryFilter
+++ /dev/null
@@ -1 +0,0 @@
-com.github.seregamorph.testsmartcontext.SmartDirtiesPostDiscoveryFilter