Skip to content

Commit 06ae4aa

Browse files
committed
Ensure compatibility with JUnit < 5.13
1 parent 5d3a885 commit 06ae4aa

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
@@ -9,6 +9,8 @@
99
import static org.hibernate.testing.bytecode.enhancement.extension.engine.BytecodeEnhancedClassUtils.enhanceTestClass;
1010
import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation;
1111

12+
import java.lang.reflect.Constructor;
13+
import java.lang.reflect.InvocationTargetException;
1214
import java.lang.reflect.Method;
1315
import java.util.Arrays;
1416
import java.util.HashSet;
@@ -44,6 +46,7 @@
4446
import org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor;
4547
import org.junit.jupiter.engine.execution.JupiterEngineExecutionContext;
4648
import org.junit.platform.engine.EngineDiscoveryRequest;
49+
import org.junit.platform.engine.EngineExecutionListener;
4750
import org.junit.platform.engine.ExecutionRequest;
4851
import org.junit.platform.engine.TestDescriptor;
4952
import org.junit.platform.engine.UniqueId;
@@ -214,6 +217,15 @@ private Method findMethodReplacement(ClassTestDescriptor updated, Method testMet
214217

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

0 commit comments

Comments
 (0)