01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.module.financial.service;
17:
18: import java.util.Calendar;
19:
20: import org.kuali.core.service.DateTimeService;
21: import org.kuali.kfs.context.KualiTestBase;
22: import org.kuali.kfs.context.SpringContext;
23: import org.kuali.test.ConfigureContext;
24:
25: @ConfigureContext
26: public class UniversityDateServiceTest extends KualiTestBase {
27:
28: public final void testGetCurrentFiscalYear() {
29: int currentFiscalYearAccordingToUniversityDateService = SpringContext
30: .getBean(UniversityDateService.class)
31: .getCurrentFiscalYear();
32: Calendar today = SpringContext.getBean(DateTimeService.class)
33: .getCurrentCalendar();
34: int currentFiscalYearAccordingToTest = today.get(Calendar.YEAR);
35: if (today.get(Calendar.MONTH) >= Calendar.JULY) {
36: currentFiscalYearAccordingToTest++;
37: }
38: assertEquals("Test expected: "
39: + currentFiscalYearAccordingToTest
40: + ", but UniversityDateService said: "
41: + currentFiscalYearAccordingToUniversityDateService,
42: currentFiscalYearAccordingToTest,
43: currentFiscalYearAccordingToUniversityDateService);
44: }
45:
46: public final void testGetFiscalYear_nullDate() {
47: boolean failedAsExpected = false;
48:
49: try {
50: SpringContext.getBean(UniversityDateService.class)
51: .getFiscalYear(null);
52: } catch (IllegalArgumentException e) {
53: failedAsExpected = true;
54: }
55:
56: assertTrue(failedAsExpected);
57: }
58:
59: public final void testGetFiscalYear_pastDate() throws Exception {
60: java.sql.Timestamp badTimestamp = SpringContext.getBean(
61: DateTimeService.class).convertToSqlTimestamp(
62: "01/10/1989 12:00 AM");
63: java.sql.Timestamp goodTimestamp = SpringContext.getBean(
64: DateTimeService.class).convertToSqlTimestamp(
65: "08/19/1993 12:00 AM");
66:
67: assertNull("This date shouldn't be in sh_univ_date_t",
68: SpringContext.getBean(UniversityDateService.class)
69: .getFiscalYear(badTimestamp));
70: assertEquals("This date should be in sh_univ_date_t",
71: new Integer(1994), SpringContext.getBean(
72: UniversityDateService.class).getFiscalYear(
73: goodTimestamp));
74: }
75:
76: }
|