Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit creating mocked void success response?

Hi i am trying to mock one of my request response api to return a response success of type Void but i cant seem to do that as Void cannot be initialised and is private.

Im trying to do this:V

val responseMock = Response.success(Void())

But no joy.

I even tried setting the Response.success(null) and it complains that the responseMock object has to be of type Void in my case as my api method returns this:

Single<Response<Void>>

but having response.success(null) yields

Single<Response<Nothing?>>?
like image 475
Jonathan Avatar asked Jan 02 '23 01:01

Jonathan


1 Answers

If defined in Kotlin, Single<Response<Void>> is an impossible type. Void can only be null so the type has to be Single<Response<Void?>> to make Response.success<Void?>(null) a valid value.

like image 70
Kiskae Avatar answered Jan 05 '23 00:01

Kiskae