1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.util;
24
25 import java.util.Calendar;
26 import java.util.Date;
27 import java.util.TimeZone;
28
29 import junit.framework.TestCase;
30
31 /***
32 * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
33 */
34 public final class GregorianTest extends TestCase {
35
36 /***
37 * @param name the name of the test
38 */
39 public GregorianTest(String name) {
40 super(name);
41 }
42
43 /***
44 * test Gregorian operations.
45 */
46 public void testGregorian() {
47
48
49 Calendar date = new GregorianDate(2004, Calendar.JULY, 31);
50 Calendar time = new GregorianTime(17, 30, 15);
51 assertDate(date);
52 assertTime(time);
53
54
55 date.set(Calendar.YEAR, 2005);
56 time.set(Calendar.HOUR, 19);
57 assertDate(date);
58 assertTime(time);
59
60
61 Calendar date2 = new GregorianDate(date);
62 Calendar time2 = new GregorianTime(time);
63 time2.set(Calendar.YEAR, 1999);
64 time2.set(Calendar.MONTH, 0);
65 time2.set(Calendar.DATE, 1);
66 date2.set(Calendar.HOUR, 19);
67 date2.set(Calendar.MINUTE, 19);
68 date2.set(Calendar.SECOND, 19);
69 assertEquals(date, date2);
70 assertEquals(time, time2);
71
72
73
74 System.out.println("Gregorian test successful");
75 }
76
77 private void assertTime(Calendar time) {
78 assertFalse(time.isSet(Calendar.YEAR));
79 assertFalse(time.isSet(Calendar.MONTH));
80 assertFalse(time.isSet(Calendar.DATE));
81 }
82
83 private void assertDate(Calendar date) {
84 assertFalse(date.isSet(Calendar.HOUR));
85 assertFalse(date.isSet(Calendar.MINUTE));
86 assertFalse(date.isSet(Calendar.SECOND));
87 }
88
89 /***
90 * test integrity of class GregorianTime against method setTimeInMillis().
91 */
92 public void testGregorianTimeSetTimeInMillis() {
93 GregorianTime time1 = new GregorianTime();
94 GregorianTime time2 = new GregorianTime();
95 long timeInMillis = time1.getTimeInMillis();
96
97 time1.setTimeInMillis(timeInMillis + 1);
98 assertEquals(time1, time2);
99 assertEquals(time1.getTimeInMillis(), time2.getTimeInMillis());
100 }
101
102 /***
103 * test integrity of class GregorianTime against method setTime().
104 */
105 public void testGregorianTimeSetTime() {
106 Date date = new Date();
107 GregorianTime time1 = new GregorianTime(date);
108 GregorianTime time2 = new GregorianTime(date);
109
110 time1.setTime(new Date(date.getTime() + 1));
111 assertEquals(time1, time2);
112 assertEquals(time1.getTimeInMillis(), time2.getTimeInMillis());
113 }
114
115 /***
116 * test integrity of class GregorianTime against method setTimeZone().
117 */
118 public void testGregorianTimeSetTimeZone() {
119 Date date = new Date();
120 GregorianTime time1 = new GregorianTime(date);
121 GregorianTime time2 = new GregorianTime(date);
122
123 time1.setTimeZone(TimeZone.getTimeZone("GMT+5"));
124 assertEquals(time1, time2);
125 assertTrue(time1.getTimeInMillis() != time2.getTimeInMillis());
126 }
127
128 /***
129 * test integrity of class GregorianDate against method setTimeInMillis().
130 */
131 public void testGregorianDateSetTimeInMillis() {
132 GregorianDate date1 = new GregorianDate();
133 GregorianDate date2 = new GregorianDate();
134 long timeInMillis = date1.getTimeInMillis();
135
136 date1.setTimeInMillis(timeInMillis + 1);
137 assertEquals(date1, date2);
138 assertEquals(date1.getTimeInMillis(), date2.getTimeInMillis());
139 }
140
141 /***
142 * test integrity of class GregorianDate against method setTime().
143 */
144 public void testGregorianDateSetTime() {
145 Date date = new Date();
146 GregorianDate date1 = new GregorianDate(date);
147 GregorianDate date2 = new GregorianDate(date);
148
149 date1.setTime(new Date(date.getTime() + 1));
150 assertEquals(date1, date2);
151 assertEquals(date1.getTimeInMillis(), date2.getTimeInMillis());
152 }
153
154 /***
155 * test integrity of class GregorianDate against method setTimeZone().
156 */
157 public void testGregorianDateSetTimeZone() {
158 Date date = new Date();
159 GregorianDate date1 = new GregorianDate(date);
160 GregorianDate date2 = new GregorianDate(date);
161
162 date1.setTimeZone(TimeZone.getTimeZone("GMT+5"));
163 assertEquals(date1, date2);
164 assertEquals(date1.getTimeInMillis(), date2.getTimeInMillis());
165 }
166 }