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
Umamageshwari PalanisamyUmamageshwari Palanisamy 

How to cover a wrapper class in testclass?

I have wriiten a test class for an apex class which have a wrapper class.In the test class the wrapper class lines are not covered.Please help me out!
My apex class:
public with sharing class Rfleet_Dashboard_DeliveriesYear {

public Rfleet_Dashboard_DeliveriesYear(ApexPages.StandardController controller) {

  
   
System.Debug('>>>>>>>>>>>>>a value --> ' +selcoun);

recentdate=[SELECT Current_month__c FROM IKAM_Data__c where Current_month__c != null order by  Current_month__c Desc limit 1].Current_month__c ;
system.debug('date<<<<<<<<<'+recentdate.day());
recentyear=recentdate.year();
recentmonth=recentdate.month();


If(recentmonth==1){mOnthName='January';}
 else if(recentmonth==2){mOnthName='February';}
  else if(recentmonth==3){mOnthName='March';}
   else if(recentmonth==4){mOnthName='April';}
    else if(recentmonth==5){mOnthName='May';}
     else if(recentmonth==6){mOnthName='June';}
      else if(recentmonth==7){mOnthName='July';}
       else if(recentmonth==8){mOnthName='August';}
        else if(recentmonth==9){mOnthName='Sepetember';}
         else if(recentmonth==10){mOnthName='October';}
          else if(recentmonth==11){mOnthName='November';}
           else if(recentmonth==12){mOnthName='December';}
            else{}

france=false;
    europe=false;
    eurasia=false;
    asia=false;
    AMI=false;
    america=false;

    allcountry=true;
    }
 public String mOnthName{get;set;}
public Integer recentyear{get;set;}
public Integer recentmonth{get;set;}  
public boolean america{get;set;}
public boolean allcountry {get;set;}
public boolean AMI{get;set;}
public boolean asia{get;set;}
public boolean eurasia{get;set;}
public boolean europe{get;set;}
public boolean france{get;set;}
public string selcoun{get;set;} 
public Date recentdate{get;set;} 


public String getcont() {return selcoun;}

 
public class Month {
    public Decimal year {get; set;}
    public Decimal volume{get; set;}
    Month(Decimal year,Decimal volume) {this.year = year;this.volume= volume;}
}

public Month[] getMonths() {
    Month[] months = new Month[] {};
    System.Debug('>>>>>>>>>>>>>insid getmonths--> ' +selcoun);
    for (AggregateResult ar : [

SELECT sum( IKAM_Data__r.Countries_delivered_volume__c)Dvol,CALENDAR_YEAR(IKAM_Data__r.Current_month__c)Year FROM Country_DCVF_Volume__c  group by CALENDAR_YEAR(IKAM_Data__r.Current_month__c) order by CALENDAR_YEAR(IKAM_Data__r.Current_month__c)]) {
    months.add(new Month((Decimal )ar.get('Year'),(Decimal)ar.get('Dvol')));
    }
    system.debug('------->'+months);
    return months;
}  

      
      
    public class Month1 {
    public Decimal year {get; set;}
    public Decimal volume{get; set;}
    Month1(Decimal year,Decimal volume) {this.year = year;this.volume= volume;}
}

public Month[] getMonths1() {
    Month[] months1 = new Month[] {};
      System.Debug('>>>>>>>>>>>>>insid getmonths1--> ' +selcoun);
    for (AggregateResult ar : [SELECT sum( IKAM_Data__r.Countries_delivered_volume__c)Dvol,CALENDAR_YEAR(IKAM_Data__r.Current_month__c)Year FROM Country_DCVF_Volume__c where region__c='americas' group by CALENDAR_YEAR(IKAM_Data__r.Current_month__c) order by CALENDAR_YEAR(IKAM_Data__r.Current_month__c) ]) {                                        
    months1.add(new Month((Decimal )ar.get('Year'),(Decimal)ar.get('Dvol')));
    }
    system.debug('------->'+months1);
    return months1;
} 

 public class Month2{
    public Decimal year {get; set;}
    public Decimal volume{get; set;}
    Month2(Decimal year,Decimal volume) {this.year = year;this.volume= volume;}
}

public Month[] getMonths2() {
    Month[] months2 = new Month[] {};
      System.Debug('>>>>>>>>>>>>>insid getmonths1--> ' +selcoun);
    for (AggregateResult ar : [SELECT sum( IKAM_Data__r.Countries_delivered_volume__c)Dvol,CALENDAR_YEAR(IKAM_Data__r.Current_month__c)Year FROM Country_DCVF_Volume__c where region__c='AMI' group by CALENDAR_YEAR(IKAM_Data__r.Current_month__c) order by CALENDAR_YEAR(IKAM_Data__r.Current_month__c) ]) {                                        
    months2.add(new Month((Decimal )ar.get('Year'),(Decimal)ar.get('Dvol')));
    }
    system.debug('------->'+months2);
    return months2;
} 
  public class Month3 {
    public Decimal year{get; set;}
    public Decimal volume{get; set;}
    Month3(Decimal year,Decimal volume) {this.year = year;this.volume= volume;}
}

public Month[] getMonths3() {
    Month[] months3 = new Month[] {};
      System.Debug('>>>>>>>>>>>>>insid getmonths1--> ' +selcoun);
    for (AggregateResult ar : [SELECT sum( IKAM_Data__r.Countries_delivered_volume__c)Dvol,CALENDAR_YEAR(IKAM_Data__r.Current_month__c)Year FROM Country_DCVF_Volume__c where region__c='Asia-Pacific' group by CALENDAR_YEAR(IKAM_Data__r.Current_month__c) order by CALENDAR_YEAR(IKAM_Data__r.Current_month__c) ]) {                                        
    months3.add(new Month((Decimal )ar.get('Year'),(Decimal)ar.get('Dvol')));
    }
    system.debug('------->'+months3);
    return months3;
}  

 public class Month4 {
    public Decimal year {get; set;}
    public Decimal volume{get; set;}
    Month4(Decimal year,Decimal volume) {this.year = year;this.volume= volume;}
}

public Month[] getMonths4() {
    Month[] months4 = new Month[] {};
      System.Debug('>>>>>>>>>>>>>insid getmonths1--> ' +selcoun);
    for (AggregateResult ar : [SELECT sum( IKAM_Data__r.Countries_delivered_volume__c)Dvol,CALENDAR_YEAR(IKAM_Data__r.Current_month__c)Year FROM Country_DCVF_Volume__c where region__c='Eurasia' group by CALENDAR_YEAR(IKAM_Data__r.Current_month__c) order by CALENDAR_YEAR(IKAM_Data__r.Current_month__c) ]) {                                        
    months4.add(new Month((Decimal )ar.get('Year'),(Decimal)ar.get('Dvol')));
    }
    system.debug('------->'+months4);
    return months4;
} 

 public class Month5 {
    public Decimal year {get; set;}
    public Decimal volume{get; set;}
    Month5(Decimal year,Decimal volume) {this.year = year;this.volume= volume;}
}

public Month[] getMonths5() {
    Month[] months5 = new Month[] {};
      System.Debug('>>>>>>>>>>>>>insid getmonths1--> ' +selcoun);
    for (AggregateResult ar : [SELECT sum( IKAM_Data__r.Countries_delivered_volume__c)Dvol,CALENDAR_YEAR(IKAM_Data__r.Current_month__c)Year FROM Country_DCVF_Volume__c where region__c='Europe G9' group by CALENDAR_YEAR(IKAM_Data__r.Current_month__c) order by CALENDAR_YEAR(IKAM_Data__r.Current_month__c) ]) {                                        
    months5.add(new Month((Decimal )ar.get('Year'),(Decimal)ar.get('Dvol')));
    }
    system.debug('------->'+months5);
    return months5;
} 

 public class Month6 {
    public Decimal year {get; set;}
    public Decimal volume{get; set;}
    Month6(Decimal year,Decimal volume) {this.year = year;this.volume= volume;}
}

public Month[] getMonths6() {
    Month[] months6 = new Month[] {};
      System.Debug('>>>>>>>>>>>>>insid getmonths1--> ' +selcoun);
    for (AggregateResult ar : [SELECT sum( IKAM_Data__r.Countries_delivered_volume__c)Dvol,CALENDAR_YEAR(IKAM_Data__r.Current_month__c)Year FROM Country_DCVF_Volume__c where region__c='France' group by CALENDAR_YEAR(IKAM_Data__r.Current_month__c) order by CALENDAR_YEAR(IKAM_Data__r.Current_month__c) ]) {                                        
    months6.add(new Month((Decimal )ar.get('Year'),(Decimal)ar.get('Dvol')));
    }
    system.debug('------->'+months6);
    return months6;
}
public List<SelectOption> getRegion() {
    List<SelectOption> options = new List<SelectOption>();
    
    options .add(new SelectOption('All countries','All countries'));
    Schema.DescribeFieldResult fieldResult = Country_DCVF_Volume__c.Region__c .getDescribe();
    List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
    for( Schema.PicklistEntry f : ple)
    {
    options.add(new SelectOption(f.getLabel(), f.getValue()));
    }
    return options;
}

      
public PageReference selectedcountry() {
    System.Debug('>>>>>>>>>>>>>insid pageref--> ' +selcoun);
     france=false;
    europe=false;
    eurasia=false;
    asia=false;
    AMI=false;
    america=false;
    allcountry=true;
    getMonths();
    return null;
}

public PageReference selectedcountry1() {

 allcountry=false;
   
    america=true;
   
    getMonths1();
    return null;
}

public PageReference selectedcountry2() {
      france=false;
    europe=false;
    eurasia=false;
    asia=false;
    AMI=true;
    america=false;
    allcountry=false;
    getMonths2();
    return null;
}

public PageReference selectedcountry3() {
    france=false;
    europe=false;
    eurasia=false;
    asia=true;
    AMI=false;
    america=false;
    allcountry=false;
    getMonths3();
    return null;
}
   public PageReference selectedcountry4() {
    france=false;
    europe=false;
    eurasia=true;
    asia=false;
    AMI=false;
    america=false;
    allcountry=false;
    getMonths4();
    return null;
}
  
  public PageReference selectedcountry5() {
   france=false;
    europe=true;
    eurasia=false;
    asia=false;
    AMI=false;
    america=false;
    allcountry=false;
    getMonths5();
    return null;
}
  
  public PageReference selectedcountry6() {
    france=true;
    europe=false;
    eurasia=false;
    asia=false;
    AMI=false;
    america=false;
    allcountry=false;
    getMonths6();
    return null;
}
  

 
 }

