liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
@isTest
private class ConsumApplyInventoryAutoDeleteScheduleT {
    static testMethod void myUnitTest() {
        // This test runs a scheduled job at 5 year after
        Integer a5year = Date.today().addyears(5).year();
        String cronExp = '0 0 0 3 9 ? ' + a5year;
 
        System.Test.startTest();
 
        // Schedule the test job
        String jobId = system.schedule('ConsumApplyInventoryAutoDeleteSchedule', cronExp, new ConsumApplyInventoryAutoDeleteSchedule());
 
        // Get the information from the CronTrigger API object
        CronTrigger ct = 
            [SELECT Id, CronExpression, TimesTriggered, NextFireTime
               FROM CronTrigger
              WHERE id = : jobId];
 
        // Verify the expressions are the same
        System.assertEquals(cronExp, ct.CronExpression);
 
        // Verify the job has not run
        System.assertEquals(0, ct.TimesTriggered);
 
        // Verify the next time the job will run
        System.assertEquals(a5year + '-09-03 00:00:00', String.valueOf(ct.NextFireTime));
        System.Test.stopTest();
    }
}