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
jayesh pagarejayesh pagare 

Please Help me to write Test Class for below apex class?

public class theControllerMyTEST {
  
    public user currentuser{get;set;}
    public string emailAddress{get;set;}
    public List<PersonInfo> lstPersonInfo{get;set;} 

    public class PersonInfo {  
        public integer g_id{get;set;}
        public string sportname{get;set;}      
        public string description{get;set;}      
        public string imageUrl{get;set;}      

        public PersonInfo(){     
          
        }  
    } 
   
// Constructor
    
    public theControllerMyTEST () {
      
       currentuser=[Select FirstName,LastName,Email from User where Id=:userinfo.getuserId()];
       emailAddress =currentuser.Email ;
       system.debug('Email Id :'+emailAddress );  
       getGames();
       
    }
  
// getGame method definition
    
  public void getGames()
    {        
          Http httpProtocol = new Http();  
          HttpRequest request = new HttpRequest();       
          String endpoint ='http://mytest.test.com/gedetails.php?id='+emailAddress;      
          request.setEndPoint(endpoint);                                                                                                         
          request.setMethod('GET');
          request.setEndpoint(endpoint);
          request.setTimeOut(60000);
          HTTPResponse response = httpProtocol.send(request);
          String jsonString = response.getBody();         
          System.debug(jsonString);           
          parseJSON(jsonString );

    }
    
// Json Parser Method
    
    public void parseJSON(String jsonstr) {  
        if (jsonstr != null){  
        lstPersonInfo= new List<PersonInfo>();     
        JSONParser parser = JSON.createParser(jsonstr);
       
        while (parser.nextToken() != null)  
        {  
            if (parser.getCurrentToken() == JSONToken.START_ARRAY)  
            {  
                while (parser.nextToken()!=  JSONToken.END_ARRAY)  
                {  
                    if (parser.getCurrentToken() == JSONToken.START_OBJECT)  
                    {                            
                        PersonInfo ci = new PersonInfo();  
                        while (parser.nextToken() !=  JSONToken.END_OBJECT)  
                    {                                                     
                                                                                               
                          if((parser.getCurrentToken() ==JSONToken.FIELD_NAME)&&(parser.getText().tolowercase()== 'id'))  
                                {   
                                    parser.nextToken();                                                                   
                                    ci.g_id = integer.valueof( parser.getText()); 
                                    system.debug('ID OF CELERY: '+ci.g_id);
                                }           
                         
                        if((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getText().tolowercase() == 'description'))  
                                {  
                                    parser.nextToken();  
                                    ci.description= parser.getText();  
                                                       
                                }                                            
                                                        
                        }  
                        lstPersonInfo.add(ci);  
                    }  
                }  
            }  
        }  
      }     
    }  
 
    
}