+ Start a Discussion
RSKRSK 

Test method to cover Wrapper/Inner class

Hi,

 

I am unable to figure out how i can write test methods to cover code for my wrapper/inner class. It covers only 73 % and the highlighted (in red color) part is not covered. Can any one point me in the right direction?



public class showAsPDF_Cls {

  List<Case> cs = new List<Case>();
  Id Assid;
 
   public class WrapperCases{
       public Integer Count{set;get;}
       public Case CaseDetails{set;get;}
    }
    public List<WrapperCases> wrapperlist = new List<WrapperCases>();
 
   
    public showAsPDF_Cls(ApexPages.StandardController controller) {
      Assid = apexPages.currentPage().getParameters().get('id');
      cs = [select Serial_Number__c,Product_Lookup__c,Firmware_Version__c,CaseNumber,OwnerId,Status,CreatedDate,ClosedDate,Description,Resolution_Summary__c,DTS_c__c FROM Case where AssetId =: Assid order by CreatedDate ];
     
     
      for(Integer i=0; i<cs.size();i++){
           WrapperCases wp = new WrapperCases();
           wp.Count= i+1;
           wp.CaseDetails= cs[i];
           wrapperlist.add(wp);     
      }
     
    }
    public List<WrapperCases> getList(){
      return wrapperlist;  
    }
   

     static testMethod void testPDF(){
      Account acc = new Account(Name= 'Sample Acc');
      insert acc;
      pageReference p = system.CurrentPagereference();
      p.getParameters().put('id',acc.Id);
      Case c = new Case(status='test');
      insert c;

      WrapperCases w = New WrapperCases();
      List<WrapperCases> wlist = new List<WrapperCases>();
      w.count = 1;
      w.CaseDetails= c;
      wlist.add(w);
      ApexPages.StandardController QController = new ApexPages.StandardController(c);
      showAsPDF_Cls s = new showAsPDF_Cls(QController);
      s.getList();
    }
}

 

 

Any help is highly appreciated.

 

 

Thanks,

Kumar.

Shashikant SharmaShashikant Sharma

Update your test class to, Changed statements are in red font.

 

static testMethod void testPDF(){
      //Inset Asset record, fill all mandatory fields
      Asset assetObj = new Asset(Name = 'Test Asset'); 
      insert assetObj; 

      Account acc = new Account(Name= 'Sample Acc');
      insert acc;
      pageReference p = system.CurrentPagereference();
      p.getParameters().put('id',acc.Id);
      Case c = new Case(status='test');
      c.AssetId = assetObj.id;
      insert c;
      WrapperCases w = New WrapperCases();
      List<WrapperCases> wlist = new List<WrapperCases>(); 
      w.count = 1;
      w.CaseDetails= c;
      wlist.add(w); 
      
      ApexPages.StandardController QController = new ApexPages.StandardController(assetObj);
      showAsPDF_Cls s = new showAsPDF_Cls(QController);
      s.getList();
    }

 

 

RSKRSK

Thank you for the peply. I have done it.

 

 

 

Thank you,

kumar