diff --git a/build.gradle.kts b/build.gradle.kts index 108bc95..bf60a06 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -75,6 +75,9 @@ val testNGTestFixturesConfigurationsByVersion = allTestNGVersions.associateWith extendsFrom(testFixturesRuntimeClasspath) } } +val latestCompileClasspath: Configuration by configurations.creating { + extendsFrom(configurations.compileClasspath.get()) +} dependencies { api(platform("org.junit:junit-bom:5.7.2")) @@ -106,6 +109,11 @@ dependencies { } } } + latestCompileClasspath("org.testng:testng") { + version { + strictly(supportedTestNGVersions.keys.last().value) + } + } } testImplementation("org.junit.jupiter:junit-jupiter") @@ -146,6 +154,11 @@ tasks { listOf("--patch-module", "org.junit.support.testng.engine=${files.asPath}") } } + val compileJavaLatest by registering(JavaCompile::class) { + source = compileJava.get().source + classpath = latestCompileClasspath + destinationDirectory = layout.buildDirectory.dir("latestClasses") + } withType().configureEach { options.compilerArgs.addAll(listOf("-Xlint:all,-requires-automatic", "-Werror")) } @@ -215,6 +228,9 @@ tasks { enabled = false dependsOn(testTasks) } + check { + dependsOn(compileJavaLatest) + } } spotless { diff --git a/src/main/java/org/junit/support/testng/engine/MethodDescriptor.java b/src/main/java/org/junit/support/testng/engine/MethodDescriptor.java index 9da6c7d..52398c2 100644 --- a/src/main/java/org/junit/support/testng/engine/MethodDescriptor.java +++ b/src/main/java/org/junit/support/testng/engine/MethodDescriptor.java @@ -48,6 +48,7 @@ private static MethodSource toMethodSource(Class sourceClass, MethodSignature nullSafeToString(methodSignature.parameterTypes)); } + @SuppressWarnings({ "deprecation", "RedundantSuppression" }) // deprecated since 7.10.1 static String toMethodId(ITestResult result, MethodSignature methodSignature) { String id = methodSignature.stringRepresentation; Object[] instances = result.getTestClass().getInstances(true); diff --git a/src/main/java/org/junit/support/testng/engine/TestDescriptorFactory.java b/src/main/java/org/junit/support/testng/engine/TestDescriptorFactory.java index 5d512af..a62a5dd 100644 --- a/src/main/java/org/junit/support/testng/engine/TestDescriptorFactory.java +++ b/src/main/java/org/junit/support/testng/engine/TestDescriptorFactory.java @@ -27,6 +27,7 @@ import org.junit.platform.engine.UniqueId; import org.testng.ITestNGMethod; import org.testng.ITestResult; +import org.testng.internal.IParameterInfo; import org.testng.internal.annotations.DisabledRetryAnalyzer; class TestDescriptorFactory { @@ -68,6 +69,18 @@ private static Object[] getFactoryParameters(ITestResult result) { } private static Integer getFactoryMethodInvocationIndex(ITestResult result) { + try { + IParameterInfo parameterInfo = result.getMethod().getFactoryMethodParamsInfo(); + return parameterInfo == null ? null : parameterInfo.getIndex(); + } + catch (NoSuchMethodError ignore) { + return getFactoryMethodInvocationIndex_6_14(result); + } + } + + @SuppressWarnings({ "deprecation", "RedundantSuppression" }) // deprecated since 7.10.1 + private static Integer getFactoryMethodInvocationIndex_6_14(ITestResult result) { + // ITestNGMethod.getFactoryMethodParamsInfo() was added in 7.0 and IParameterInfo.getIndex() in 7.5 long[] instanceHashCodes = result.getTestClass().getInstanceHashCodes(); if (instanceHashCodes.length > 1) { long hashCode = result.getInstance().hashCode(); @@ -77,7 +90,6 @@ private static Integer getFactoryMethodInvocationIndex(ITestResult result) { } } } - return null; } diff --git a/src/test/java/org/junit/support/testng/engine/DataProviderIntegrationTests.java b/src/test/java/org/junit/support/testng/engine/DataProviderIntegrationTests.java index 59105d0..5f3f5ce 100644 --- a/src/test/java/org/junit/support/testng/engine/DataProviderIntegrationTests.java +++ b/src/test/java/org/junit/support/testng/engine/DataProviderIntegrationTests.java @@ -184,12 +184,12 @@ void executesFactoryMethodTestClass() { event(engine(), finishedSuccessfully())); results.allEvents().assertEventsMatchLooselyInOrder( // event(testClass(FactoryMethodTestCase.class), started()), // - event(test("method:test()@0"), started()), // + event(test("method:test()@0"), displayName("test[0]"), started()), // event(test("method:test()@0"), finishedSuccessfully()), // event(testClass(FactoryMethodTestCase.class), finishedSuccessfully())); results.allEvents().assertEventsMatchLooselyInOrder( // event(testClass(FactoryMethodTestCase.class), started()), // - event(test("method:test()@1"), started()), // + event(test("method:test()@1"), displayName("test[1]"), started()), // event(test("method:test()@1"), finishedSuccessfully()), // event(testClass(FactoryMethodTestCase.class), finishedSuccessfully())); }