java - How to mock Void Call? -
in api (with retrofit) have lot of requests this:
public call<void> postasyncreservedevice(@nonnull reservedworkerdata data, @nonnull string token) { return apiservice.postreservedworker( data, apiprefs.token_prefix + token); }
where ignore result of response - successful or not , important.
but faced problem in unit test. need mock api answer:
@test public void test() { //... when(apiservice.postasyncreservedevice( eq(data), any(string.class))) .thenreturn(calls.response(any() void)) //... }
looks good, when run test case see error:
java.lang.classcastexception: java.lang.object cannot cast java.lang.void
how mock , test such methods in api?
the method returns call<void>
, why not return in mocked method : mockito.any(call.class)
?
for example :
mockito.when(mock.postasyncreservedevice()).thenreturn(mockito.any(call.class));
while produce warning @ compile time declares raw call
.
Comments
Post a Comment