0

I am new for test class but I very eager to learn for that, I have created class. Please can any one help me out to my class.

global class Searchaddress 
    { 
    public String accName{get;set;} 
    public String StNumber{get;set;} 
    public String Bcity{get;set;} 
    public String BPostalcode{get;set;} 
    public String BCountry{get;set;} 
    public Id accId{get;set;} 
    string Id;

    list<Account>updateAdd=new list<Account>(); 
    public Searchaddress(ApexPages.StandardController controller)  
    { 
    id=ApexPages.currentPage().getParameters().get('id'); 
    } 
    public PageReference autosave() 
    { 
    for(Account updatelist:[SELECT id,BillingAddress,BillingCity,BillingCountry,BillingLatitude,BillingLongitude,BillingPostalCode,BillingState,BillingStreet
    FROM Account where id=:id])
        {
            updatelist.BillingStreet=StNumber;
            updatelist.BillingCity=Bcity;
            updatelist.BillingPostalCode=BPostalcode;
            updatelist.BillingState='';
            updatelist.BillingCountry=BCountry;
            updateAdd.add(updatelist);
          }

        update updateAdd;
        PageReference pageRef = new PageReference('/' + ApexPages.currentPage().getParameters().get('id')+'?inline=0');
        return pageRef;

        }

    public class Properties 
        {
            public String city;
            public String label;
            public String id;
            public String postcode;
            public String name;
            public String citycode;
            public String context;
            public Double score;
            public String type;
        }

     @RemoteAction  
     global static list<String> restapi(string accName)  
     {    
     string jsonStr;      
     Http h = new Http();    
     HttpRequest req = new HttpRequest();    
     req.setHeader('Accept','application/JSON');   
     req.setEndpoint('http://api-adresse.data.gouv.fr/search/?q='+EncodingUtil.urlEncode(accName,'UTF-8'));//+'&'+'limit'+'='+'10');//
     req.setMethod('GET');    
     HttpResponse res = h.send(req);   
     List<String> calOut = new List<String>();    
     jsonStr= res.getBody();
     system.debug('res1===>'+res.getBody());    
     JSONParser parser = JSON.createParser(jsonStr);    
     List<String> calOut1 = new List<String>();    
     JSON2Apex parsed = JSON2Apex.parse(res.getBody());    
     for(JSON2Apex.Features f : parsed.Features)
     {
         JSON2Apex.Properties p = f.Properties ;
         calOut1.add(p.label+' '+'FRANCE');    
      }
        return calOut1;   
     }  
 }
Mihai Neagoe
  • 3,192
  • 1
  • 16
  • 25
Nikitha
  • 151
  • 2
  • 7
  • 20
  • 3
    See how to do it here: https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods – Mihai Neagoe Aug 12 '15 at 07:38
  • Nikitha, you need to try writing the test class first and come back if you have any specific issues. You can't expect other people to write the code for you. – Rob Aug 12 '15 at 07:38
  • You can also go through this link for testing HTTP callouts https://developer.salesforce.com/blogs/developer-relations/2012/10/testing-http-callouts-with-static-data-in-winter-13.html#comment-688228232.

    http://salesforce.stackexchange.com/questions/3486/testing-httpcallout-with-httpcalloutmock-and-unittest-created-data

    Start your test class by creating a test account record.

    – Ruchi Aug 12 '15 at 07:47

0 Answers0