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
Jyotirupa DasJyotirupa Das 

Can someone please help with the guidance of test method for below trigger handler method

Hi, This the method which is basically used to remove the version if any associated to contact while creating the case.
For example from contact 'Anonymous Japan Contact_v1.0.2021' some agent is trying to create a case, it will by default show him the contact as 'Anonymous Japan Contact' after case creation.

Here is the method
 public static void inquiryAssociatedToVersionContact(){
        String ConName = '';
        String ConName1 = '';
        String anonymize =  'Anonymized Contact'; //for Anonymized Contact
        String orignalname = '';
        String finalcon = '';
        String Middlename = '';
        String Firstname = '';
        set<Id> sets = new set<id>();
        List<Case> caseList = new List<Case>();
        List<Case> updatedCaseList = new List<Case>();
        List<Case> cas = trigger.new;
        for (Case c:cas){
            caseList.add(c);
            
            sets.add(c.ContactId );
            if( caseList.size()>0 && c.ContactId != NULL){
                List<Contact> cont = [select id, Name, Is_Contact_Version__c, Country__r.Name from Contact where id in :sets];            
                System.debug('@#@current Contact: ' + cont);
                for(Contact contact : cont ){
                ConName = contact.Name;
            
              if(c.LookupCountry__c == contact.Country__c && contact.Is_Contact_Version__c == TRUE )  //Is_Contact_Version__c = true
              {
                if( ConName.contains(anonymize)  ){
                        finalcon  = anonymize;
                        //Middlename = '';
                        Firstname = 'Anonymized';    
                    }
                    else{    
                    
                orignalname = 'Anonymous' + ' ' + contact.Country__r.Name + ' ' + 'Contact' ;               
                System.debug('@#@original contact: '+ orignalname);
                boolean istrue = ConName.contains(orignalname);
                 system.debug(' @#@istrue Contact Name' + istrue);
                if(istrue == True){
                    finalcon = orignalname;
                    Middlename = contact.Country__r.Name;
                }
                }       
                system.debug(' @#@final Contact Name' + finalcon);
                system.debug(' @#@final Middle Name' + Middlename);
                
            }
            //for Anonymized Contact
                if( contact.Is_Contact_Version__c == TRUE && contact.Country__r.Name == 'World'  ) {
                      orignalname = 'Anonymized Contact' ;               
                    System.debug('@#@original contact: '+ orignalname);
                    boolean istrue = ConName.contains(orignalname);
                     system.debug(' @#@istrue Contact Name' + istrue);
                    if(istrue == True){
                    finalcon = orignalname;
                    //Middlename = ;
                    Firstname = 'Anonymized';    
                    }
                       
                    system.debug(' @#@final Contact Name' + finalcon);
                    system.debug(' @#@final Middle Name' + Middlename);
                    
                }  
                }
        }
        
        List<Contact> con1 ;
        if( Middlename != ''  ){
            
        //Contact con = [select id, Name from Contact where MiddleName =:Middlename AND LastName = 'Contact'];
         con1 = [select id, Name from Contact where MiddleName =:Middlename AND LastName = 'Contact'];
            
             System.debug('@#@contact c: '+ con1);
            for(Contact con : con1){
             c.ContactId = con.id;
                    updatedCaseList.add(c) ;
            } 
        }
       if( Firstname != '' ){
             con1 = [select id, Name from Contact where FirstName =:Firstname AND LastName = 'Contact'];
           System.debug('@#@contact c: '+ con1);
           for(Contact con : con1){
            c.ContactId = con.id;
                    updatedCaseList.add(c) ;
           }   
                
            }    
        
                
                system.debug('%caselist%'+updatedCaseList);
    
    }
    
    }

Can someone please assist e how to write the test method for above