• Peter Thorson
  • 10 Points
  • Member since 2015
  • Senior Consultant

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 2
I am not able to save my test class:

Below is my test Class:
private class AnimalLocatorTest{
    @isTest static void AnimalLocatorMock1() {
        Test.setMock(HttpCalloutMock.class, new AnimalLocatorMock());
        string result = AnimalLocator.getAnimalNameById(0);
        String expectedResult = 'dog';
        System.assertEquals(result,expectedResult );
My Mock Class:
global class AnimalLocatorMock implements HttpCalloutMock {
    // Implement this interface method
    global HTTPResponse respond(HTTPRequest request) {
        // Create a fake response
        HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
        response.setBody('{"name": ["dog"]}');
        return response; 

My Rest Class:
public class AnimalLocator{
    public string getAnimalNameById(Integer id){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        HttpResponse response = http.send(request);
        String ret;
        if(response.getStatusCode() == 200){
            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            List<Object> name = (List<Object>) results.get('name');
            for (Object animal: name) {
                ret = (String)animal;
        return ret;

On this module, specifically on the Apex Rest Callout unit, I feel like this following challenge instruction could be misleading.

    •    The 'getAnimalNameById' method must call https://th-apex-http-callout.herokuapp.com/animals/:id, using the ID passed into the method. The method returns the value of the 'name' property (i.e., the animal name).

If someone physically copies that link, removes id but leaves in : then the challenge review will not pass because the request link will post as 
instead of the correct 

The first incorrect link will still perform get for the request, but just blank values in the json response.