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
AK2017AK2017 

Test coverage for getter setter method

Hello All,

I am trying to get good code coverage for my getter setter method but i am not able to do anything.

Here is my code and test class.
 
public class PhdAppsProgressViewcontroller {
    
    public List<SelectOption> terms{ get; set;}
    public String Field {get; Set;}
    public String Fieldvalue {get; Set;}
    public Date FieldvalueDate {get; Set;}
    public Date FieldvalueEndDate {get; Set;}
    public String Query;
    public ApexPages.StandardSetController con {get; set;}
    public boolean searchPerformed{get;set;}
    public Integer queryLimit { get{return 50000;}}
    //public List<PhdOppDocuments> lstOppDocuments { get; set;}
    public class PhdOppDocuments {
    
        public String OppName {get;Set;}
        public String ProgramName {get;Set;}        
        public Boolean Resume {get; set;}
        public Boolean Recommendation {get; set;}
        public Boolean WritingSample {get; set;}
        public Boolean unoffiTranscripts {get; set;}
        public Boolean CoverLetter {get; set;}        
        public String CurrentStatus {get;set;}
        public String OppID {get;set;} 
        public String Owner {get;set;}
        public Integer Age {get;set;}   
        public String Term {get;set;}   
        
    }

    public PhdAppsProgressViewcontroller(){

        //Lstopps = [Select ID, Name, StageName, Opportunity_Status__c, Program_Name__c, Timestamp_Qual_Applicant__c from Opportunity where Program_Name__c like '%Doctor%' and Timestamp_Qual_Applicant__c = null limit ];
        
        this.terms = new List<selectOption>();
        List<Term__C> termLST = new List<Term__C>();
        termLST = [select id, Name, Term_Start__c from Term__c where Term_Start__c != null and Active__c = true order by Term_Start__c DESC Limit 10];      
        for(term__c trm:termLST){
                terms.add(new SelectOption(trm.Name,trm.Name));
        }
        
        
    
    }

    public pagereference RunReport(){
     
         
          if(Field != null){
             
          
            if(Field == 'Term__r.Name'){   
                
                if( Fieldvalue == null || Fieldvalue == ''){
                    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 'Please enter the Term.'));
                     return null;
                }
                
                String[] FieldValues = new String[]{Fieldvalue};
                Query = 'Select ID, Name, StageName, Opportunity_Status__c, Program_Name__c, Timestamp_Qual_Applicant__c, Owner.Name, Term__r.Name, (Select Id, CreatedDate, LastModifiedDate, Document_Type__c From Attachments__r) from Opportunity where (StageName = \'Lead\' OR StageName = \'Application\') and Program_Name__c like \'%Doctor%\' and Timestamp_Qual_Applicant__c = null AND Owner.Name != \'ITAdmin Trident\' AND ' +Field+' Like \''+ Fieldvalue+'\'';
            }
            
