title: How to test code that calls top level functions in Kotlin?
body: <p>I am very new to Kotlin.</p>
  
  <p>I have a class that calls a top level function (which makes a http call). I am trying to write unit tests for my class without having it go out to the network.</p>
  
  <p>Is there a way to mock/powermock/intercept the call from my class to the Kotlin top level function?</p>
  
  <pre><code>class MyClass {
      fun someMethod() {
          // do some stuff
          "http://somedomain.com/some-rest/action".httpGet(asList("someKey" to "someValue")).responseString { (request, response, result) -&gt;
              // some processing code
          }
      }
  }
  </code></pre>
  
  <p>It is using the <a href="https://github.com/kittinunf/Fuel" rel="noreferrer" title="kittinunf/Fuel">kittinunf/Fuel library</a> for the httpGet call.</p>
  
  <p>It adds a top level function to String that ultimately calls a companion object function in Fuel (Fuel.get()).</p>
  
  <p>The unit test needs to intercept the call to httpGet so that I can return a json string for the test.</p>