Skip to content

Commit

Permalink
Merge pull request #137 from jenschude/fix-junit-5_9
Browse files Browse the repository at this point in the history
Fix NoClassDefFoundError with JUnit 5.9 and ignore coveralls because new functions are very simple ...
  • Loading branch information
aaschmid authored Dec 26, 2022
2 parents 632b72c + d81e91e commit 4ace908
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 22 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ build-job: &build-job
# Restart caching for every new wrapper and add job name (= JDK version) as JDK influences Gradle's caching
- gradle-repo-v2-{{ .Environment.CIRCLE_JOB }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}

- run: ./gradlew --build-cache --scan build -Pjunit4Version=4.10 -PjunitJupiterVersion=5.5.0 -PskipSpotBugs
- run: ./gradlew --build-cache --scan build -Pjunit4Version=4.11 -PjunitJupiterVersion=5.5.2 -PskipSpotBugs
- run: ./gradlew --build-cache --scan build -Pjunit4Version=4.12 -PjunitJupiterVersion=5.6.3 -PskipSpotBugs
- run: ./gradlew --build-cache --scan build -Pjunit4Version=4.10 -PjunitJupiterVersion=5.9.0 -PskipSpotBugs
- run: ./gradlew --build-cache --scan build -Pjunit4Version=4.11 -PjunitJupiterVersion=5.9.0 -PskipSpotBugs
- run: ./gradlew --build-cache --scan build -Pjunit4Version=4.12 -PjunitJupiterVersion=5.9.0 -PskipSpotBugs
- run: ./gradlew --build-cache --scan build
- run: COVERALLS_REPO_TOKEN=Npp4tyTSCz0wSMZTJ81vXdVe1uw6WtRrC ./gradlew --build-cache --scan jacocoRootReport coveralls

Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jdk:
- oraclejdk11

script:
- ./gradlew --scan build -Pjunit4Version=4.10 -PjunitJupiterVersion=5.5.0 -PskipSpotBugs
- ./gradlew --scan build -Pjunit4Version=4.11 -PjunitJupiterVersion=5.5.2 -PskipSpotBugs
- ./gradlew --scan build -Pjunit4Version=4.12 -PjunitJupiterVersion=5.6.3 -PskipSpotBugs
- ./gradlew --scan build -Pjunit4Version=4.10 -PjunitJupiterVersion=5.9.0 -PskipSpotBugs
- ./gradlew --scan build -Pjunit4Version=4.11 -PjunitJupiterVersion=5.9.0 -PskipSpotBugs
- ./gradlew --scan build -Pjunit4Version=4.12 -PjunitJupiterVersion=5.9.0 -PskipSpotBugs
- ./gradlew --scan build

- cd ${TRAVIS_BUILD_DIR}/junit4/
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ println("Using skipSpotBugs = $skipSpotBugs for current build.")
// set default junit versions if not set via command line
val junit4Version by extra(findProperty("junit4Version")?.toString() ?: "4.13.1")
println("Using JUnit4 version $junit4Version for current build.")
val junitJupiterVersion by extra(findProperty("junitJupiterVersion")?.toString() ?: "5.7.0")
val junitJupiterVersion by extra(findProperty("junitJupiterVersion")?.toString() ?: "5.9.0")
println("Using JUnit Jupiter version $junitJupiterVersion for current build.")

class Dependency {
Expand Down
4 changes: 2 additions & 2 deletions junit-jupiter-params/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.5.0</version>
<version>5.9.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.0</version>
<version>5.9.0</version>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
import org.junit.jupiter.api.extension.ExtensionContext.Store;
import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ParameterResolutionException;
import org.junit.jupiter.engine.config.DefaultJupiterConfiguration;
import org.junit.jupiter.engine.execution.ExecutableInvoker;
import org.junit.jupiter.engine.execution.DefaultExecutableInvoker;
import org.junit.jupiter.engine.extension.ExtensionRegistry;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.platform.engine.ConfigurationParameters;
Expand All @@ -52,8 +53,6 @@
public abstract class AbstractUseDataProviderArgumentProvider<SOURCE_ANNOTATION extends Annotation, DATAPROVIDER_ANNOTATION extends Annotation>
extends AbstractDataProviderArgumentProvider<SOURCE_ANNOTATION> {

private static final ExecutableInvoker executableInvoker = new ExecutableInvoker();

protected static final Namespace NAMESPACE_USE_DATAPROVIDER = Namespace
.create(AbstractUseDataProviderArgumentProvider.class, "dataCache");

Expand Down Expand Up @@ -154,8 +153,7 @@ protected Object invokeDataProviderMethodToRetrieveData(Method dataProviderMetho
// TODO how to not require junit-jupiter-engine dependency and reuse already existing ExtensionRegistry?
ExtensionRegistry extensionRegistry = createRegistryWithDefaultExtensions(
new DefaultJupiterConfiguration(emptyConfigurationParameters()));
Object data = executableInvoker.invoke(dataProviderMethod, context.getTestInstance().orElse(null), context,
extensionRegistry, InvocationInterceptor::interceptTestFactoryMethod);
Object data = new DefaultExecutableInvoker(context, extensionRegistry).invoke(dataProviderMethod, context.getTestInstance().orElse(null));
if (cacheDataProviderResult) {
store.put(dataProviderMethod, data);
}
Expand All @@ -171,6 +169,7 @@ protected Object invokeDataProviderMethodToRetrieveData(Method dataProviderMetho

private ConfigurationParameters emptyConfigurationParameters() {
return new ConfigurationParameters() {
@SuppressWarnings("deprecation")
@Override
public int size() {
return 0;
Expand All @@ -185,6 +184,11 @@ public Optional<Boolean> getBoolean(String key) {
public Optional<String> get(String key) {
return Optional.empty();
}

@Override
public Set<String> keySet() {
return Collections.emptySet();
}
};
}
}
2 changes: 1 addition & 1 deletion junit-jupiter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.0</version>
<version>5.9.0</version>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
import org.junit.jupiter.api.extension.ExtensionContext.Store;
import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ParameterResolutionException;
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
import org.junit.jupiter.engine.config.DefaultJupiterConfiguration;
import org.junit.jupiter.engine.execution.ExecutableInvoker;
import org.junit.jupiter.engine.execution.DefaultExecutableInvoker;
import org.junit.jupiter.engine.extension.ExtensionRegistry;
import org.junit.platform.engine.ConfigurationParameters;

Expand All @@ -54,8 +55,6 @@
public abstract class UseDataProviderInvocationContextProvider<TEST_ANNOTATION extends Annotation, DATAPROVIDER_ANNOTATION extends Annotation>
extends AbstractDataProviderInvocationContextProvider<TEST_ANNOTATION> {

private static final ExecutableInvoker executableInvoker = new ExecutableInvoker();

protected static final Namespace NAMESPACE_USE_DATAPROVIDER = Namespace
.create(UseDataProviderInvocationContextProvider.class, "dataCache");

Expand Down Expand Up @@ -176,8 +175,7 @@ protected Object invokeDataProviderMethodToRetrieveData(Method dataProviderMetho
// TODO how to not require junit-jupiter-engine dependency and reuse already existing ExtensionRegistry?
ExtensionRegistry extensionRegistry = createRegistryWithDefaultExtensions(
new DefaultJupiterConfiguration(emptyConfigurationParameters()));
Object data = executableInvoker.invoke(dataProviderMethod, context.getTestInstance().orElse(null), context,
extensionRegistry, InvocationInterceptor::interceptTestFactoryMethod);
Object data = new DefaultExecutableInvoker(context, extensionRegistry).invoke(dataProviderMethod, context.getTestInstance().orElse(null));
if (cacheDataProviderResult) {
store.put(dataProviderMethod, data);
}
Expand All @@ -193,6 +191,7 @@ protected Object invokeDataProviderMethodToRetrieveData(Method dataProviderMetho

private ConfigurationParameters emptyConfigurationParameters() {
return new ConfigurationParameters() {
@SuppressWarnings("deprecation")
@Override
public int size() {
return 0;
Expand All @@ -207,6 +206,11 @@ public Optional<Boolean> getBoolean(String key) {
public Optional<String> get(String key) {
return Optional.empty();
}

@Override
public Set<String> keySet() {
return Collections.emptySet();
}
};
}
}

0 comments on commit 4ace908

Please sign in to comment.