01: /**
02: *
03: */package clime.messadmin.utils;
04:
05: import javax.servlet.jsp.JspTagException;
06:
07: import junit.framework.TestCase;
08:
09: /**
10: * @author Cédrik LIME
11: */
12: public class DateUtilsTest extends TestCase {
13: /**
14: * Number of milliseconds in a standard second: {@value}
15: */
16: public static final long MILLIS_PER_SECOND = 1000;
17: /**
18: * Number of milliseconds in a standard minute: {@value}
19: */
20: public static final long MILLIS_PER_MINUTE = 60 * MILLIS_PER_SECOND;
21: /**
22: * Number of milliseconds in a standard hour: {@value}
23: */
24: public static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE;
25: /**
26: * Number of milliseconds in a standard day: {@value}
27: */
28: public static final long MILLIS_PER_DAY = 24 * MILLIS_PER_HOUR;
29:
30: public static void main(String[] args) {
31: junit.textui.TestRunner.run(DateUtilsTest.class);
32: }
33:
34: /**
35: * Constructor for DateUtilsTest.
36: * @param name
37: */
38: public DateUtilsTest(String name) {
39: super (name);
40: }
41:
42: /**
43: * {@inheritDoc}
44: */
45: protected void setUp() throws Exception {
46: super .setUp();
47: }
48:
49: /**
50: * {@inheritDoc}
51: */
52: protected void tearDown() throws Exception {
53: super .tearDown();
54: }
55:
56: /*
57: * Test method for 'clime.messadmin.taglib.fmt.setValue(long)'
58: */
59: public void testSetValueLong() throws JspTagException {
60: long value = 3 * MILLIS_PER_SECOND;
61: String formated = DateUtils
62: .timeIntervalToFormattedString(value);
63: assertEquals("00:00:03", formated);
64:
65: value = 5 * MILLIS_PER_MINUTE;
66: formated = DateUtils.timeIntervalToFormattedString(value);
67: assertEquals("00:05:00", formated);
68:
69: value = 7 * MILLIS_PER_HOUR;
70: formated = DateUtils.timeIntervalToFormattedString(value);
71: assertEquals("07:00:00", formated);
72:
73: value = 2 * MILLIS_PER_DAY;
74: formated = DateUtils.timeIntervalToFormattedString(value);
75: assertEquals("2 days, 00:00:00", formated);
76:
77: value = 1 * MILLIS_PER_DAY + 2 * MILLIS_PER_HOUR + 42
78: * MILLIS_PER_MINUTE + 8 * MILLIS_PER_SECOND;
79: formated = DateUtils.timeIntervalToFormattedString(value);
80: assertEquals("1 day, 02:42:08", formated);
81:
82: value = 5 * MILLIS_PER_DAY + 2 * MILLIS_PER_HOUR + 42
83: * MILLIS_PER_MINUTE + 8 * MILLIS_PER_SECOND;
84: formated = DateUtils.timeIntervalToFormattedString(value);
85: assertEquals("5 days, 02:42:08", formated);
86: }
87:
88: }
|