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

Replace usage of deprecated APIs #121

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
16 changes: 16 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -106,6 +109,11 @@ dependencies {
}
}
}
latestCompileClasspath("org.testng:testng") {
version {
strictly(supportedTestNGVersions.keys.last().value)
}
}
}

testImplementation("org.junit.jupiter:junit-jupiter")
Expand Down Expand Up @@ -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<JavaCompile>().configureEach {
options.compilerArgs.addAll(listOf("-Xlint:all,-requires-automatic", "-Werror"))
}
Expand Down Expand Up @@ -215,6 +228,9 @@ tasks {
enabled = false
dependsOn(testTasks)
}
check {
dependsOn(compileJavaLatest)
}
}

spotless {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand All @@ -77,7 +90,6 @@ private static Integer getFactoryMethodInvocationIndex(ITestResult result) {
}
}
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
Loading