samedi 18 juillet 2020

Kotlin - Mocking functions having an extension function as parameter

Given a method taking a suspendable extension function as parameter, e.g.

data class Context(val a: String, val b:String)

interface Runner {
   operator fun <T> invoke(task: suspend Context.() -> T) : T
}

Is there any mocking framework helping me to mock that?


class Test {

   @Mock
   lateinit var runner: Runner

   fun test() {

      // given
      whenever(runner.invoke( ???any-context-extension-method??? )
         .thenReturn( ???something??? ))

      ...

   }
}

Aucun commentaire:

Enregistrer un commentaire