01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-app/src/test/org/sakaiproject/test/section/TimeConversionTest.java $
03: * $Id: TimeConversionTest.java 9245 2006-05-10 17:48:20Z jholtzman@berkeley.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.test.section;
21:
22: import java.sql.Time;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26: import org.sakaiproject.tool.section.jsf.JsfUtil;
27:
28: import junit.framework.Assert;
29: import junit.framework.TestCase;
30:
31: public class TimeConversionTest extends TestCase {
32: private static final Log log = LogFactory
33: .getLog(TimeConversionTest.class);
34:
35: private class TimeObject {
36: TimeObject(String startTime, boolean startTimeAm,
37: String endTime, boolean endTimeAm) {
38: this .startTime = startTime;
39: this .startTimeAm = startTimeAm;
40: this .endTime = endTime;
41: this .endTimeAm = endTimeAm;
42: }
43:
44: String startTime;
45: boolean startTimeAm;
46: String endTime;
47: boolean endTimeAm;
48: }
49:
50: public void testConvertStringToTime() throws Exception {
51: // Is midnight before 1am?
52: TimeObject time = new TimeObject("12", true, "1", true);
53: checkBefore(time, true);
54:
55: time = new TimeObject("1", true, "2", true);
56: checkBefore(time, true);
57:
58: time = new TimeObject("2", true, "1", true);
59: checkBefore(time, false);
60:
61: time = new TimeObject("9", false, "10", false);
62: checkBefore(time, true);
63:
64: time = new TimeObject("10", false, "11", false);
65: checkBefore(time, true);
66:
67: // Is 11am before noon?
68: time = new TimeObject("11", true, "12", false);
69: checkBefore(time, true);
70:
71: // Is 1pm before noon?
72: time = new TimeObject("1", false, "12", false);
73: checkBefore(time, false);
74: }
75:
76: private void checkBefore(TimeObject timeObj, boolean shouldPass) {
77: Time startTime = JsfUtil.convertStringToTime(timeObj.startTime,
78: timeObj.startTimeAm);
79: Time endTime = JsfUtil.convertStringToTime(timeObj.endTime,
80: timeObj.endTimeAm);
81:
82: boolean before = startTime.before(endTime);
83: if (shouldPass) {
84: Assert.assertTrue(before);
85: } else {
86: Assert.assertTrue(!before);
87: }
88: }
89: }
|