function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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();

        try{

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

            if(!Test.isRunningTest()){

            }

            HttpRequest req=new HttpRequest();
            req.setEndpoint(endPoint);
            req.setMethod('POST');
            req.setCompressed(false);
            req.setHeader('Content-Type','application/hal+json');
            String jsonBody = JSON.serialize(reqApplication);
            req.setBody(jsonBody);

            //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.');
                returnApplication.errors.add(er);
                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){
            system.debug(e);
            DTOError er = new DTOError(e.getMessage());
            returnApplication.errors.add(er);
        }
        return returnApplication;
    }

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

        //Create a fake response

        HttpResponse res = new HttpResponse();
        res.setHeader('Content-type', 'application/json');
        res.setBody('{"applicationType"}:"major_med"}');
        res.setStatusCode(200);

        return res;

    }

}

And here is the start of my test class

@isTest
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.
AshishyadavAshishyadav

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

Test.starttest();
 APIApplicationUtility.createApplication(paramter);
Test.stoptest();

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