@isTest
static void getTest(){
final String RESPONSE_TOKEN = '{ "access_token": "xxxxxxxxx", "token_type": "Bearer"}';
final String REQUEST_BODY = '['+
' {'+
' "code": "329",'+
' "nameSummarized": "Test"'+
' }'+
']';
TestUtils.Mock mock = TestUtils.setMultipleMocks(RESPONSE_TOKEN, 200);
mock = TestUtils.setMultipleMocks(REQUEST_BODY, 200, mock);
Boolean catchException = false;
String requestBody = REQUEST_BODY;
List<sObject> responseBody = null;
Test.startTest();
Test.setMock(HttpCalloutMock.class, mock);
try {
responseBody = (List<sObject>) JSON.deserialize(requestBody, List<sObject>.class);
//call method to be tested
} catch(Exception e){
catchException = true;
}
Test.stopTest();
System.assertEquals(false, catchException);
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter