Created
October 2, 2019 09:27
-
-
Save olopsman/23627637e87e99734ec92af556598ab6 to your computer and use it in GitHub Desktop.
Apex GenericRESTMock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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