package org.kuali.kfs.pdp.batch.service.impl;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Date;

import org.easymock.EasyMock;
import org.easymock.Mock;
import org.easymock.TestSubject;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kuali.kfs.krad.util.ObjectUtils;
import org.kuali.kfs.pdp.businessobject.CustomerProfile;
import org.kuali.kfs.pdp.businessobject.FormatSelection;
import org.kuali.rice.core.api.datetime.DateTimeService;

public class AutoCheckFormatServiceImplTest {

	@TestSubject
	private AutoCheckFormatServiceImpl autoCheckFormatServ = new AutoCheckFormatServiceImpl();
	
	@Mock
	private static FormatSelection fs = new FormatSelection();
	
	@BeforeClass
	public static void setUp() throws Exception{
		fs = EasyMock.createMock(FormatSelection.class);
	}
	
	@Test
	public void testNullCustomerListInFormatSelectionWhenGeneratingFomatReadyCustomerList() throws Exception {
		EasyMock.expect(fs.getCustomerList()).andReturn(null);
		EasyMock.replay(fs);
		
		assertNotNull(autoCheckFormatServ.generateListOfCustomerProfilesReadyForFormat(fs));
		EasyMock.reset(fs);
	}
	
	@Test
	public void testGeneratingFomatReadyCustomersListWithFormatSelectionCustomersWithWrongCampus() throws Exception {
		CustomerProfile cp1 = new CustomerProfile();
		cp1.setDefaultPhysicalCampusProcessingCode("IR");
		
		ArrayList<CustomerProfile> customerList = new ArrayList<CustomerProfile>();
		customerList.add(cp1);
		
		EasyMock.expect(fs.getCustomerList()).andReturn(customerList);
		EasyMock.expect(fs.getCampus()).andReturn("BL");
		EasyMock.replay(fs);
		
		//there is only only item in the list and it is marked for format as FALSE
		assertFalse(autoCheckFormatServ.generateListOfCustomerProfilesReadyForFormat(fs).get(0).isSelectedForFormat());
		
		EasyMock.reset(fs);
	}
	
	@Test
	public void testGeneratingFomatReadyCustomersListWithFormatSelectionCustomersWithMatchingCampuses() throws Exception {
		CustomerProfile cp1 = new CustomerProfile();
		cp1.setDefaultPhysicalCampusProcessingCode("BL");
		
		ArrayList<CustomerProfile> customerList = new ArrayList<CustomerProfile>();
		customerList.add(cp1);
		
		EasyMock.expect(fs.getCustomerList()).andReturn(customerList);
		EasyMock.expect(fs.getCampus()).andReturn("BL");
		EasyMock.replay(fs);
		
		//there is only only item in the list and it is marked for format as TRUE
		assertTrue(autoCheckFormatServ.generateListOfCustomerProfilesReadyForFormat(fs).get(0).isSelectedForFormat());
		
		EasyMock.reset(fs);
	}
	
	@Test
	public void testCreationOfAutoCheckFormatWhenFormatSelectionHasStartDate() throws Exception {
		//set format selection to have date already set
		EasyMock.expect(fs.getStartDate()).andReturn(new Date()).times(3);
		EasyMock.replay(fs);
		
		DateTimeService dtService = EasyMock.createMock(DateTimeService.class);
		EasyMock.expect(dtService.toDateTimeString(fs.getStartDate())).andReturn("date time");
		autoCheckFormatServ.setDateTimeService(dtService);
		
		// the method should return a null
		assertTrue(ObjectUtils.isNull(autoCheckFormatServ.createAutoCheckFormat(fs)));
		
		EasyMock.reset(fs);
	}
	
	@Test
	public void testCreationOfAutoCheckFormatWhenFormatSelectionHasNullStartDate() throws Exception {
		
		assertTrue(true);
	}
	
}

@@ -75,16 +75,43 @@
 ert.*;%0A%0A
+import java.sql.Timestamp;%0A
 import j
@@ -380,30 +380,152 @@
 sobject.
-CustomerProfil
+AutoCheckFormat;%0Aimport org.kuali.kfs.pdp.businessobject.CustomerProfile;%0Aimport org.kuali.kfs.pdp.businessobject.DisbursementNumberRang
 e;%0Aimpor
@@ -3085,16 +3085,46 @@
 time%22);%0A
+%09%09EasyMock.replay(dtService);%0A
 %09%09autoCh
@@ -3318,32 +3318,1171 @@
 s);%0A%09%7D%0A%09%0A%09@Test%0A
+%09public void testCreateAutoCheckFormatHasSetFormatSelectionData() throws Exception %7B%0A%09%09EasyMock.expect(fs.getStartDate()).andReturn(null);%0A%09%09EasyMock.expect(fs.getCampus()).andReturn(%22BL%22);%0A%09%09%0A%09%09DateTimeService dtService = EasyMock.createMock(DateTimeService.class);%0A%09%09long currentTimeMillis = System.currentTimeMillis();%0A%09%09EasyMock.expect(dtService.getCurrentTimestamp()).andReturn(new Timestamp(currentTimeMillis));%0A%09%09EasyMock.expect(dtService.toDateString(new Timestamp(currentTimeMillis))).andReturn(new Date().toString());%0A%09%09EasyMock.replay(dtService);%0A%09%09autoCheckFormatServ.setDateTimeService(dtService);%0A%09%09%0A%09%09EasyMock.expect(fs.getRangeList()).andReturn(new ArrayList%3CDisbursementNumberRange%3E());%0A%09%09EasyMock.expect(fs.getCustomerList()).andReturn(null);%0A%09%09EasyMock.replay(fs);%0A%09%09%0A%09%09AutoCheckFormat autoCheckFormat = autoCheckFormatServ.createAutoCheckFormat(fs);%0A%09%09%0A%09%09assertEquals(autoCheckFormat.getCampus(), %22BL%22);%0A%09%09assertEquals(autoCheckFormat.getPaymentTypes(), %22all%22);%0A%09%09assertEquals(autoCheckFormat.getRanges().size(), 0);%0A%09%09assertEquals(autoCheckFormat.getCustomers().size(), 0);%0A%09%09%0A%09%09%0A%09%09EasyMock.reset(fs);%0A%09%7D%0A%09%0A%09%0A%09%0A%09@Test%0A
 %09public void tes

add more unit tests cases