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
swetha parameshwarswetha parameshwar 

Hi am unable to cover the below method in my test class

  public void setLandDRecordCount() {

        for(AggregateResult ar : [select Product__r.city_ins__SubType__c, count(ID) 
                                    from        Quote_Temp__C 
                                    where       Product__r.city_ins__Type__c = 'LAndD'
                                    and         Quote__c = :quoteId
                                    group by    Product__r.city_ins__SubType__c 
                                 ] ) 
        {
            LandDMap.put((String) ar.get('city_ins__SubType__c'), (Integer) ar.get('expr0'));
        }
    }
    
    /*********************************************************/
    /* Setect the appropriate L&D templates                  */
    /*********************************************************/
    public String  getTemplateNameForLAndD(string groupSize) {
        
        /* 
        One Product Template either ( LAndD , LAndDD or STD )   <Sub_ProductType>_Template 
        Two Product Templates ( LAndD + LAndDD Template )   
        Two Product Templates ( LandD + STD Template )
        Two Product Template ( LandDD + STD Template )

        LAndD Count
        LAndDD count
        STD Count
        Template 1 : LAndDLAndDD
        Template 2 : LAndDLAndDDSTD
        Template 3 : LAndDSTD 
        Template 3 : LAndD 
        */
        setLandDRecordCount();
        
        String LAndD_Str    = ''; 
        String LAndDD_Str   = '';
        String STD_Str      = '';
        
        String LandDTemplate = '';
        
        if (LAndDMap.get('LAndD') > 0 ) {
            LAndD_Str   = 'LAndD'; 
            LAndDD_Str = '';
        }
        if (LAndDMap.get('LAndDD') > 0) {
            LAndDD_Str  = 'LAndDD';
            LAndD_Str = '';
        }
        if ( LAndDMap.get('STD') > 0) {
            STD_Str     = 'STD';
        }
        return LAndD_Str + LAndDD_Str + STD_Str + 'Template'+groupSize;

    }
    
Best Answer chosen by swetha parameshwar
Niraj Kr SinghNiraj Kr Singh
Hi Swetha,

In your test method, your have to call this method : getTemplateNameForLAndD(groupSize);

Try like this:
@isTest
private class TestClass {

@isTest static void myTest() {
    Product__c objProd = new Product__c();
    objProd.Name = 'Test Prod';
    objProd.city_ins__Type__c = 'LAndD';
    //Provide other required fields here.

    insert objProd;

    Quote objQuote = new Quote();
    objQuote.name = 'Test Quote';
    //Provide other required fields here.

    insert objQuote;

    Quote_Temp__C objQTemp = new Quote_Temp__C();
    objQTemp.Name= '';
    objQTemp.Quote__c = objQuote.Id
    objQTemp.Product__c = objProd.Id
    objQTemp.city_ins__SubType__c = ''; //Provide value here
    //Provide other required fields here.

    insert objQTemp;
    Test.startTest();
        YourClassName insUrClass = new YourClassName(); //Give your class name here
        String groupSize = '10'; //Give here the respected value
        insUrClass.getTemplateNameForLAndD(groupSize);
    Test.stopTest();
}



Note: Written this script based on some assumption, Modify little bit if needed

plz let me know if it help you.


Thanks
Niraj