<commit_before>package org.kuali.kfs.pdp.service.impl;

import static org.junit.Assert.*;

import org.junit.Test;

public class FormatServiceImplTest {

	@Test
	public void testAddSummaryToCustomerProfileMap() {
		fail("Not yet implemented");
	}

}<commit_msg>added test cases for addSummaryToCustomerProfileMap method<commit_after>package org.kuali.kfs.pdp.service.impl;

import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.easymock.TestSubject;
import org.junit.Test;
import org.kuali.kfs.pdp.businessobject.CustomerProfile;
import org.kuali.kfs.pdp.businessobject.ProcessSummary;
import org.kuali.rice.core.api.util.type.KualiDecimal;
import org.kuali.rice.core.api.util.type.KualiInteger;

public class FormatServiceImplTest {
	

    @TestSubject
    private FormatServiceImpl formatServ = new FormatServiceImpl();

	@Test
	public void testAddSummaryToCustomerProfileMapWhenProcessSummaryIsNull() {
		HashMap<CustomerProfile, List<KualiDecimal>> custProMap = new HashMap<CustomerProfile, List<KualiDecimal>>();
		formatServ.addSummaryToCustomerProfileMap(custProMap, null);
		assertTrue(custProMap.isEmpty());
	}
	
	@Test
	public void testAddSummaryToCustomerProfileMapWhenMapIsNull() {
		HashMap<CustomerProfile, List<KualiDecimal>> custProMap = new HashMap<CustomerProfile, List<KualiDecimal>>();
		formatServ.addSummaryToCustomerProfileMap(null, null);
		//by sending in a null map should get back an instantiated HashMap
		assertTrue(custProMap.isEmpty());
	}
	
	@Test
	public void testAddSummaryToCustomerProfileMapWhenProcessSummaryHasNullCustomerProfile() throws Exception {	
		ProcessSummary processSummary = new ProcessSummary();
		processSummary.setCustomer(null);
		
		HashMap<CustomerProfile, List<KualiDecimal>> custProMap = new HashMap<CustomerProfile, List<KualiDecimal>>();
		
		formatServ.addSummaryToCustomerProfileMap(custProMap, processSummary);
		
		assertTrue(custProMap.isEmpty());
	}

	@Test
	public void testAddSummaryToCustomerProfileMapWhenProcessSummaryHasValidCustomerProfile() throws Exception {	
		ProcessSummary procSum = createBasicProcessSummary();
		CustomerProfile custProfile = procSum.getCustomer();
		HashMap<CustomerProfile, List<KualiDecimal>> custProMap = new HashMap<CustomerProfile, List<KualiDecimal>>();
		
		formatServ.addSummaryToCustomerProfileMap(custProMap, procSum);
		
		// check to make sure map was updated
		assertTrue(custProMap.size()==1);
		
		// check to see if correct key-value pair was added to map
		List<KualiDecimal> totals = custProMap.get(custProfile);
		assertTrue(totals.get(0).intValue() == 3);
		assertTrue(totals.get(1).intValue() == 350);
	}
	
	@Test
	public void testAddSummaryToCustomerProfileMapWhenSameCustomerProfileKeyExists() throws Exception {
		HashMap<CustomerProfile, List<KualiDecimal>> custProMap = new HashMap<CustomerProfile, List<KualiDecimal>>();
		createBasicSummaryMap(custProMap);

		ProcessSummary procSum = createBasicProcessSummary();
		procSum.setProcessTotalCount(new KualiInteger(2));
		procSum.setProcessTotalAmount(new KualiDecimal(150));
		CustomerProfile custProfile = procSum.getCustomer();
		
		formatServ.addSummaryToCustomerProfileMap(custProMap, procSum);
		
		assertTrue(custProMap.size()==1);
		List<KualiDecimal> totals = custProMap.get(custProfile);
		assertTrue(totals.get(0).intValue() == 5);
		assertTrue(totals.get(1).intValue() == 500);
	}

	@Test
	public void testAddSummaryToCustomerProfileMapForTwoDifferentCustomerProfiles() throws Exception {
		HashMap<CustomerProfile, List<KualiDecimal>> custProMap = new HashMap<CustomerProfile, List<KualiDecimal>>();
		createBasicSummaryMap(custProMap);

		// create a new process summary for a new customer profile
		ProcessSummary procSum = createBasicProcessSummary();
		procSum.setProcessTotalCount(new KualiInteger(2));
		procSum.setProcessTotalAmount(new KualiDecimal(150));
		CustomerProfile custProfile = procSum.getCustomer();
		custProfile.setChartCode("IR");
		procSum.setCustomer(custProfile);
		
		formatServ.addSummaryToCustomerProfileMap(custProMap, procSum);
		
		// there should be two key-value pairs in the map
		assertTrue(custProMap.size()==2);
		
		// the key-vlaue pair for the new cust profile that was added
		List<KualiDecimal> totals = custProMap.get(custProfile);
		assertTrue(totals.get(0).intValue() == 2);
		assertTrue(totals.get(1).intValue() == 150);
	}
	
	/**
	 * @param custProMap
	 */
	protected void createBasicSummaryMap(HashMap<CustomerProfile, List<KualiDecimal>> custProMap) {
		CustomerProfile custPro = new CustomerProfile();
		custPro.setChartCode("BL");
		custPro.setUnitCode("KUAL");
		custPro.setSubUnitCode("DV");
		List<KualiDecimal> totals = new ArrayList<KualiDecimal>();
		totals.add(0, new KualiDecimal(3));
		totals.add(1, new KualiDecimal(350));
		
		custProMap.put(custPro, totals);
	}
	
	/**
	 * @return
	 */
	protected ProcessSummary createBasicProcessSummary(){
		
		CustomerProfile custPro = new CustomerProfile();
		custPro.setChartCode("BL");
		custPro.setUnitCode("KUAL");
		custPro.setSubUnitCode("DV");
		
		ProcessSummary procSum = new ProcessSummary();
		procSum.setCustomer(custPro);
		procSum.setProcessTotalCount(new KualiInteger(3));
		procSum.setProcessTotalAmount(new KualiDecimal(350));
		
		return procSum;
	}
	
}


{'fraction_non_alphanumeric': 0.1075712143928036, 'fraction_numerical': 0.007308845577211395, 'mean_word_length': 6.241519674355495, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4444831', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1629, 'n_words': 304}