高章伟
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
51
52
@isTest
public class ConsumApplyInventoryAutoDeleteBatchTest {
    static ConsumTestDataFactory factory;
    // 造出选择完明细的申请
    @testSetup static void setupTestData(){
        factory = new ConsumTestDataFactory();
        factory.setupTestData();
        factory.selectDetails();
    }
    // 2日以内の場合、明細をクリアしない
    static testMethod void testMethod1() {
 
        System.Test.StartTest();
        Integer dateLimit = 2;
        Database.executeBatch(new ConsumApplyInventoryAutoDeleteBatch(dateLimit));
        System.Test.StopTest();
        // 明細削除しないの確認
        List<Consum_Apply_Equipment_Set_Detail__c> aftDltCsmList1 = [
            SELECT Id
              FROM Consum_Apply_Equipment_Set_Detail__c
        ];
        System.assertEquals(1, aftDltCsmList1.size());
        // 借出分配数変わらないの確認
        List<Asset> assetList1 = [
            SELECT Id,
                   Out_of_wh__c
            FROM Asset
        ];
        System.assertEquals(1, assetList1[0].Out_of_wh__c);
    }
 
    // 2日以上の場合、明細をクリアする
    static testMethod void testMethod2() {
        System.Test.StartTest();
        Integer dateLimit = 0;
        Database.executeBatch(new ConsumApplyInventoryAutoDeleteBatch(dateLimit));
        System.Test.StopTest();
        // 明細削除の確認
        List<Consum_Apply_Equipment_Set_Detail__c> aftDltCsmList2 = [
            SELECT Id
              FROM Consum_Apply_Equipment_Set_Detail__c
        ];
        System.assertEquals(0, aftDltCsmList2.size());
        // 借出分配数回復の確認
        List<Asset> assetList2 = [
            SELECT Id,
                   Out_of_wh__c
            FROM Asset
        ];
        System.assertEquals(0, assetList2[0].Out_of_wh__c);
    }
}