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
shekhar kumar 5shekhar kumar 5 

How to cover the code of Wrapper class

Hello gyys ,
                 i am trying to make a test class  but i am facing some issue can someone help me out

Class -------------
public with sharing class NewQuoteLineItemCont {

    public Quote__c quote {get; set;}        
    public List<QuoteLineItemWrapper> qliwList { get; set; }
    public Integer glbCounter = 0;
    public Integer index {get;set;}
    public String  type {get;set;}
    
    public NewQuoteLineItemCont(){
     
        String quoteId = ApexPages.CurrentPage().getParameters().get('QuoteId');
        
        quote = ([ SELECT Id,Name FROM Quote__c WHERE Id =: quoteId ] ).get(0);                
        
        Quote_Line_Item__c item1 = new Quote_Line_Item__c();        
        item1.Quote__c = quote.Id;
        
        glbCounter = 0;
                        
        Slab__c sl = new Slab__c();
        
        qliwList = new List<QuoteLineItemWrapper> ();                
        
        QuoteLineItemWrapper qw = new QuoteLineItemWrapper ( quote , item1 , sl, glbCounter );        
        qliwList.add ( qw );  
        
        glbCounter++;
                        
    }
    
    public void setSlabTableMethod(){
    
        system.debug('===========index=============>>' + index );
        
        if ( index != null && index >= 0  ){
        
            QuoteLineItemWrapper qw = qliwList.get ( index );
                        
            if ( type != null && type.equalsIgnorecase('Slab') )
                qw.showSlab = true;
            else
                qw.showSlab = false;
        }
        
    
    }
    
    public void addProduct(){
    
        Quote_Line_Item__c item1 = new Quote_Line_Item__c();        
        item1.Quote__c = quote.Id;
        item1.Service_Tax__c = 14;
        item1.VAT_CST__c = 5;
                    
                                
        Slab__c sl = new Slab__c();                                
        
        QuoteLineItemWrapper qw = new QuoteLineItemWrapper ( quote , item1 , sl, glbCounter );        
        qliwList.add ( qw );
        
        glbCounter++;
        
        system.debug('===========qliwList==============>>'+ qliwList );
        
    
    }
    
    public PageReference saveQuoteLine(){
    
        Quote_Line_Item__c item = new Quote_Line_Item__c ();
        
        Map<Quote_Line_Item__c,List<Slab__c>> quoteSlabMap = new Map<Quote_Line_Item__c,List<Slab__c>>();
        
        List<Quote_Line_Item__c> insQuLineListWihoutSlab = new List<Quote_Line_Item__c>();
    
        for ( QuoteLineItemWrapper qw : qliwList ){
        
            System.debug('==========qw===============>>'+ qw );
            System.debug('==========qw.lineItem===============>>'+ qw.lineItem );
            System.debug('==========qw.slabList===============>>'+ qw.slabList );
                    
            item = qw.lineItem;
            
            System.debug('==========item===============>>'+ item );
            System.debug('==========item.Product__c ===============>>'+ item.Product__c  );
            System.debug('==========item.Price_Type__c===============>>'+ item.Price_Type__c);
            
            if ( item.Product__c != null ){
                        
                if ( (item.Price_Type__c).equalsIgnoreCase('Slab') ){
                                
                    List<Slab__c> slbList = new List<Slab__c>();
                    
                    for ( Slab__c sl : qw.slabList ){
                    
                        if ( sl.To__c != null && sl.Till__c != null && sl.Price__c != null )
                            slbList.add ( sl );
                    }
                    System.debug('==========item===============>>'+ item );
                    System.debug('==========slbList===============>>'+ slbList );                   
                    quoteSlabMap.put ( item , slbList );  
                                                     
                }else{
                    insQuLineListWihoutSlab.add ( item );
                }
                                        
            }                                    
        }
        
        if ( insQuLineListWihoutSlab.size() > 0 )
            INSERT insQuLineListWihoutSlab;
        
        System.debug('==========quoteSlabMap========BEFORE=======>>'+ quoteSlabMap );
        
        if ( quoteSlabMap.size() > 0 ){
        
            List<Quote_Line_Item__c> insQuLineList = new List<Quote_Line_Item__c>();
            
            System.debug('==========quoteSlabMap.keySet()===============>>'+ quoteSlabMap.keySet() );
        
            for ( Quote_Line_Item__c qline : quoteSlabMap.keySet() ){
                System.debug('==========qline===============>>'+ qline );
                insQuLineList.add ( qline );
            }
            
            INSERT insQuLineList;                                                  
            
            Integer ck = 0;
            List<Slab__c> insSbList = new List<Slab__c>();
            
            for ( List<Slab__c> sbList : quoteSlabMap.values() ){
            
                System.debug('==========sbList================>>'+ sbList );
            
                for ( Slab__c sl : sbList ){
                    System.debug('==========insQuLineList.get ( ck )================>>'+ insQuLineList.get ( ck ) );
                    sl.Quote_Line_Item__c = insQuLineList.get ( ck ).Id;
                    insSbList.add ( sl );
                }
                ck++;
            
            }
            
            System.debug('==========insSbList================>>'+ insSbList );
            
            if ( insSbList.size() > 0 )
                INSERT insSbList;
            
            
            /*List<Slab__c> insSlabList = new List<Slab__c>();
            
            for ( Quote_Line_Item__c line : quoteSlabMap.keySet() ){
            
                System.debug('==========line===============>>'+ line );
                System.debug('==========line.Id===============>>'+ line.Id );
            
                List<Slab__c> sList = quoteSlabMap.get ( line );                
                
                System.debug('==========sList===============>>'+ sList );
                
            }
            
             System.debug('==========quoteSlabMap========AFTER=======>>'+ quoteSlabMap );*/
                    
        }
    
        return ( new PageReference ('/'+quote.Id) );
    }
    
    public PageReference cancelQuoteLine(){
    
        return ( new PageReference ('/'+quote.Id) );
    }
    
    public class QuoteLineItemWrapper {
    
        public Integer counter {get;set;}
        public Quote__c quote {get;set;}
        public Quote_Line_Item__c lineItem {get;set;}
        public List<Slab__c> slabList {get;set;}
        public Boolean showSlab {get;set;}
    
        public QuoteLineItemWrapper( Quote__c q, Quote_Line_Item__c li , Slab__c s, Integer cnt){
        
            counter = cnt;
            quote = q;
            lineItem = li;
            //Slab__c slab;  
            
            slabList = new List<Slab__c>();
            showSlab = false;
            
            for ( Integer i = 0 ; i < 5 ; i++ ){
                Slab__c slab = new Slab__c(name = 'slab-'+String.valueOf(i+1));
               
                slabList.add ( slab );
            }                                   
        
        }
        
    }    

}




