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
VRKVRK 

Help on write Test class for wapper class

Hi 
Application_ c employerApplication = [ select id,Party__c,Plan_Type__c,State__c from Application__c ];


 public static EmpInfoWrapper caseInfoWrapperRecord(Application__c employerApplication,Id partyId){
        InfoWrapper wrapper = new InfoWrapper();
        wrapper.partyId = employerApplication.Party__c;
        wrapper.productType = ' Life';             
        if(employerApplication.Plan_Type__c == 'SI'){
            wrapper.product = ' Issue1';
        }else if (employerApplication.Plan_Type__c == 'GI'){
            wrapper.product = ' Issue2';
        }
        wrapper.stateId = employerApplication.State__c;
        return wrapper;
    }
    
    public class InfoWrapper{
        public String partyId{get;set;}  
        public String productType{get;set;} 
        public String product{get;set;}  
        public String stateId{get;set;}   
    } 
AbhishekAbhishek (Salesforce Developers) 
I can give you the sample code for the wrapper class.

Sample Code:

Apex Class:



public class EmployeeController {
    public static void assignSequence(List<Employee__c> listEmployee, Decimal startNum) {
        Decimal initial = startNum;
        List<EmployeeWrapper> listEmployeeWrapper = new List<EmployeeWrapper>();
        
        for(Employee__c emp : listEmployee) {
            listEmployeeWrapper.add(new EmployeeWrapper(emp));
        }
        
        listEmployeeWrapper.sort();
        listEmployee.clear();
        
        for(EmployeeWrapper empW : listEmployeeWrapper) {
            listEmployee.add(empW.dirPagination);
        } 

        for(Employee__c emp : listEmployee) {                   
            emp.Sequence_in_Section__c = initial;
            initial = initial + 10;
        }        
                
        update listEmployee;
    }
    
    public class EmployeeWrapper implements Comparable {

        public Employee__c emp = new Employee__c();
        
        // Constructor
        public EmployeeWrapper(Employee__c empRecord) {
            emp = empRecord;
        }
        
        // Compare emp based on the Employee__c Age__c.
        public Integer compareTo(Object compareTo) {
            // Cast argument to EmployeeWrapper
            EmployeeWrapper compareToEmp = (EmployeeWrapper)compareTo;
            
            // The return value of 0 indicates that both elements are equal.
            Integer returnValue = 0;
            if (emp.Age__c > compareToEmp.emp.Age__c) {
                // Set return value to a positive value.
                returnValue = 1;
            } else if (emp.Directory_Heading__c < compareToEmp.emp.Age__c) {
                // Set return value to a negative value.
                returnValue = -1;
            }
            
            return returnValue;       
        }
    }
}


Test Class:


private class EmployeeControllerTest {
    static testMethod void empTest() {
        Employee__c emp = new Employee__c(Name = 'Test', Age__c = 12);
        EmployeeController.EmployeeWrapper empW = new EmployeeController.EmployeeWrapper(emp);  //Covering inner/wrapper class
        empW.compareTo(empW);  
//Covering compareTo()
    }  
}


I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.