Try this, get rid of the mock interface you created. I am referring to:global interface HttpCalloutMock { void PostData(string url, HTTPRequest request);
}
Then change FutureClassCalloutMock to look like this
@isTest
global class FutureClassCalloutMock implements HttpCalloutMock {
global HTTPResponse respond(HTTPRequest request) {
// Create a fake response
HttpResponse response = new HttpResponse();
response.setHeader('Content-Type', 'application/json');
response.setBody('{"testing": ["test1", "test2"]}');
response.setStatusCode(200);
return response;
}
}
And then assuming that CallbackProcessor is similar to this
public class CallbackProcessor {
public static HttpResponse PostData(string url, String testing) {
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(url);
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setBody('{"testing":"the test"}');
HttpResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
return response;
}
}
The test class becomes
@isTest
private class futureCls_Test {
private static testMethod void srvcCallout_Test() {
// Unit test to cover http web service
// CallbackProcessor.PostData(url, data);
Test.setMock(HttpCalloutMock.class, new FutureClassCalloutMock());
string url = 'https://xpresstaxappeals.com/callback/WebhookHexRefunds';
HttpResponse response = CallbackProcessor.PostData(url, 'Just random testing data');
System.assertEquals(200, response.getStatusCode());
System.assertEquals(response.getBody(), '{"testing": ["test1", "test2"]}');
// Unit test to cover future method
//futureCls.srvcCallout(oppId, oppAmt,oppType);
}
}
1 answer