@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);
    }
}