+ Start a Discussion
Swaggy BSwaggy B 

Test Class Help http response

Hello I have a class that I am trying to get some test coverage from that is using a http response. Here is my class 

public with sharing class APIApplicationUtility {

    public static DTOApplication createApplication (DTOApplication reqApplication){
        DTOApplication returnApplication = new DTOApplication();


            String endPoint='http://hcscdn-dev.apigee.net/retailapi/v1-dev/application/application';



            HttpRequest req=new HttpRequest();
            String jsonBody = JSON.serialize(reqApplication);

            //Where going to call the API here
            HttpResponse r = OAuthUtility.InvokeService(req,false);

            if (r == null){
                DTOError er = new DTOError ('There was a problem with the Application service. Please call an administrator.');
                return returnApplication;

            String jsonStr = r.getBody();
            system.debug('Quote Response: '+jsonStr);

            //Deserialize JSON back to DTO class
            returnApplication = (DTOApplication)System.JSON.deserialize(jsonStr, DTOApplication.class);
        }catch (Exception e){
            DTOError er = new DTOError(e.getMessage());
        return returnApplication;

I wrote a mock also 
global class TestApplicationAPIMock implements HttpCalloutMock {
    global HttpResponse respond(HttpRequest req){

        //Create a fake response

        HttpResponse res = new HttpResponse();
        res.setHeader('Content-type', 'application/json');

        return res;



And here is the start of my test class

public class APIApplicationUtilityTest {
    @isTest static void TestAPIApplication(){

           Test.setMock(HttpCalloutMock.class, new TestApplicationAPIMock());

           APIApplicationUtility thisApp = new APIApplicationUtility();

          HttpResponse r = APIApplicationUtility.createApplication();

Im having problems getting the method.

createApplication has a parameter which you have not passed . Try passing the DTOApplication parrameter 
Also try using


Swaggy BSwaggy B
I also tried that but I still got an error "expecting a right parenteses, found reqApplication" or either the variable does not exisit