Skip to content

Commit 5076a7e

Browse files
committed
Ensure compatibility with JUnit < 5.13
1 parent f120a90 commit 5076a7e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

hibernate-testing/src/main/java/org/hibernate/testing/bytecode/enhancement/extension/engine/BytecodeEnhancedTestEngine.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import static org.hibernate.testing.bytecode.enhancement.extension.engine.BytecodeEnhancedClassUtils.enhanceTestClass;
1212
import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation;
1313

14+
import java.lang.reflect.Constructor;
15+
import java.lang.reflect.InvocationTargetException;
1416
import java.lang.reflect.Method;
1517
import java.util.Arrays;
1618
import java.util.HashSet;
@@ -45,6 +47,7 @@
4547
import org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor;
4648
import org.junit.jupiter.engine.execution.JupiterEngineExecutionContext;
4749
import org.junit.platform.engine.EngineDiscoveryRequest;
50+
import org.junit.platform.engine.EngineExecutionListener;
4851
import org.junit.platform.engine.ExecutionRequest;
4952
import org.junit.platform.engine.TestDescriptor;
5053
import org.junit.platform.engine.UniqueId;
@@ -211,6 +214,15 @@ private Method findMethodReplacement(ClassTestDescriptor updated, Method testMet
211214

212215
@Override
213216
protected JupiterEngineExecutionContext createExecutionContext(ExecutionRequest request) {
217+
try {
218+
// Try constructing the JupiterEngineExecutionContext the way it was done in 5.12 and before
219+
final Constructor<JupiterEngineExecutionContext> constructorV5_12 = JupiterEngineExecutionContext.class
220+
.getConstructor( EngineExecutionListener.class, JupiterConfiguration.class );
221+
return constructorV5_12.newInstance( request.getEngineExecutionListener(), this.getJupiterConfiguration( request ) );
222+
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e ) {
223+
// Ignore errors as they are probably due to version mismatches and try the 5.13 way
224+
}
225+
214226
return new JupiterEngineExecutionContext(
215227
request.getEngineExecutionListener(),
216228
this.getJupiterConfiguration( request ),

0 commit comments

Comments
 (0)