I'm following the suggestion mentioned here for mocking retrofit in testing: Square retrofit server mock for testing
It looks like I'm pretty close following this concept except the return object is null. The following is how I construct my mocked vendors response:
public Response getVendorsResponse(String url) {
String responseString = "";
if (url.contains("category=one")) {
responseString = mFixturesMan.use("one_all");
} else if (url.contains("category=two")) {
responseString = mFixturesMan.use("two_all");
}
return new Response(
url,
200,
"nothing",
Collections.EMPTY_LIST,
new TypedByteArray("application/json", responseString.getBytes()));
}
My callback is as follows:
@Override
public void success(MyResult result, Response response) {
// result is null when mocked.
displayResult(result.getTitle());
}
When debugging, the response I expect comes through. I see the status and the reason I set.
Does this mean the data being passed as the response is bad? Or could other things be wrong? I've copied (and modified slightly) the text from a real response that I know works, so it's possible it's bad data. I can't seem to find the source of the error though.