I have a class I've written that HttpRequest GET to an API and brings back lead information that I'm converting to Contacts (we use them as Inquiries).
I have 2 additional classes, one is a Wrapper class I use to deserialize the JSON response, the other is lets me turn my Wrapper into a list.
I'm using an HttpCalloutMock class to test it, and filling in a few static JSON responses.
Everything works, it's wonderful and my test results are 80% code coverage, but all the lines that aren't tested are all the lines in those 2 classes.
Can anyone tell me why the test ignores those classes?
EDIT: Here's some code: I'm using the SingleRequestMock.cls outlined in this post, I'm also using the testMethod in that post: https://developer.salesforce.com/blogs/developer-relations/2013/03/testing-apex-callouts-using-httpcalloutmock.html
requestmock:
@isTest
public class SingleRequestMock implements HttpCalloutMock {
protected Integer code;
protected String status;
protected String bodyAsString;
protected Blob bodyAsBlob;
protected Map<String, String> responseHeaders;
public SingleRequestMock(Integer code, String status, String body,
Map<String, String> responseHeaders) {
this.code = code;
this.status = status;
this.bodyAsString = body;
this.bodyAsBlob = null;
this.responseHeaders = responseHeaders;
}
public SingleRequestMock(Integer code, String status, Blob body,
Map<String, String> responseHeaders) {
this.code = code;
this.status = status;
this.bodyAsBlob = body;
this.bodyAsString = null;
this.responseHeaders = responseHeaders;
}
public HTTPResponse respond(HTTPRequest req) {
HttpResponse resp = new HttpResponse();
resp.setStatusCode(code);
resp.setStatus(status);
if (bodyAsBlob != null) {
resp.setBodyAsBlob(bodyAsBlob);
} else {
resp.setBody(bodyAsString);
}
if (responseHeaders != null) {
for (String key : responseHeaders.keySet()) {
resp.setHeader(key, responseHeaders.get(key));
}
}
return resp;
}
}
testclass:
@isTest
private class testrequestStudyAbroad101 {
static testMethod void testrequestStudyAbroad() {
Datetime dt=Datetime.now();
String dts=dt.format('yyyy-MM-dd');
SingleRequestMock fakeResponse=new SingleRequestMock(200,'OK','[{/**FAKE STATIC JSON HERE**/}]', null);
Test.setMock(HttpCallOutMock.class, fakeResponse);
requestStudyAbroad101.getInq();
}
}
The "uncovered" wrappers:
public class saJSON {
public List<saJSONwrapper> saJSON;
}
public class saJSONwrapper {
String id;
String email;
String name; //contact.name breaks out into firsname lastname
String university;
String comment;
String address; //mailing address breaks out to mailing street, mailing city, mailing state, maling zip, mailing country
String program_id; //need to map
String program_name;
String program_link;
String created_at_string;
String catalog_requested; //make a task
String phone_call_requested; //make a task
String phone_number;
String lead_type;
}
I'd rather not put in all the extra code because it's just a callout and then a bunch of regex and parsing and soql, and it would take a long time to clean out stuff that shouldn't be on the internet.