            if(Field == 'CreatedDate'){  
            
                if( FieldvalueDate == null || FieldvalueEndDate == null){
                    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 'Please enter Start date and End date.'));
                     return null;
                }
               
                Datetime dt = datetime.newInstance(FieldvalueDate.year(), FieldvalueDate.month(),FieldvalueDate.day(),0,0,0);
                //DateTime newDateTime = dt.addHours(12);
                String dateTimeFormat = dt.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\'');
                
                Datetime Enddt = datetime.newInstance(FieldvalueEndDate.year(), FieldvalueEndDate.month(),FieldvalueEndDate.day(),24,0,0);
                //DateTime newDateTime = dt.addHours(12);
                String EnddateTimeFormat = Enddt.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\'');
                Query = 'Select ID, Name, StageName, Opportunity_Status__c, Program_Name__c, Timestamp_Qual_Applicant__c, Owner.Name, Term__r.Name,(Select Id, CreatedDate, LastModifiedDate, Document_Type__c From Attachments__r) from Opportunity where (StageName = \'Lead\' OR StageName = \'Application\') and Program_Name__c like \'%Doctor%\' and Timestamp_Qual_Applicant__c = null AND Owner.Name != \'ITAdmin Trident\' AND ' +Field+' > '+dateTimeFormat +' AND '+ Field+' < '+EnddateTimeFormat;
            }
            system.debug('query'+Query );
            //List<opportunity> lstOpp = database.query(Query);
            con = new ApexPages.Standardsetcontroller(Database.getQueryLocator(Query));
            //this.lstOppDocuments = Querydata();     
            con.setPageSize(25);
            system.debug('pagenumber'+Con.getPageNumber());
         } 
         return null;
    }
    
     /*Public Methods */
    public List<PhdOppDocuments> lstOppDocuments { // This is used to Populate VF Search Results Table. If con is NULL, no records are returned.     
      
      get{
            //System.debug('***con.getResultSize()'+con.getResultSize());
         if(con != null)   {
           system.debug('inside page pagenumber');
            List<PhdOppDocuments> lstPhdOppDocuments = new List<PhdOppDocuments>();
            for (Opportunity Opp: (List<Opportunity>)con.getRecords()){
              PhdOppDocuments oppdoc = new PhdOppDocuments();
              Datetime LOR1;
              Datetime LOR2;
              Date LastModifieddate;
              for(Attachment__c att:Opp.Attachments__r){
                  If(att.Document_Type__c == 'Resume/CV'){
                      oppdoc.Resume = true;
                  }                  
                  
                  If(att.Document_Type__c == 'Letter of Recommendation' && LOR1 == null){
                      LOR1 = att.CreatedDate;                     
                  }
                  
                   If(att.Document_Type__c == 'Letter of Recommendation' && LOR1 != null && LOR1 != att.CreatedDate){
                      LOR2 = att.CreatedDate;
                      oppdoc.Recommendation = true;
                  }
                  
                  If(att.Document_Type__c == 'PhD-Writing Sample'){
                      oppdoc.WritingSample = true;
                  }
                  
                  If(att.Document_Type__c == 'Unofficial Transcript'){
                      oppdoc.UnoffiTranscripts = true;
                  }
                  
                  If(att.Document_Type__c == 'PhD-Short Essay'){
                      oppdoc.CoverLetter = true;
                  } 
                  
                  if(LastModifieddate == null){
                      LastModifieddate  = date.valueof(att.LastModifiedDate);
                  }  else if(att.LastModifiedDate > LastModifieddate && (att.Document_Type__c == 'Resume/CV' || att.Document_Type__c == 'Letter of Recommendation' || att.Document_Type__c == 'PhD-Writing Sample'
                              || att.Document_Type__c == 'Unofficial Transcript' || att.Document_Type__c == 'PhD-Short Essay')){
                      LastModifieddate  = date.valueof(att.LastModifiedDate);
                  }               
              
              }
              
              if(LastModifieddate != null){
                  oppdoc.Age = LastModifieddate.daysBetween(date.today());
              } else {
                  oppdoc.Age = 0;
              }
              
              oppdoc.CurrentStatus = Opp.Opportunity_Status__c;
              oppdoc.OppID = Opp.ID;
              oppdoc.OppName = Opp.Name; 
              oppdoc.Owner= Opp.Owner.Name;
              oppdoc.ProgramName = opp.Program_Name__c; 
              oppdoc.Term = Opp.term__r.Name;             
              lstPhdOppDocuments.add(oppdoc); 
            }             
              return lstPhdOppDocuments; 
            } else  
              return new List<PhdOppDocuments>(); 
          } set;
    }  
   
 //#################################### Prev/Next Page Coding Starts######################################
     
    public Boolean hasNext //Boolean to check if there are more records after the present displaying records
    {
        get
        {            
           
            return con.getHasNext();
        }
        set;
    }
 
    public Boolean hasPrevious //Boolean to check if there are more records before the present displaying records
    {
        get
        {
            return con.getHasPrevious();
        }
        set;
    }
 
    public Integer pageNumber //Page number of the current displaying records
    {
        get
        {
            return con.getPageNumber();
        }
        set;
    }

    public void previous() //Returns the previous page of records
    {
        con.previous();
        //showNoRecord = false;
    }
 
    public void next() //Returns the next page of records
    {
        con.next();
        //showNoRecord = false;
    }
    
    //#################################### Prev/Next Page Coding Ends###################################### 

}

test class snippet
 
List<PhdOppDocuments> tstphddocs = new List<PhdOppDocuments>();
        PageReference pref = page.PhdAppsProgressView; 
        Test.setCurrentPage(pref);
        List<Opportunity> opplist = [select id from Opportunity where AccountID =: acc.Id];
        ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opplist);
               
        PhdAppsProgressViewcontroller  repPOC = new PhdAppsProgressViewcontroller();
        
        
        repPOC.Field = 'Term__r.Name';
        repPOC.Fieldvalue = 'Fall 2014';
        pref = repPOC.runreport();        
        //List<PhdOppDocuments> lstOppDocuments = repPOC.getlstOppDocuments(); 
        
        //tstphddocs = new List<PhdOppDocuments>();
        
        PhdOppDocuments tstphddocs1 = new PhdOppDocuments();
        tstphddocs1.OppName = 'test';
        tstphddocs1.ProgramName= 'test';     
        tstphddocs1.Resume = true;
        tstphddocs1.Recommendation = true;
        tstphddocs1.WritingSample = true;
        tstphddocs1.unoffiTranscripts = true;
        tstphddocs1.CoverLetter = true;  
        tstphddocs1.CurrentStatus = 'test';
        tstphddocs1.OppID = '897898979'; 
        tstphddocs1.Owner = 'test';
        tstphddocs1.Age = 56;  
        tstphddocs1.Term = 'Fall 2015';
        tstphddocs.add(tstphddocs1);
        
        repPOC.Field = 'CreatedDate';
        repPOC.FieldvalueDate = Date.Today();
        repPOC.FieldvalueEndDate  = Date.Today();
        //repPOC.lstOppDocuments = tstphddocs;
        //repPOC.lstOppDocuments = tstphddocs1;
       // tstphddocs = repPOC.lstOppDocuments;
        pref = repPOC.runreport();
        
        
        repPOC.next();
        repPOC.previous();