Skip to content

Commit ec23701

Browse files
committed
fix: Use classloader for loading test resources to ensure CI compatibility
The willReturnValidJsonWebKeys() method was using a relative file path (src/test/resources/rsa_jwks.json) which works locally when the working directory is the module folder, but fails in CI where the working directory is the project root. Changed to use classloader.getResourceAsStream() which works regardless of the current working directory. Also improved error handling to actually throw the exception instead of silently ignoring it, which made debugging difficult.
1 parent 23911a9 commit ec23701

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

auth0/src/test/java/com/auth0/android/util/AuthenticationAPIMockServer.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.auth0.android.util
22

33
import okhttp3.mockwebserver.MockResponse
4-
import java.nio.file.Files
5-
import java.nio.file.Paths
64

75
internal class AuthenticationAPIMockServer : APIMockServer() {
86

@@ -128,11 +126,14 @@ internal class AuthenticationAPIMockServer : APIMockServer() {
128126

129127
fun willReturnValidJsonWebKeys(): AuthenticationAPIMockServer {
130128
try {
131-
val encoded = Files.readAllBytes(Paths.get("src/test/resources/rsa_jwks.json"))
132-
val json = String(encoded)
129+
// Use classloader to load resource file - works regardless of working directory
130+
val inputStream = this::class.java.classLoader?.getResourceAsStream("rsa_jwks.json")
131+
?: throw IllegalStateException("Could not find rsa_jwks.json in test resources")
132+
val json = inputStream.bufferedReader().use { it.readText() }
133133
server.enqueue(responseWithJSON(json, 200))
134-
} catch (ignored: Exception) {
135-
println("File parsing error")
134+
} catch (e: Exception) {
135+
println("File parsing error: ${e.message}")
136+
throw e
136137
}
137138
return this
138139
}

0 commit comments

Comments
 (0)