I have this code that I want to test:
public List<Map<String, Object>> getMaps (Query query) throws CustomException {
Response<MapsResponse> response = mapsApi.get(); // this is a retrofit2 response
if (!response.isSuccessful()) {
handle(response); // throws CustomException
}
.
.
.
}
So I mocked it with mockito, but when I try to do:
retrofit2.Response<MapsResponse> response = retrofit2.Response.error(500, ResponseBody.create(null, content))
when(mapsApi.get()).thenReturn(response);
It says it cannot resolve method 'thenReturn...'
Does anyone know how can I mock an error response (error HTTP code) that will trigger my exception? Thanks!