I am wondering if I can do this mock
Deferred<Response<Void>>
I am new at Kotlin and at mock but I have unsuccessfully made it.
So far I have done this:
I have a client interface:
class MyClient {
@POST("/names")
@FormUrlEncoded
fun names(
@Field("username") username: String
): Deferred<Response<Void>>
}
On my tests:
lateinit var myClient : MyClient
@Before
fun setUp() {
client = mockk<MyClient>(relaxed = true)
val response = mockk<Response<Void>>(relaxed = true)
every { myClient.names(username) }.returns(mockedResponse)
}
I've found many posts about Response (like this Handle empty response with retrofit and rxjava 2.x ) but not really sure how to handle the "Deferred"
or some about deferred (cannot implement the answer of this. async cannot be resolved in my project
When using kotlin coroutines, how do I unit test a function that calls a suspend function?
Is this possible? what am I missing?
The service I am testing:
class MyService {
fun doSomething(username: String) {
myClient().names(username).await()
}
}