My test class:
@isTest
public class Rfleet_Dashboard_DeliveriesYear_Test {
    public static testMethod void deliverytest(){
         Id rType =[Select id from RecordType where sObjectType = 'Account' and name='RFLEET-ACC-DCVF-RT'].id;    
        account acc = new account(name='gfgf',montant__c=0.3,recordtypeid=rType);
        insert acc;
        acc.Name='hghg';
        update acc;
        
        
        IKAM_Data__c ikam = new IKAM_Data__c();
        ikam.Annual_deliveries_target__c=85;
        ikam.Annual_global_deliveries_commitment__c=90;
        ikam.Account__c=acc.id; // insert some account and use that id here 001m000000NPFrU
        ikam.IKAM_Year__c=2015;
        test.startTest();
        insert ikam;
         
       
      country_dcvf_volume__c con = new country_dcvf_volume__c();
        con.Country__c='Algeria';
        con.Region__c='France';
        con.Insertion_date__c=system.Today();
        con.KAM__c='Prabu';
        con.Country_forecast__c=3;
        con.Delivered_volume__c=1;
        con.Parent_Account__c=acc.id;  // insert some account and use that id here  001m000000NFrdp
        con.IKAM_Data__c=ikam.id;
        insert con;
         
        
        
        pagereference vfpage = page.Rfleet_Dashboard_DeliveriesYear_Vf;
        test.setCurrentPageReference(vfpage);
        apexpages.StandardController bre = new apexpages.StandardController(con);
       // Rfleet_Dashboard_DeliveriesYear.Month1 = new Rfleet_Dashboard_DeliveriesYear.Month1();
        Rfleet_Dashboard_DeliveriesYear controller = new Rfleet_Dashboard_DeliveriesYear(bre);
        
        
        controller.getcont();
        controller.getMonths();
        controller.getMonths1();
        controller.getMonths2();
        controller.getMonths3();
        controller.getMonths4();
        controller.getMonths5();
        controller.getMonths6();
        controller.getRegion();
        controller.selectedcountry();
        controller.selectedcountry1();
        controller.selectedcountry2();
        controller.selectedcountry3();
        controller.selectedcountry4();
        controller.selectedcountry5();
        controller.selectedcountry6();
        
       
      }
  
}

