001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.lm.leavecode.service; 017 018 import java.math.BigDecimal; 019 020 import org.junit.Assert; 021 import org.junit.Test; 022 import org.kuali.hr.lm.leavecode.LeaveCode; 023 import org.kuali.hr.test.KPMETestCase; 024 import org.kuali.hr.time.service.base.TkServiceLocator; 025 026 public class LeaveCodeServiceTest extends KPMETestCase { 027 028 @Test 029 public void testRoundHrsWithLeaveCode() { 030 LeaveCode leaveCode = new LeaveCode(); 031 leaveCode.setLeaveCode("testLC"); 032 leaveCode.setEligibleForAccrual("Y"); 033 leaveCode.setAccrualCategory("testAC"); 034 leaveCode.setLeavePlan("testLP"); 035 leaveCode.setUnitOfTime("M"); 036 037 leaveCode.setFractionalTimeAllowed("99.999"); 038 // Traditional rounding option 039 leaveCode.setRoundingOption("T"); 040 041 BigDecimal hours = new BigDecimal("12.3846"); 042 BigDecimal roundedHours = TkServiceLocator.getLeaveCodeService().roundHrsWithLeaveCode(hours, leaveCode); 043 Assert.assertTrue("Rounded hours should be 12.385", roundedHours.equals(new BigDecimal("12.385"))); 044 hours = new BigDecimal("5.1234"); 045 roundedHours = TkServiceLocator.getLeaveCodeService().roundHrsWithLeaveCode(hours, leaveCode); 046 Assert.assertTrue("Rounded hours should be 5.123", roundedHours.equals(new BigDecimal("5.123"))); 047 hours = new BigDecimal("3.0"); 048 roundedHours = TkServiceLocator.getLeaveCodeService().roundHrsWithLeaveCode(hours, leaveCode); 049 Assert.assertTrue("Rounded hours should be 3.000", roundedHours.equals(new BigDecimal("3.000"))); 050 051 // Truncate rounding option 052 leaveCode.setRoundingOption("R"); 053 054 hours = new BigDecimal("12.3846"); 055 roundedHours = TkServiceLocator.getLeaveCodeService().roundHrsWithLeaveCode(hours, leaveCode); 056 Assert.assertTrue("Rounded hours should be 12.384", roundedHours.equals(new BigDecimal("12.384"))); 057 hours = new BigDecimal("5.1234"); 058 roundedHours = TkServiceLocator.getLeaveCodeService().roundHrsWithLeaveCode(hours, leaveCode); 059 Assert.assertTrue("Rounded hours should be 5.123", roundedHours.equals(new BigDecimal("5.123"))); 060 hours = new BigDecimal("3.0"); 061 roundedHours = TkServiceLocator.getLeaveCodeService().roundHrsWithLeaveCode(hours, leaveCode); 062 Assert.assertTrue("Rounded hours should be 3.000", roundedHours.equals(new BigDecimal("3.000"))); 063 } 064 065 }