Language: Kotlin
The goal is to test a method that calls System.getenv
internally, I'd like to make this method produce a predefined result
Tried:
mockkStatic(System::class)
every {
System.getenv(any())
} answers {
when {
firstArg() as String == "clientId" -> "aaa"
firstArg() as String == "clientSecret" -> "bbb"
else -> throw IllegalArgumentException("something went wrong")
}
}
mockkStatic(System::class)
This appears to have sent the JVM into a bit of tipsy:
Exception in thread "main" java.lang.StackOverflowError
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "main"
How does one test a method like this? (as you can imagine, a lot of code uses environment variables)