Skip to content

Instantly share code, notes, and snippets.

@olopsman
Created October 2, 2019 09:27
Show Gist options
  • Save olopsman/23627637e87e99734ec92af556598ab6 to your computer and use it in GitHub Desktop.
Save olopsman/23627637e87e99734ec92af556598ab6 to your computer and use it in GitHub Desktop.
Apex GenericRESTMock
public with sharing class GenericRESTMock implements HttpCalloutMock{
protected Integer code;
protected String status;
protected String body;
protected Map<string , String> responseHeaders;
public GenericRESTMock(Integer code, String status, String body, Map<String,String> responseHeaders) {
this.code = code;
this.status = status;
this.body = body;
this.responseHeaders = responseHeaders;
}
public HTTPResponse respond(HTTPRequest req) {
//create fake response
HttpResponse res = new HttpResponse();
for (String key : this.responseHeaders.keySet()) {
res.setHeader(key, this.responseHeaders.get(key));
}
res.setBody(this.body);
res.setStatusCode(this.code);
res.setStatus(this.status);
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment