I am just copying and pasting an exercise in the Trailhead API Integration tutorial and the system.assertEquals(expectedValue,actualValue)
line keeps failing between the mocked JSON I am feeding versus the Actual, what's even strange is that the logs show that the Expected vs Actual values are the same
System.AssertException: Assertion Failed: Expected: {"animals":["majestic badger,"fluffy bunny","scary bear","chicken","mighty moose"]}, Actual: {"animals": ["majestic badger", "fluffy bunny", "scary bear", "chicken", "mighty moose"]}`
Any idea what tweaks I need to make to nudge the system assert? I tried editing and re-editing the whitespace but no luck there
Here's the @isTest class (copied from the tutorial)
@isTest
private class AnimalsCalloutsTest {
@isTest static void testGetCallout() {
//Create the mockk response based on a static resource
StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
mock.setStaticResource('GetAnimalResource');
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
HttpResponse result = AnimalsCallouts.makeGetCallout();
//Verify mock response is not null
System.assertNotEquals(null,result,
'The callout returned a null response');
//Verify content type
System.assertEquals('application/json;charset=UTF-8',
result.getHeader('Content-Type'),
'The content type value is not expected.');
//Verify the array contains 3 items
Map<String, Object> results = (Map<String,Object>)
JSON.deserializeUntyped(result.getBody());
List<Object> animals = (List<Object>) results.get('animals');
System.assertEquals(3, animals.size(),
'The array should only contain 3 items');
}
@isTest static void testPostCallout() {
//set mock callout class
Test.setMock(HttpCalloutMock.class, new AnimalsHttpCalloutMock());
//This causes a fake response to be sent
//from the class that implements HttpCalloutMock.
HttpResponse response = AnimalsCallouts.makePostCallout();
//Verify that the response received contains fake values
String contentType = response.getHeader('Content-Type');
System.assert(contentType == 'application/json');
String actualValue = response.getBody();
System.debug(response.getBody());
String expectedValue = '{"animals": ["majestic badger", "fluffy bunny", "scary bear", "chicken", "mighty moose"]}';
System.assertEquals(actualValue, expectedValue);
System.assertEquals(200, response.getStatusCode());
}
}