Skip to content
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

Update dependency org.junit:junit-bom to v5.11.1 #1694

Merged
merged 2 commits into from
Oct 2, 2024
Merged
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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ aspectj-jweaver = { module = "org.aspectj:aspectjweaver", version.ref = "aspectj
byteBuddy = { module = "net.bytebuddy:byte-buddy", version.ref = "byteBuddy-version" }
byteBuddy-agent = { module = "net.bytebuddy:byte-buddy-agent", version.ref = "byteBuddy-version" }
hypersql-database = { module = "org.hsqldb:hsqldb", version = "2.7.3" }
junit-bom = { module = "org.junit:junit-bom", version = "5.10.3" }
junit-bom = { module = "org.junit:junit-bom", version = "5.11.1" }
junit4 = { module = "junit:junit", version.ref = "junit4-version" }
junit4-dataprovider = { module = "com.tngtech.java:junit-dataprovider", version = "1.13.1" }
junit4-params = { module = "pl.pragmatists:JUnitParams", version = "1.1.1" }
Expand Down
1 change: 1 addition & 0 deletions jgiven-junit5/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
api project(':jgiven-core')

implementation(platform(libs.junit.bom))
compileOnly 'org.junit.jupiter:junit-jupiter-params'
compileOnly 'org.junit.jupiter:junit-jupiter-api'

testImplementation project(':jgiven-html5-report')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -14,7 +15,7 @@
import com.tngtech.jgiven.report.model.NamedArgument;

class ArgumentReflectionUtil {
private static final Logger log = LoggerFactory.getLogger( ArgumentReflectionUtil.class );
private static final Logger log = LoggerFactory.getLogger(ArgumentReflectionUtil.class);

static final String METHOD_EXTENSION_CONTEXT = "org.junit.jupiter.engine.descriptor.MethodExtensionContext";
static final String TEST_TEMPLATE_INVOCATION_TEST_DESCRIPTOR = "org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor";
Expand All @@ -26,27 +27,31 @@ class ArgumentReflectionUtil {
/**
* This is a very ugly workaround to get the method arguments from the JUnit 5 context via reflection.
*/
static List<NamedArgument> getNamedArgs( ExtensionContext context ) {
static List<NamedArgument> getNamedArgs(ExtensionContext context) {
List<NamedArgument> namedArgs = new ArrayList<>();

if( context.getTestMethod().get().getParameterCount() > 0 ) {
if (context.getTestMethod().get().getParameterCount() > 0) {
try {
if( context.getClass().getCanonicalName().equals( METHOD_EXTENSION_CONTEXT ) ) {
Field field = context.getClass().getSuperclass().getDeclaredField( "testDescriptor" );
Object testDescriptor = ReflectionUtil.getFieldValueOrNull( field, context, ERROR );
if( testDescriptor != null
&& testDescriptor.getClass().getCanonicalName().equals( TEST_TEMPLATE_INVOCATION_TEST_DESCRIPTOR ) ) {
Object invocationContext = ReflectionUtil.getFieldValueOrNull( "invocationContext", testDescriptor, ERROR );
if( invocationContext != null
&& invocationContext.getClass().getCanonicalName().equals( PARAMETERIZED_TEST_INVOCATION_CONTEXT ) ) {
Object arguments = ReflectionUtil.getFieldValueOrNull( "arguments", invocationContext, ERROR );
List<Object> args = Arrays.asList( (Object[]) arguments );
namedArgs = ParameterNameUtil.mapArgumentsWithParameterNames( context.getTestMethod().get(), args );
if (context.getClass().getCanonicalName().equals(METHOD_EXTENSION_CONTEXT)) {
Field field = context.getClass().getSuperclass().getDeclaredField("testDescriptor");
Object testDescriptor = ReflectionUtil.getFieldValueOrNull(field, context, ERROR);
if (testDescriptor != null
&& testDescriptor.getClass().getCanonicalName().equals(TEST_TEMPLATE_INVOCATION_TEST_DESCRIPTOR)) {
Object invocationContext = ReflectionUtil.getFieldValueOrNull("invocationContext", testDescriptor, ERROR);
if (invocationContext != null
&& invocationContext.getClass().getCanonicalName().equals(PARAMETERIZED_TEST_INVOCATION_CONTEXT)) {
Object arguments = ReflectionUtil.getFieldValueOrNull("arguments", invocationContext, ERROR);
if (arguments instanceof Arguments) {
List<Object> args = List.of(((Arguments) arguments).get());
namedArgs = ParameterNameUtil.mapArgumentsWithParameterNames(context.getTestMethod().get(), args);
} else {
log.warn(ERROR + " The type of arguments in the invocation context has changed. Please write a bug report.");
}
}
}
}
} catch( Exception e ) {
log.warn( ERROR, e );
} catch (Exception e) {
log.warn(ERROR, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.3</version>
<version>5.11.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Loading