• Developer One 25
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
1 Create VF one page with two sections Account details, Account Backup details
 and one custom button

2. On click of first page custom button second vf page will open for creation of account record 
this page also contains one custom button
on click of custom button the record will save and also need to redirect to first page
 

3. After redirection the records that we entered will show in first section of account details
with link delete
 

4. when click on delete link the record will save to one custom object account backup 
and will show in second section of first page
Account Backup details with link delete and undelete

5. when click on undelete it will show in first section again
and if deleted in second section it will not show in both the sections
Hi,

I have written a test class for this rest callouts but its not covering 100% code coverage. Can someone please help me

It throws me error when I run the test class 
Class.AnimalLocator.getAnimalNameById: line 16, column 1 Class.AnimalLocatorTest.testcallout: line 7, column 1

Apex class 

public class AnimalLocator {

public static string getAnimalNameById (integer i)
{
    string a;
    Http ht = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/' + i);
        request.setMethod('GET');
        HttpResponse response = ht.send(request);
        // If the request is successful, parse the JSON response.
    if (response.getStatusCode() == 200) 
    {
            Map<String, Object> result = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());
             Map<string,object> cc = (Map<string,object>) result.get('animals');
        a = (string)cc.get('name');
    }
    return a;
  }
}


Test class

@isTest
public class AnimalLocatorTest 
{
@isTest static void testcallout()
{
      Test.setMock(HttpCalloutMock.class, new AnimalLocatorMock()); 
    string response = AnimalLocator.getAnimalNameById (2); 
String expectedValue = '{"animal":{"id":2,"name":"bear","eats","berries, campers, adam seligman","says":"yum yum"}}'; 
system.assertEquals('eats', response);
   
   }
}

@isTest
global class AnimalLocatorMock implements HttpCalloutMock 
{
global HTTPResponse respond(HTTPRequest request) 
{
        // Create a fake response
         HttpResponse response = new HttpResponse(); 
     response.setHeader('Content-Type', 'application/json');
    response.setBody('{"animal":{"i":2,"name":"bear","eats":"berries, campers, adam seligman","says":"yum yum"}}'); 
        response.setStatusCode(200);
        return response;
}
}
 
  • January 29, 2016
  • Like
  • 0