I'm currently playing around with SFDC-Http Integration and the new Mock server functionality.
In the Apex code which I am testing, I have this branch condition:
if (response.getStatusCode() != 200) { debugResponse (response); }
else { update (processInvoiceList(invoiceIdList, response)); }
... and I can thoroughly test what happens if the status code is 200.
However, if the status code is not 200, the code executed is simply this:
/**
* Write debugging information
* @param HttpResponse response : Http response (e.g., from sendJsonToRemoteService())
* @return None
**/
private static void debugResponse (HttpResponse response)
{
System.debug(
LoggingLevel.ERROR ,
'!!!!! Error from ' + request.getEndpoint() + ' : ' + response.getStatusCode() + ' ' + response.getStatus()
);
}
This being the case, as the code currently stands, the only changes made to the system to check for would be to check the debug log.
I realize I could refactor my source to expose the HttpResponse (i.e. make it a public class variable), but aside from testing there is no need to expose it, so I don't want to if I don't need to.
So, instead, I'd like my unit test to parse the error log for the error message.
Is this possible?
If so, how?