Skip to content

Commit 515bb13

Browse files
committed
Ensure compatibility with JUnit < 5.13
1 parent b94f633 commit 515bb13

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;
@@ -46,6 +48,7 @@
4648
import org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor;
4749
import org.junit.jupiter.engine.execution.JupiterEngineExecutionContext;
4850
import org.junit.platform.engine.EngineDiscoveryRequest;
51+
import org.junit.platform.engine.EngineExecutionListener;
4952
import org.junit.platform.engine.ExecutionRequest;
5053
import org.junit.platform.engine.TestDescriptor;
5154
import org.junit.platform.engine.UniqueId;
@@ -216,6 +219,15 @@ private Method findMethodReplacement(ClassTestDescriptor updated, Method testMet
216219

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

0 commit comments

Comments
 (0)