Skip to content

Ensure compatibility with JUnit < 5.13 #10576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 6.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gradle/java-module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ dependencies {

testImplementation testLibs.byteman

testRuntimeOnly testLibs.junit5Launcher
testRuntimeOnly testLibs.log4j2
testRuntimeOnly libs.byteBuddy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Blob;
Expand All @@ -40,9 +41,9 @@ protected Class<?>[] getAnnotatedClasses() {

@Test
@Priority(10)
public void testGenerateProxyNoStream() {
public void testGenerateProxyNoStream() throws URISyntaxException {
final Path path = Path.of( Thread.currentThread().getContextClassLoader()
.getResource( "org/hibernate/orm/test/envers/integration/blob/blob.txt" ).getPath() );
.getResource( "org/hibernate/orm/test/envers/integration/blob/blob.txt" ).toURI() );
doInJPA( this::entityManagerFactory, entityManager -> {
final Asset asset = new Asset();
asset.setFileName( "blob.txt" );
Expand Down Expand Up @@ -84,9 +85,9 @@ public void testGenerateProxyNoStream() {
comment = "The driver closes the stream, so it cannot be reused by envers")
@SkipForDialect(value = SybaseDialect.class,
comment = "The driver closes the stream, so it cannot be reused by envers")
public void testGenerateProxyStream() {
public void testGenerateProxyStream() throws URISyntaxException {
final Path path = Path.of( Thread.currentThread().getContextClassLoader()
.getResource( "org/hibernate/orm/test/envers/integration/blob/blob.txt" ).getPath() );
.getResource( "org/hibernate/orm/test/envers/integration/blob/blob.txt" ).toURI() );

try (final InputStream stream = new BufferedInputStream( Files.newInputStream( path ) )) {
doInJPA( this::entityManagerFactory, entityManager -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import static org.hibernate.testing.bytecode.enhancement.extension.engine.BytecodeEnhancedClassUtils.enhanceTestClass;
import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashSet;
Expand All @@ -24,14 +26,15 @@
import java.util.function.Supplier;

import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.ClassOrderer;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.Extension;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestInstantiationAwareExtension;
import org.junit.jupiter.api.io.CleanupMode;
import org.junit.jupiter.api.io.TempDirFactory;
import org.junit.jupiter.api.parallel.ExecutionMode;
Expand All @@ -40,13 +43,16 @@
import org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor;
import org.junit.jupiter.engine.descriptor.ClassTestDescriptor;
import org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor;
import org.junit.jupiter.engine.descriptor.LauncherStoreFacade;
import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor;
import org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor;
import org.junit.jupiter.engine.execution.JupiterEngineExecutionContext;
import org.junit.platform.engine.EngineDiscoveryRequest;
import org.junit.platform.engine.EngineExecutionListener;
import org.junit.platform.engine.ExecutionRequest;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.reporting.OutputDirectoryProvider;
import org.junit.platform.engine.support.hierarchical.EngineExecutionContext;
import org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine;
import org.junit.platform.engine.support.hierarchical.ThrowableCollector;
Expand Down Expand Up @@ -126,6 +132,7 @@ private void addEnhancementCheck(boolean enhance, String[] testEnhancedClasses,
descriptor.getTestClass().getName()
),
descriptor.getTestClass(),
descriptor::getEnclosingTestClasses,
jc,
enhance,
testEnhancedClasses
Expand Down Expand Up @@ -161,6 +168,7 @@ private void replaceWithEnhanced(Class<?> enhanced, ClassBasedTestDescriptor des
convertUniqueId( child.getUniqueId(), enhancementContextId ),
updated.getTestClass(),
findMethodReplacement( updated, testMethod ),
updated::getEnclosingTestClasses,
configuration
)
);
Expand All @@ -172,6 +180,7 @@ private void replaceWithEnhanced(Class<?> enhanced, ClassBasedTestDescriptor des
convertUniqueId( child.getUniqueId(), enhancementContextId ),
updated.getTestClass(),
findMethodReplacement( updated, testMethod ),
updated::getEnclosingTestClasses,
configuration
) );
}
Expand Down Expand Up @@ -210,9 +219,20 @@ private Method findMethodReplacement(ClassTestDescriptor updated, Method testMet

@Override
protected JupiterEngineExecutionContext createExecutionContext(ExecutionRequest request) {
try {
// Try constructing the JupiterEngineExecutionContext the way it was done in 5.12 and before
final Constructor<JupiterEngineExecutionContext> constructorV5_12 = JupiterEngineExecutionContext.class
.getConstructor( EngineExecutionListener.class, JupiterConfiguration.class );
return constructorV5_12.newInstance( request.getEngineExecutionListener(), this.getJupiterConfiguration( request ) );
}
catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
// Ignore errors as they are probably due to version mismatches and try the 5.13 way
}

return new JupiterEngineExecutionContext(
request.getEngineExecutionListener(),
this.getJupiterConfiguration( request )
this.getJupiterConfiguration( request ),
new LauncherStoreFacade( request.getStore() )
);
}

Expand Down Expand Up @@ -249,6 +269,11 @@ private DelegatingJupiterConfiguration(JupiterConfiguration configuration, Objec
);
}

@Override
public Predicate<Class<? extends Extension>> getFilterForAutoDetectedExtensions() {
return configuration.getFilterForAutoDetectedExtensions();
}

@Override
public Optional<String> getRawConfigurationParameter(String s) {
return configuration.getRawConfigurationParameter( s );
Expand All @@ -264,11 +289,21 @@ public boolean isParallelExecutionEnabled() {
return configuration.isParallelExecutionEnabled();
}

@Override
public boolean isClosingStoredAutoCloseablesEnabled() {
return configuration.isClosingStoredAutoCloseablesEnabled();
}

@Override
public boolean isExtensionAutoDetectionEnabled() {
return configuration.isExtensionAutoDetectionEnabled();
}

@Override
public boolean isThreadDumpOnTimeoutEnabled() {
return configuration.isThreadDumpOnTimeoutEnabled();
}

@Override
public ExecutionMode getDefaultExecutionMode() {
return configuration.getDefaultExecutionMode();
Expand Down Expand Up @@ -313,6 +348,16 @@ public CleanupMode getDefaultTempDirCleanupMode() {
public Supplier<TempDirFactory> getDefaultTempDirFactorySupplier() {
return configuration.getDefaultTempDirFactorySupplier();
}

@Override
public TestInstantiationAwareExtension.ExtensionContextScope getDefaultTestInstantiationExtensionContextScope() {
return configuration.getDefaultTestInstantiationExtensionContextScope();
}

@Override
public OutputDirectoryProvider getOutputDirectoryProvider() {
return configuration.getOutputDirectoryProvider();
}
}

private static class DelegatingDisplayNameGenerator implements DisplayNameGenerator {
Expand All @@ -335,13 +380,13 @@ private String prefix() {
}

@Override
public String generateDisplayNameForNestedClass(Class<?> aClass) {
return prefix() + delegate.generateDisplayNameForNestedClass( aClass );
public String generateDisplayNameForNestedClass(List<Class<?>> enclosingInstanceTypes, Class<?> nestedClass) {
return prefix() + delegate.generateDisplayNameForNestedClass( enclosingInstanceTypes, nestedClass );
}

@Override
public String generateDisplayNameForMethod(Class<?> aClass, Method method) {
return prefix() + delegate.generateDisplayNameForMethod( aClass, method );
public String generateDisplayNameForMethod(List<Class<?>> enclosingInstanceTypes, Class<?> testClass, Method testMethod) {
return prefix() + delegate.generateDisplayNameForMethod( enclosingInstanceTypes, testClass, testMethod );
}
}

Expand All @@ -350,12 +395,11 @@ private static class EnhancementWorkedCheckMethodTestDescriptor extends TestMeth
private final boolean enhanced;
private final String[] classes;

public EnhancementWorkedCheckMethodTestDescriptor(UniqueId uniqueId, Class<?> testClass,
JupiterConfiguration configuration,
boolean enhanced, String[] classes) {
public EnhancementWorkedCheckMethodTestDescriptor(UniqueId uniqueId, Class<?> testClass, Supplier<List<Class<?>>> enclosingInstanceTypes, JupiterConfiguration configuration, boolean enhanced, String[] classes) {
super(
prepareId( uniqueId, testMethod( enhanced ) ),
testClass, testMethod( enhanced ),
enclosingInstanceTypes,
configuration
);
this.enhanced = enhanced;
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ dependencyResolutionManagement {
library( "el", "org.glassfish.expressly", "expressly" ).versionRef( elVersion )
}
testLibs {
def junit5Version = version "junit5", "5.10.2"
def junit5Version = version "junit5", "5.13.0"
def junit4Version = version "junit4", "4.13.2"
def junit5LauncherVersion = version "junit5Launcher", "1.10.2"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {
testImplementation testLibs.junit5Api

testRuntimeOnly testLibs.junit5Engine
testRuntimeOnly testLibs.junit5Launcher
}

gradlePlugin {
Expand Down
Loading