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