and my test class is follows

@istest
Private Class TestNewQuoteLineItemCont{
Static TestMethod void TestNewQuoteLineItemCont(){

 
Account acc = new account();
      acc.Name = 'Test';  
      insert acc;
          
    Opportunity__c opp=new Opportunity__c(Name='test12',Account__c=acc.id);
        insert opp;
    Quote__c lead = new Quote__c();
    lead.Description__c= 'TestLeadTest';
    lead.Opportunity_Name__c=opp.id;

    insert lead;
    
    Product__c p=new Product__c();
    p.Name='test';
    insert p;

    Quote_Line_Item__c Eve = new Quote_Line_Item__c();
    Eve.Quote__c= lead.id;
    Eve.Product__c=p.id;
    insert Eve;

    Slab__c s=new Slab__c();
    s.name='s-1';
    s.Quote_Line_Item__c=Eve.id;
    insert s;

    Slab__c s1=new Slab__c();
    s1.name='s-1';
    s1.Quote_Line_Item__c=Eve.id;
    insert s1;

   NewQuoteLineItemCont cls = new NewQuoteLineItemCont();
   cls.QuoteLineItemWrapper a = new cls.QuoteLineItemWrapper(lead,Eve,s,1);
   
 

    cls.setSlabTableMethod();
    cls.addProduct();
    cls.saveQuoteLine();
    cls.cancelQuoteLine();
    cls.index =1;
    cls.type = 'abc';
    

   }
}

Error is---------- Invalid type: cls.QuoteLineItemWrapper at line 38 column 37
Antonio ManenteAntonio Manente
You are close. You don't have to call your wrapper class on the instance of your NewQuoteLineItemCont class. It should be done like this:
 
NewQuoteLineItemCont cls = new NewQuoteLineItemCont();
NewQuoteLineItemCont.QuoteLineItemWrapper a = new NewQuoteLineItemCont.QuoteLineItemWrapper(lead,Eve,s,1);

Hope this helps!