Skip to content

Instantly share code, notes, and snippets.

@noeticpenguin
Created May 21, 2013 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noeticpenguin/b71ef196ebd2114e6d4e to your computer and use it in GitHub Desktop.
Save noeticpenguin/b71ef196ebd2114e6d4e to your computer and use it in GitHub Desktop.
mockClass
@isTest
public class RestClientHTTPMocks implements HttpCalloutMock {
Protected Integer code;
Protected String status;
Protected String bodyAsString;
Protected Blob bodyAsBlob;
Protected Map<String, String> responseHeaders;
/*
* Constructors.
*/
public RestClientHTTPMocks(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;
}
/*
* This is the interface method need to implement.
*/
public HTTPResponse respond(HTTPRequest req) {
// craft the return response.
HttpResponse res = new HttpResponse();
res.setStatusCode(this.code);
res.setStatus(this.status);
res.setBody(this.bodyAsString);
if (responseHeaders != null) {
for (String key : this.responseHeaders.keySet()) {
res.setHeader(key, this.responseHeaders.get(key));
}
}
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment