0

I have created a test class. Related list part is not covering.

On product object UP Relationship is a related list. I have craeted a product and created UP Relationship nd inserted. how to cover if product.up relationship size>0?

batch class:

global void execute(Database.BatchableContext bc, List<Equivalent_Version__c> evList){
        Equivalent_Version__c ev = evList[0];
        List<String> mappingColorwayList = new List<String>();
        mappingColorwayList.add(ev.DOM_COLORWAY__c);
        mappingColorwayList.addAll(ev.LC_COLORWAY__c.split(','));
        // Colorway matched products.
        List<ICIX_V1__ICIX_Product__c> colorwayMatchedProductsList = new List<ICIX_V1__ICIX_Product__c>();
        Map<String, Map<String, List<String>>> equivalentUniqueVsProductVsUprMap = new Map<String, Map<String, List<String>>>();
        Map<String, ContentVersion> uniqueCvMap = new Map<String, ContentVersion>();
        Map<String, String> cpcCeritificateUniqueUprMap = new Map<String, String>();
        if(mappingColorwayList.size()>0 && !mappingColorwayList.isEmpty()){
            // Collecting all the Assortment/Solid products based on colorway code
            colorwayMatchedProductsList = [SELECT Id, ICIX_V1__Finished_Product__c, Parent_Number__c, Product_Number__c, ColorwayF__c,EquivalentUnique__c,ProductType__c,
                                           (SELECT Id,ICIX_V1__Related_Account__c FROM ICIX_V1__UP_Relationship__r WHERE ICIX_V1__Status__c = 'Active' )
                                           FROM ICIX_V1__ICIX_Product__c
                                           
                                           WHERE ColorwayF__c IN: mappingColorwayList
                                           AND EquivalentUnique__c != null
                                           AND ProductType__c IN ('ASSORTMENT','SOLID')];
            
            System.debug('======colorwayMatchedProductsList======='+colorwayMatchedProductsList);
            
            if(colorwayMatchedProductsList.size()>0 && !colorwayMatchedProductsList.isEmpty()){
                //Separating products based on parent number
                for(ICIX_V1__ICIX_Product__c product: colorwayMatchedProductsList){
                    if(product.ICIX_V1__UP_Relationship__r.size()>0){
                        for(ICIX_V1__UP_Relationship__c upr: product.ICIX_V1__UP_Relationship__r){
                            if(upr.ICIX_V1__Related_Account__c != null){
                                if(!equivalentUniqueVsProductVsUprMap.containsKey(product.EquivalentUnique__c)){
                                    equivalentUniqueVsProductVsUprMap.put(product.EquivalentUnique__c, new Map<String, List<String>>());
                                    equivalentUniqueVsProductVsUprMap.get(product.EquivalentUnique__c).put(product.Id, new List<String>());
                                    equivalentUniqueVsProductVsUprMap.get(product.EquivalentUnique__c).get(product.Id).add(upr.ICIX_V1__Related_Account__c);
                                    
                                }  
                                else{
                                    if(equivalentUniqueVsProductVsUprMap.get(product.EquivalentUnique__c).keySet().contains(product.Id)){
                                        equivalentUniqueVsProductVsUprMap.get(product.EquivalentUnique__c).get(product.Id).add(upr.ICIX_V1__Related_Account__c);
                                        
                                    }
                                    else{
                                        equivalentUniqueVsProductVsUprMap.get(product.EquivalentUnique__c).put(product.Id, new List<String>());
                                        equivalentUniqueVsProductVsUprMap.get(product.EquivalentUnique__c).get(product.Id).add(upr.ICIX_V1__Related_Account__c);
                                        
                                    }
                                    
                                }
                            }
                            
                        }
                        
                    }
                    
                    
                }
                
            }
            
            System.debug('======equivalentUniqueVsProductVsUprMap======='+equivalentUniqueVsProductVsUprMap);

Test class:

@isTest
public class ColorwayCertificateGenerationBatch_Test {
    
    @isTest Static void test1(){
     

             
        ColorwayCertificateGenerationBatch cc=new ColorwayCertificateGenerationBatch();

        Equivalent_Version__c ev=new Equivalent_Version__c(Name='99',DOM_COLORWAY__c='229',LC_COLORWAY__c='230');
        insert ev;
        List<Equivalent_Version__c> evList=[SELECT Id, Name, DOM_COLORWAY__c, LC_COLORWAY__c FROM Equivalent_Version__c WHERE DOM_COLORWAY__c != null AND LC_COLORWAY__c != null];
    system.assertEquals(true, evList.size()>0);
        // Database.getQueryLocator(evList);
      
                List<String> mappingColorwayList = new List<String>();
                 mappingColorwayList.add(ev.DOM_COLORWAY__c);
        mappingColorwayList.addAll(ev.LC_COLORWAY__c.split(','));
        
      
        
            List<ICIX_V1__ICIX_Product__c> colorwayMatchedProductsList = new List<ICIX_V1__ICIX_Product__c>();
        Map<String, Map<String, List<String>>> equivalentUniqueVsProductVsUprMap = new Map<String, Map<String, List<String>>>();
        Map<String, ContentVersion> uniqueCvMap = new Map<String, ContentVersion>();
        Map<String, String> cpcCeritificateUniqueUprMap = new Map<String, String>();
        System.assertEquals(true, mappingColorwayList.size()>0);
        System.assertEquals(true, !mappingColorwayList.isEmpty());
        
        //creating account
    Account acc = new Account(Name = 'Name783', Type = 'Prospect', Facility_Name__c = 'Facil788', ICIX_V1__Status__c = 'Active', ICIX_V1__ICIX_ID__c = 'ICIX_480');
    Insert acc;
        List<ICIX_V1__ICIX_Product__c> productlst=new List<ICIX_V1__ICIX_Product__c>();
         ICIX_V1__ICIX_Product__c product=new ICIX_V1__ICIX_Product__c(Name='product1',ICIX_V1__Finished_Product__c=false,Parent_Number__c='C3994',Product_Number__c='C3994AS01',
         
                                                                       ProductType__c='ASSORTMENT;SOLID' ); 
       //product.EquivalentUnique__c!=null;
      
                 ICIX_V1__ICIX_Product__c product1=new ICIX_V1__ICIX_Product__c(Name='product2',ICIX_V1__Finished_Product__c=false,Parent_Number__c='C3995',Product_Number__c='C3995AS02',
         
                                                                       ProductType__c='ASSORTMENT;SOLID' ); 
       //product.EquivalentUnique__c!=null;
        productlst.add(product);
        productlst.add(product1);
        insert productlst;

        mappingColorwayList.add(product.ColorwayF__c);
       
        try{
            List<ICIX_V1__UP_Relationship__c> uplist=new List<ICIX_V1__UP_Relationship__c>();
        ICIX_V1__UP_Relationship__c up=new ICIX_V1__UP_Relationship__c(Name='C3994AS01_MVL',ICIX_V1__Related_Account__c=acc.id,ICIX_V1__Status__c='Active',
                                                                       ICIX_V1__Product__c=product.id,ICIX_V1__Type__c='Tag');
      
         ICIX_V1__UP_Relationship__c up1=new ICIX_V1__UP_Relationship__c(Name='C3994AS01',ICIX_V1__Related_Account__c=acc.id,ICIX_V1__Status__c='Active',
                                                                       ICIX_V1__Product__c=product.id,ICIX_V1__Type__c='Tag');
       
            uplist.add(up);
            uplist.add(up1);
            insert uplist;
        }
        catch(Exception e) {
            Boolean isException;
            if(e.getMessage().contains('Exception thrown for test class'))
            isException = true;
            system.assertEquals(isException, null);
        }
         colorwayMatchedProductsList = [SELECT Id, ICIX_V1__Finished_Product__c, Parent_Number__c, Product_Number__c, ColorwayF__c,EquivalentUnique__c,ProductType__c,
                                           (SELECT Id,ICIX_V1__Related_Account__c FROM ICIX_V1__UP_Relationship__r WHERE ICIX_V1__Status__c = 'Active' )
                                           FROM ICIX_V1__ICIX_Product__c
                                           
                                           WHERE ColorwayF__c IN: mappingColorwayList
                                           AND EquivalentUnique__c != null
                                           AND ProductType__c IN ('ASSORTMENT','SOLID')];
        system.assertEquals(true, productlst.size()>0);
        system.assertEquals(true, product.ICIX_V1__UP_Relationship__r.size()>0);
        
     Database.BatchableContext bc;
    cc.start(bc);
        Database.executebatch(new ColorwayCertificateGenerationBatch(),1);
        
    }

   
}

Could anyone help me on what/where I missed?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.