You need to sign in to do that
Don't have an account?
Srijan Narayan
Executing the 'getAnimalNameById' method on 'AnimalLocator' failed.
Executing the 'getAnimalNameById' method on 'AnimalLocator' failed. Make sure the method exists with the name 'getAnimalNameById', is public and static, accepts an Integer and returns a String
Here are my codes:
.AnimalLocator-
Here are my codes:
.AnimalLocator-
public class AnimalLocator { public static String getAnimalNameById(Integer id) { String animalName; Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/' + id); request.setMethod('GET'); HttpResponse response = http.send(request); if(response.getStatusCode()==200){ Map<String, Object> r = (Map<String, Object>) JSON.deserializeUntyped(response.getBody()); Map<String, Object> animal = (Map<String, Object>)r.get('animal'); animalName = string.valueOf(animal.get('name')); } return animalName; } }AnimalLocatorMock
@IsTest global class AnimalLocatorMock implements HttpCalloutMock { global HTTPresponse respond(HTTPrequest request) { Httpresponse response = new Httpresponse(); response.setStatusCode(200); response.setBody('{"animal":{"id":1,"name":"chicken","eats":"chicken food","says":"cluck cluck"}}'); return response; } }AnimalLocatorTest-
@IsTest public class AnimalLocatorTest { @isTest public static void testAnimalLocator() { Test.setMock(HttpCalloutMock.class, new AnimalLocatorMock()); String s = AnimalLocator.getAnimalNameById(1); system.debug('string returned: ' + s); } }
Please note that Questions about how to pass Trailhead challenges are not on topic, because these challenges are intended to be independent demonstrations of your abilities.
Trailhead Help (https://trailhead.salesforce.com/en/help?support=home)can provide assistance for situations where Trailhead does not appear to be functioning correctly.