@IsTest
private class MonthEndAutoJudgeNotUpdateBatchTest {

    /**
	 * 创建出当月所有日期
	 */
	@TestSetup
	static void makeData(){

		// 获取当前月份的第一天
		Date firstDayOfMonth = Date.today().toStartOfMonth();
		// 将月份推到下一个月
		Date nextMonth = Date.newInstance(firstDayOfMonth.year(), firstDayOfMonth.month() + 1, 1);
		// 获取当前月份最后一天
		System.debug('lastDay:' + nextMonth.addDays(-1));
		Date lastDayOfMonth = nextMonth.addDays(-1);

		List<OlympusCalendar__c> currentMonthDays = new List<OlympusCalendar__c>();

		for(Integer i = firstDayOfMonth.day(); i <= lastDayOfMonth.day(); i++){
			Date OlympusCalendarDate1 = Date.newInstance(firstDayOfMonth.year(),firstDayOfMonth.month(),i);
			OlympusCalendar__c oc1 = new OlympusCalendar__c(Date__c = OlympusCalendarDate1);
			currentMonthDays.add(oc1);
		}

		insert currentMonthDays;

	}

	static testMethod void test() {
		// 预测发货日  
		Date forecastDate = Date.today().addMonths(1);
		// 发货日
		Date delivery = forecastDate.addDays(-5);
		//14.收到合同日
		Date conReceivedDate = Date.today().addMonths(-5);

		Statu_Achievements__c sa1 = new Statu_Achievements__c(Name='测试数据1',Shipping_Scheduled_Date__c=forecastDate,
			DeliveryStatus__c='未交付',DeliveryDate__c=delivery,PaymentStatus__c='尾款支付',
			Monthly_forecast_shipping__c='本月发货预测',NM_forecast_shipping__c=null,
			UnshippedAmount__c=42529.0,ContractAmount__c=42529.0,Opportunity__c='00610000016seNJAAY',End_User_price__c=51000.0,
			InstallStatus__c='已提交',ContractReceivedDate__c=conReceivedDate);


		// 预测发货日  
		Date forecastDate2 = Date.today();
		// 发货日
		Date delivery2 = forecastDate.addDays(-1);
		//14.收到合同日
		Date conReceivedDate2 = Date.today().addMonths(-5);

		Statu_Achievements__c sa2 = new Statu_Achievements__c(Name='测试数据2',Shipping_Scheduled_Date__c=forecastDate2,
			DeliveryStatus__c='已完全交付',DeliveryDate__c=delivery2,PaymentStatus__c='尾款支付',
			Monthly_forecast_shipping__c=null,NM_forecast_shipping__c=null,
			UnshippedAmount__c=42529.0,ContractAmount__c=42529.0,Opportunity__c='00610000016seNJAAY',End_User_price__c=51000.0,
			InstallStatus__c='已提交',ContractReceivedDate__c=conReceivedDate2);

		insert new Statu_Achievements__c[]{sa1,sa2};


		System.Test.startTest();
		List<Id> ids = new List<Id>();
		ids.add(sa1.Id);
		ids.add(sa2.Id);
		System.debug('ids'+ids);
		Database.executeBatch(new MonthEndAutoJudgeNotUpdateBatch(ids));
		System.Test.stopTest();

		sa1 = [SELECT Id,Name,Monthly_forecast_shipping__c,NM_forecast_shipping__c,Shipping_Scheduled_Date__c FROM Statu_Achievements__c WHERE Id = :sa1.Id];
		System.debug('sa1.Monthly_forecast_shipping__c'+sa1.Monthly_forecast_shipping__c);
		System.debug('sa1.NM_forecast_shipping__c'+sa1.NM_forecast_shipping__c);
		// System.assertEquals(null, sa1.Monthly_forecast_shipping__c);
		// System.assertEquals('次月发货预测', sa1.NM_forecast_shipping__c);

	}
}