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
Avinash RaviAvinash Ravi 

Two lines not covered in Test class

Hi All,

I'm trying to write a test class to this class below. But I'm not able to cover lines 12 & 20. Can someone help me out please? 
 
trigger orientationDateUpdate on Registrations__c (before insert, before update) {

if(Trigger.isInsert && Trigger.isBefore)
{
    for(Registrations__c temp : Trigger.new)
    {
        if(temp.Planned_Orientation_Date__c == null)
        {
            Date date1 = Date.newinstance(1900,1,7);
            Date date2 = Date.TODAY();
            
            if(date2.day()<7 && math.MOD(date1.daysBetween(date2),7) != 0 && math.MOD(date2.month(),2) != 0)
            {
                date2 = date2.addDays(7-math.MOD(date1.daysBetween(date2),7)); 
            }
            else
            {
                date2 = Date.newInstance(date2.year(), math.MOD(date2.month(),2) != 0 ? date2.month()+2 : date2.month()+1 , 1);
                if(math.MOD(date1.daysBetween(date2),7) != 0)
                date2 = date2.addDays(7-math.MOD(date1.daysBetween(date2),7));    
            }
            system.debug('******Planned Orientation Date ***** ' + date2 );
            temp.Planned_Orientation_Date__c = date2;
        }
    }
}

}
Thanks in Advance,

Avinash
 
Best Answer chosen by Avinash Ravi
Matthew VelezMatthew Velez
Hello Avanash,

My first instinct is that you don't have a method in your test class that triggers the 'True' of the two IF Statements immediately proceeding your untested code. Add two more methods which will allow for those lines to run and you should get your coverage.

If this doesn't help, please post your test class.

If this does help, please select this answer as the best.

Cordially,

Matthew Velez

All Answers

Avinash RaviAvinash Ravi
I'm sorry it's lines 14 & 20. both similar I guess.
Matthew VelezMatthew Velez
Hello Avanash,

My first instinct is that you don't have a method in your test class that triggers the 'True' of the two IF Statements immediately proceeding your untested code. Add two more methods which will allow for those lines to run and you should get your coverage.

If this doesn't help, please post your test class.

If this does help, please select this answer as the best.

Cordially,

Matthew Velez
This was selected as the best answer