Skip to content

Commit bd90d98

Browse files
committed
spring-projectsGH-2481: Global Embedded Broker and JUnit Platform
Resolves spring-projects#2481 The Maven Surefire plugin uses an older version of JUnit platform which is incompatible with the Global embedded broker. Check that the platform version is compatible before attempting to determine if a global embedded broker should be created. Tested with a Spring Boot application.
1 parent 0723add commit bd90d98

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

spring-kafka-test/src/main/java/org/springframework/kafka/test/junit/GlobalEmbeddedKafkaTestExecutionListener.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,27 @@ public class GlobalEmbeddedKafkaTestExecutionListener implements TestExecutionLi
8484
public static final String BROKER_PROPERTIES_LOCATION_PROPERTY_NAME =
8585
"spring.kafka.embedded.broker.properties.location";
8686

87+
private static final boolean JUNIT_PLATFORM_COMPATIBLE;
88+
89+
static {
90+
boolean compat = false;
91+
try {
92+
TestPlan.class.getDeclaredMethod("getConfigurationParameters");
93+
compat = true;
94+
}
95+
catch (NoSuchMethodException | SecurityException e) {
96+
LOGGER.debug("JUnit Platform version must be >= 1.8 to use a global embedded kafka server");
97+
}
98+
JUNIT_PLATFORM_COMPATIBLE = compat;
99+
}
100+
87101
private EmbeddedKafkaBroker embeddedKafkaBroker;
88102

89103
@Override
90104
public void testPlanExecutionStarted(TestPlan testPlan) {
105+
if (!JUNIT_PLATFORM_COMPATIBLE) {
106+
return;
107+
}
91108
ConfigurationParameters configurationParameters = testPlan.getConfigurationParameters();
92109
boolean enabled = configurationParameters.getBoolean(LISTENER_ENABLED_PROPERTY_NAME).orElse(false);
93110
if (enabled) {

0 commit comments

Comments
 (0)