View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.lm.leavecode.service;
17  
18  import java.math.BigDecimal;
19  
20  import org.junit.Assert;
21  import org.junit.Test;
22  import org.kuali.hr.lm.leavecode.LeaveCode;
23  import org.kuali.hr.test.KPMETestCase;
24  import org.kuali.hr.time.service.base.TkServiceLocator;
25  
26  public class LeaveCodeServiceTest extends KPMETestCase {
27  	
28  	@Test
29  	public void testRoundHrsWithLeaveCode() {
30  		LeaveCode leaveCode = new LeaveCode();
31  		leaveCode.setLeaveCode("testLC");
32  		leaveCode.setEligibleForAccrual("Y");
33  		leaveCode.setAccrualCategory("testAC");
34  		leaveCode.setLeavePlan("testLP");
35  		leaveCode.setUnitOfTime("M");
36  		
37  		leaveCode.setFractionalTimeAllowed("99.999");
38  		// Traditional rounding option
39  		leaveCode.setRoundingOption("T");
40  		
41  		BigDecimal hours = new BigDecimal("12.3846");
42  		BigDecimal roundedHours = TkServiceLocator.getLeaveCodeService().roundHrsWithLeaveCode(hours, leaveCode);
43  		Assert.assertTrue("Rounded hours should be 12.385", roundedHours.equals(new BigDecimal("12.385")));
44  		hours = new BigDecimal("5.1234");
45  		roundedHours = TkServiceLocator.getLeaveCodeService().roundHrsWithLeaveCode(hours, leaveCode);
46  		Assert.assertTrue("Rounded hours should be 5.123", roundedHours.equals(new BigDecimal("5.123")));
47  		hours = new BigDecimal("3.0");
48  		roundedHours = TkServiceLocator.getLeaveCodeService().roundHrsWithLeaveCode(hours, leaveCode);
49  		Assert.assertTrue("Rounded hours should be 3.000", roundedHours.equals(new BigDecimal("3.000")));
50  		
51  		// Truncate rounding option
52  		leaveCode.setRoundingOption("R");
53  		
54  		hours = new BigDecimal("12.3846");
55  		roundedHours = TkServiceLocator.getLeaveCodeService().roundHrsWithLeaveCode(hours, leaveCode);
56  		Assert.assertTrue("Rounded hours should be 12.384", roundedHours.equals(new BigDecimal("12.384")));
57  		hours = new BigDecimal("5.1234");
58  		roundedHours = TkServiceLocator.getLeaveCodeService().roundHrsWithLeaveCode(hours, leaveCode);
59  		Assert.assertTrue("Rounded hours should be 5.123", roundedHours.equals(new BigDecimal("5.123")));
60  		hours = new BigDecimal("3.0");
61  		roundedHours = TkServiceLocator.getLeaveCodeService().roundHrsWithLeaveCode(hours, leaveCode);
62  		Assert.assertTrue("Rounded hours should be 3.000", roundedHours.equals(new BigDecimal("3.000")));
63  	}
64  
65  }