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
Aryan JhaAryan Jha 

Compile Error: Missing '<EOF>' at '@' at line 21 column 1

public class AnimalLocator
{
public static String getAnimalNameById(Integer id)
{
String returnval=null;
Http http=new Http();
HttpRequest request = new HttpRequest();
request.setEndPoint('https://th-apex-http-callout.herokuapp.com/animals/id'+id);
request.setMethod('GET');
HttpResponse response=http.send(request);
if(response.getStatusCode()==200)
{
Map<String,Object>jsonbody=(Map<String,Object>)JSON.deserializeUntyped(response.getBody());
Map<String,Object>result=(Map<String,Object>)jsonbody.get('animal');
returnval=String.valueof(result.get('name'));
}
return retunvalue;
}
}

@isTest
global class AnimalLocatorMock implements HttpCalloutMock
{
global HttpResponse respond(HttpRequest request)
{
HttpResponse response=new Httpresponse();
response.setheader('Content-Type','application/json');
response.setbody('{"animal":{"id":1,"name":"tiger","eats":"deer","says":"roar"}}');
response.setStatusCode(200);
return response;

}
}
@isTest
private class AnimalLocatorTest()
{
@isTest static void testAnimalNamebyId()
{
Test.setMock(HttpCalloutMock.class,new AnimalLocatorMock());
String result= AnimalLocator.getAnimalNameById(1);
system.assertNotEquals(null,result,'the callout returns a null response');
system.assetEquals('tiger',result);
}
}
SwethaSwetha (Salesforce Developers) 
HI Aryan,
I see that your query is related to the trailhead module 
Apex Integration Services . Can you check if you have created a separate class for the test class AnimalLocatorMock ?

The link https://gist.github.com/mannharleen/2890d40f5cea62d058d62f7c16e39f73 would be helpful.

If you have any additional queries, we have a separate Trailhead team who can help you with these issues. You can use the below link to reach out to them so that one of the Engineers will get in touch with you.
Support: https://trailhead.salesforce.com/en/help?support=home

Please mark this answer as best if it helps so that others facing the same issue will find it useful. Thanks
vishal-negandhivishal-negandhi

Hi Aryan, 

These need to be stored as different classes

Class 1 - AnimalLocator
 

public class AnimalLocator
{
	public static String getAnimalNameById(Integer id)
	{
		String returnval=null;
		Http http=new Http();
		HttpRequest request = new HttpRequest();
		request.setEndPoint('https://th-apex-http-callout.herokuapp.com/animals/id'+id);
		request.setMethod('GET');
		HttpResponse response=http.send(request);
		if(response.getStatusCode()==200)
		{
			Map<String,Object>jsonbody=(Map<String,Object>)JSON.deserializeUntyped(response.getBody());
			Map<String,Object>result=(Map<String,Object>)jsonbody.get('animal');
			returnval=String.valueof(result.get('name'));
		}
		return retunvalue;
	}
}

Class 2 - AnimalLocatorMock
@isTest
global class AnimalLocatorMock implements HttpCalloutMock{
	global HttpResponse respond(HttpRequest request)
	{
		HttpResponse response=new Httpresponse();
		response.setheader('Content-Type','application/json');
		response.setbody('{"animal":{"id":1,"name":"tiger","eats":"deer","says":"roar"}}');
		response.setStatusCode(200);
		return response;
	}
}
And finally, the test class - AnimalLocatorTest
@isTest
private class AnimalLocatorTest()
	{
	@isTest static void testAnimalNamebyId()
	{
		Test.setMock(HttpCalloutMock.class,new AnimalLocatorMock());
		String result= AnimalLocator.getAnimalNameById(1);
		system.assertNotEquals(null,result,'the callout returns a null response');
		system.assetEquals('tiger',result);
	}
}

This should fix your problem.

 
Aryan JhaAryan Jha
Method does not exist or incorrect signature: void setMock(System.Type, AnimalLocatorMock) from the type test at line 6 column 14 @isTest private class AnimalLocatorTest() { @isTest static void testAnimalNamebyId() { Test.setMock(HttpCalloutMock.class,new AnimalLocatorMock()); String result= AnimalLocator.getAnimalNameById(1); system.assertNotEquals(null,result,'the callout returns a null response'); system.assetEquals('tiger',result); } }