title: Mocking return value of method that returns Kotlin Coroutines Deferred type
body: <p>I'm using Kotlin Coroutines and in particular using Retrofit's <code>CoroutineCallAdapterFactory</code>.  I'm trying then to unit test a class that in turn utilizes Retrofit interface (<code>GalwayBusService</code> below).</p>
  
  <pre><code>interface GalwayBusService {
  
      @GET("/routes/{route_id}.json")
      fun getStops(@Path("route_id") routeId: String) : Deferred&lt;GetStopsResponse&gt;
  
  }
  </code></pre>
  
  <p>In my unit test I have </p>
  
  <p><code>val galwayBusService = mock()</code></p>
  
  <p>and then trying something like following to mock what gets returned when that method is called.  The issue is though that <code>getStops</code> returns a <code>Deferred</code> value.  Is there any particular approach recommend for mocking APIs like this?</p>
  
  <pre><code>`when`(galwayBusService.getBusStops()).thenReturn(busStopsResponse)
  </code></pre>