The wraper class lines are not covered in test class.The uncovered lines in test class are:
User-added image
Umamageshwari PalanisamyUmamageshwari Palanisamy
Compile Error: Variable does not exist: Rfleet_Dashboard_DeliveriesYear.Month1  .I got this error.how can i resolve this ?
Nisar799Nisar799
Hi Umamageshwari Palanisamy,
First of all the following wrapper classes are not being used in your Main class.Month1
Month2
Month3
Month4
Month5
Month6Whatever the reason, may be I am not aware of your this. But if you still wanna cover all those wrapper classes then includes the following statements in your test class code.
Rfleet_Dashboard_DeliveriesYear.Month1 objMonth1 = new Rfleet_Dashboard_DeliveriesYear.Month1(2015,34.67);
Rfleet_Dashboard_DeliveriesYear.Month2 objMonth2 = new Rfleet_Dashboard_DeliveriesYear.Month2(2015,7.99);
Rfleet_Dashboard_DeliveriesYear.Month3 objMonth3 = new Rfleet_Dashboard_DeliveriesYear.Month3(2015,34.67);
Rfleet_Dashboard_DeliveriesYear.Month4 objMonth4 = new Rfleet_Dashboard_DeliveriesYear.Month4(2015,7.99);
Rfleet_Dashboard_DeliveriesYear.Month5 objMonth5 = new Rfleet_Dashboard_DeliveriesYear.Month5(2015,34.67);
Rfleet_Dashboard_DeliveriesYear.Month6 objMonth6 = new Rfleet_Dashboard_DeliveriesYear.Month6(2015,23.2);

Feel free to ask if you need further help.
Thanks,
799 Coder.