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
Sadik Shaik 3Sadik Shaik 3 

How to cover these lines in test class for response

Below is the code:
if (response.getStatusCode() == 200) {
string jsonresponse = response.getBody();
}
else if(response.getStatusCode() == 400){
sMessage = 'Bad Request: This response means that target system could not understand the request due to invalid syntax.';
displayMessage(sMessage);
}

Can anyone help me on this to cover the above lines of code in test class?
Thanks in Advance
Raj VakatiRaj Vakati
On mock callout you can set the status

 
YOURMOCK mock = new YOURMOCK ();
        mock.setStatusCode(200);
        mock.setHeader('Content-Type', 'application/json;charset=UTF-8');
        // Associate the callout with a mock response
        Test.setMock(HttpCalloutMock.class, mock);
        // Call method to test

YOURMOCK mock = new YOURMOCK ();
        mock.setStatusCode(400);
        mock.setHeader('Content-Type', 'application/json;charset=UTF-8');
        // Associate the callout with a mock response
        Test.setMock(HttpCalloutMock.class, mock);
        // Call method to test


 
Sadik Shaik 3Sadik Shaik 3
HI Raj Vakati,

I am unable to cover the above code.
Can you please send me the mock response code and how to call the method in test class?
Thanks in advance