https://kotlinlang.org logo
Title
d

Daniele Andreoli

03/09/2021, 9:42 PM
Good evening. Sadly, i'm not good at testing and I need some help. I'm trying to use mockk to mock my Retrofit API response. I?m trying to do as follow:
Response.success(mockedResponseList)
Here's the code complete:
coEvery { restApi.getAllBeersWithPagination(1, null).hint(Response::class) } coAnswers { Response.success(mockedResponseList)}
But it always returns:
java.lang.ClassCastException: java.lang.Object cannot be cast to retrofit2.Response
Someone can help me, please? Thanks
m

Mattia Tommasone

03/09/2021, 10:11 PM
what does your
getAllBeersWithPagination
return?
i think you can just
coEvery {
    restApi.getAllBeersWithPagination(1, null)
} returns Response.success(mockedResponseList)
btw
d

Daniele Andreoli

03/10/2021, 6:31 AM
Hi, thanks for thw answer. I did what you said but unfortunatly the result was the same...
Anyway, the method returns a
Response<List<BeersListDTOItem>>