高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@isTest
private class SetOlympusCalendarWorkDayBatchTest {
    static void setupTestData(){
        OlympusCalendar__c oc = new OlympusCalendar__c();
        oc.Date__c = System.Today();
        List<OlympusCalendar__c> ocList = new List<OlympusCalendar__c> ();
        ocList.add(oc);
        for(Integer i = 1;i<=60;i++){
            OlympusCalendar__c oc_i = new OlympusCalendar__c();
            OlympusCalendar__c oc_j = new OlympusCalendar__c();
            oc_i.Date__c = System.Today().addDays(i);
            oc_j.Date__c = System.Today().addDays(-i);
            ocList.add(oc_i);
            ocList.add(oc_j);
        }
        insert ocList;
    }
    static testMethod void testExecute() {
        setupTestData();
        Test.startTest();
        SetOlympusCalendarWorkDayBatch workDayBatch = new SetOlympusCalendarWorkDayBatch();
        Date today = System.Today();
        Datetime dt = Datetime.newInstance(today.year(), today.month(), today.day());
        String dt_str = dt.format('yyyy-MM-dd');
        List<OlympusCalendar__c> ocList = [
                SELECT Date__c
                FROM OlympusCalendar__c
                WHERE Date__c =: today
            ];
        workDayBatch.start(null);
        workDayBatch.execute(null, ocList);
        workDayBatch.finish(null);
        Test.stopTest();
        String soqlString = 'SELECT Date__c ';
        for(Integer i = 1;i<=30;i++){
            soqlString += ',After_' + i + '_WorkDay__c';
            soqlString += ',Before_' + i + '_WorkDay__c';
        }
        soqlString += ' FROM OlympusCalendar__c WHERE Date__c =' + dt_str;
 
        OlympusCalendar__c oc = Database.query(soqlString);
        for(Integer i = 1;i<=30;i++){
            //System.debug('qyj:' + 'After_' + i + '_WorkDay__c' + oc.get('After_' + i + '_WorkDay__c'));
            //System.debug('qyj:' + 'Before_' + i + '_WorkDay__c' + oc.get('Before_' + i + '_WorkDay__c'));
            System.assertNotEquals(null, oc.get('After_' + i + '_WorkDay__c'));
            System.assertNotEquals(null, oc.get('Before_' + i + '_WorkDay__c'));
        }
        System.assertEquals(0, workDayBatch.emailMessages.size());
    }
}