Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke committed Jan 11, 2025
1 parent 7af5705 commit 4e9d4b3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions okhttp/src/jvmTest/kotlin/okhttp3/CacheLockTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.RegisterExtension
import org.junit.jupiter.api.io.TempDir
import java.util.Optional

@org.junit.jupiter.api.parallel.Isolated
class CacheLockTest {
Expand Down Expand Up @@ -99,17 +100,21 @@ class CacheLockTest {
lockFile.toFile().createNewFile()

val javaExe =
// if (PlatformVersion.majorVersion >= 9) {
// @Suppress("Since15")
// ProcessHandle.current().info().command().get().toPath()
// } else {
if (PlatformVersion.majorVersion >= 9) {
val info = Class.forName("java.lang.ProcessHandle").run {
val handle = getMethod("current").invoke(null)
getMethod("info").invoke(handle)
}
val command = Class.forName("java.lang.ProcessHandle\$Info").getMethod("command").invoke(info) as Optional<*>
(command.get() as String).toPath()
} else {
System.getenv("JAVA_HOME").toPath() / "bin/java"
// }
}

val process =
ProcessBuilder().command(
javaExe.toString(),
"src/test/java/okhttp3/LockTestProgram.java",
"src/jvmTest/kotlin/okhttp3/LockTestProgram.java",
(lockFile.toString()),
)
.redirectErrorStream(true)
Expand Down

0 comments on commit 4e9d4b3

Please sign in to comment.