KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joda > time > TestLocalTime_Constructors


1 /*
2  * Copyright 2001-2006 Stephen Colebourne
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.joda.time;
17
18 import java.util.Calendar JavaDoc;
19 import java.util.Date JavaDoc;
20 import java.util.GregorianCalendar JavaDoc;
21
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24
25 import org.joda.time.chrono.BuddhistChronology;
26 import org.joda.time.chrono.GJChronology;
27 import org.joda.time.chrono.ISOChronology;
28 import org.joda.time.chrono.JulianChronology;
29
30 /**
31  * This class is a Junit unit test for LocalTime.
32  *
33  * @author Stephen Colebourne
34  */

35 public class TestLocalTime_Constructors extends TestCase {
36
37     private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
38     private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
39     private static final DateTimeZone TOKYO = DateTimeZone.forID("Asia/Tokyo");
40     private static final DateTimeZone NEW_YORK = DateTimeZone.forID("America/New_York");
41     private static final ISOChronology ISO_UTC = ISOChronology.getInstanceUTC();
42     private static final JulianChronology JULIAN_LONDON = JulianChronology.getInstance(LONDON);
43     private static final JulianChronology JULIAN_PARIS = JulianChronology.getInstance(PARIS);
44     private static final JulianChronology JULIAN_UTC = JulianChronology.getInstanceUTC();
45     private static final Chronology BUDDHIST_UTC = BuddhistChronology.getInstanceUTC();
46     private static final int OFFSET_LONDON = LONDON.getOffset(0L) / DateTimeConstants.MILLIS_PER_HOUR;
47     private static final int OFFSET_PARIS = PARIS.getOffset(0L) / DateTimeConstants.MILLIS_PER_HOUR;
48
49     private long TEST_TIME_NOW =
50             10L * DateTimeConstants.MILLIS_PER_HOUR
51             + 20L * DateTimeConstants.MILLIS_PER_MINUTE
52             + 30L * DateTimeConstants.MILLIS_PER_SECOND
53             + 40L;
54
55     private long TEST_TIME1 =
56         1L * DateTimeConstants.MILLIS_PER_HOUR
57         + 2L * DateTimeConstants.MILLIS_PER_MINUTE
58         + 3L * DateTimeConstants.MILLIS_PER_SECOND
59         + 4L;
60
61     private long TEST_TIME2 =
62         1L * DateTimeConstants.MILLIS_PER_DAY
63         + 5L * DateTimeConstants.MILLIS_PER_HOUR
64         + 6L * DateTimeConstants.MILLIS_PER_MINUTE
65         + 7L * DateTimeConstants.MILLIS_PER_SECOND
66         + 8L;
67
68     private DateTimeZone zone = null;
69
70     public static void main(String JavaDoc[] args) {
71         junit.textui.TestRunner.run(suite());
72     }
73
74     public static TestSuite suite() {
75         return new TestSuite(TestLocalTime_Constructors.class);
76     }
77
78     public TestLocalTime_Constructors(String JavaDoc name) {
79         super(name);
80     }
81
82     protected void setUp() throws Exception JavaDoc {
83         DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
84         zone = DateTimeZone.getDefault();
85         DateTimeZone.setDefault(LONDON);
86         java.util.TimeZone.setDefault(LONDON.toTimeZone());
87     }
88
89     protected void tearDown() throws Exception JavaDoc {
90         DateTimeUtils.setCurrentMillisSystem();
91         DateTimeZone.setDefault(zone);
92         java.util.TimeZone.setDefault(zone.toTimeZone());
93         zone = null;
94     }
95
96     //-----------------------------------------------------------------------
97
/**
98      * Test constructor ()
99      */

100     public void testConstantMidnight() throws Throwable JavaDoc {
101         LocalTime test = LocalTime.MIDNIGHT;
102         assertEquals(ISO_UTC, test.getChronology());
103         assertEquals(0, test.getHourOfDay());
104         assertEquals(0, test.getMinuteOfHour());
105         assertEquals(0, test.getSecondOfMinute());
106         assertEquals(0, test.getMillisOfSecond());
107     }
108
109     //-----------------------------------------------------------------------
110
public void testFactory_FromCalendarFields_Calendar() throws Exception JavaDoc {
111         GregorianCalendar JavaDoc cal = new GregorianCalendar JavaDoc(1970, 1, 3, 4, 5, 6);
112         cal.set(Calendar.MILLISECOND, 7);
113         LocalTime expected = new LocalTime(4, 5, 6, 7);
114         assertEquals(expected, LocalTime.fromCalendarFields(cal));
115         try {
116             LocalTime.fromCalendarFields((Calendar JavaDoc) null);
117             fail();
118         } catch (IllegalArgumentException JavaDoc ex) {}
119     }
120
121     //-----------------------------------------------------------------------
122
public void testFactory_FromDateFields_Date() throws Exception JavaDoc {
123         GregorianCalendar JavaDoc cal = new GregorianCalendar JavaDoc(1970, 1, 3, 4, 5, 6);
124         cal.set(Calendar.MILLISECOND, 7);
125         LocalTime expected = new LocalTime(4, 5, 6, 7);
126         assertEquals(expected, LocalTime.fromDateFields(cal.getTime()));
127         try {
128             LocalTime.fromDateFields((Date JavaDoc) null);
129             fail();
130         } catch (IllegalArgumentException JavaDoc ex) {}
131     }
132
133     //-----------------------------------------------------------------------
134
public void testFactoryMillisOfDay_long() throws Throwable JavaDoc {
135         LocalTime test = LocalTime.fromMillisOfDay(TEST_TIME1);
136         assertEquals(ISO_UTC, test.getChronology());
137         assertEquals(1, test.getHourOfDay());
138         assertEquals(2, test.getMinuteOfHour());
139         assertEquals(3, test.getSecondOfMinute());
140         assertEquals(4, test.getMillisOfSecond());
141     }
142
143     //-----------------------------------------------------------------------
144
public void testFactoryMillisOfDay_long_Chronology() throws Throwable JavaDoc {
145         LocalTime test = LocalTime.fromMillisOfDay(TEST_TIME1, JULIAN_LONDON);
146         assertEquals(JULIAN_UTC, test.getChronology());
147         assertEquals(1, test.getHourOfDay());
148         assertEquals(2, test.getMinuteOfHour());
149         assertEquals(3, test.getSecondOfMinute());
150         assertEquals(4, test.getMillisOfSecond());
151     }
152
153     public void testFactoryMillisOfDay_long_nullChronology() throws Throwable JavaDoc {
154         LocalTime test = LocalTime.fromMillisOfDay(TEST_TIME1, null);
155         assertEquals(ISO_UTC, test.getChronology());
156         assertEquals(1, test.getHourOfDay());
157         assertEquals(2, test.getMinuteOfHour());
158         assertEquals(3, test.getSecondOfMinute());
159         assertEquals(4, test.getMillisOfSecond());
160     }
161
162     //-----------------------------------------------------------------------
163
public void testConstructor() throws Throwable JavaDoc {
164         LocalTime test = new LocalTime();
165         assertEquals(ISO_UTC, test.getChronology());
166         assertEquals(10 + OFFSET_LONDON, test.getHourOfDay());
167         assertEquals(20, test.getMinuteOfHour());
168         assertEquals(30, test.getSecondOfMinute());
169         assertEquals(40, test.getMillisOfSecond());
170     }
171
172     //-----------------------------------------------------------------------
173
public void testConstructor_DateTimeZone() throws Throwable JavaDoc {
174         DateTime dt = new DateTime(2005, 6, 8, 23, 59, 30, 40, LONDON);
175         DateTimeUtils.setCurrentMillisFixed(dt.getMillis());
176         // 23:59 in London is 00:59 the following day in Paris
177

178         LocalTime test = new LocalTime(LONDON);
179         assertEquals(ISO_UTC, test.getChronology());
180         assertEquals(23, test.getHourOfDay());
181         assertEquals(59, test.getMinuteOfHour());
182         assertEquals(30, test.getSecondOfMinute());
183         assertEquals(40, test.getMillisOfSecond());
184         
185         test = new LocalTime(PARIS);
186         assertEquals(ISO_UTC, test.getChronology());
187         assertEquals(0, test.getHourOfDay());
188         assertEquals(59, test.getMinuteOfHour());
189         assertEquals(30, test.getSecondOfMinute());
190         assertEquals(40, test.getMillisOfSecond());
191     }
192
193     public void testConstructor_nullDateTimeZone() throws Throwable JavaDoc {
194         DateTime dt = new DateTime(2005, 6, 8, 23, 59, 30, 40, LONDON);
195         DateTimeUtils.setCurrentMillisFixed(dt.getMillis());
196         // 23:59 in London is 00:59 the following day in Paris
197

198         LocalTime test = new LocalTime((DateTimeZone) null);
199         assertEquals(ISO_UTC, test.getChronology());
200         assertEquals(23, test.getHourOfDay());
201         assertEquals(59, test.getMinuteOfHour());
202         assertEquals(30, test.getSecondOfMinute());
203         assertEquals(40, test.getMillisOfSecond());
204     }
205
206     //-----------------------------------------------------------------------
207
public void testConstructor_Chronology() throws Throwable JavaDoc {
208         LocalTime test = new LocalTime(JULIAN_LONDON);
209         assertEquals(JULIAN_UTC, test.getChronology());
210         assertEquals(10 + OFFSET_LONDON, test.getHourOfDay());
211         assertEquals(20, test.getMinuteOfHour());
212         assertEquals(30, test.getSecondOfMinute());
213         assertEquals(40, test.getMillisOfSecond());
214     }
215
216     public void testConstructor_nullChronology() throws Throwable JavaDoc {
217         LocalTime test = new LocalTime((Chronology) null);
218         assertEquals(ISO_UTC, test.getChronology());
219         assertEquals(10 + OFFSET_LONDON, test.getHourOfDay());
220         assertEquals(20, test.getMinuteOfHour());
221         assertEquals(30, test.getSecondOfMinute());
222         assertEquals(40, test.getMillisOfSecond());
223     }
224
225     //-----------------------------------------------------------------------
226
public void testConstructor_long1() throws Throwable JavaDoc {
227         LocalTime test = new LocalTime(TEST_TIME1);
228         assertEquals(ISO_UTC, test.getChronology());
229         assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
230         assertEquals(2, test.getMinuteOfHour());
231         assertEquals(3, test.getSecondOfMinute());
232         assertEquals(4, test.getMillisOfSecond());
233     }
234
235     public void testConstructor_long2() throws Throwable JavaDoc {
236         LocalTime test = new LocalTime(TEST_TIME2);
237         assertEquals(ISO_UTC, test.getChronology());
238         assertEquals(5 + OFFSET_LONDON, test.getHourOfDay());
239         assertEquals(6, test.getMinuteOfHour());
240         assertEquals(7, test.getSecondOfMinute());
241         assertEquals(8, test.getMillisOfSecond());
242     }
243
244     //-----------------------------------------------------------------------
245
public void testConstructor_long_DateTimeZone() throws Throwable JavaDoc {
246         LocalTime test = new LocalTime(TEST_TIME1, PARIS);
247         assertEquals(ISO_UTC, test.getChronology());
248         assertEquals(1 + OFFSET_PARIS, test.getHourOfDay());
249         assertEquals(2, test.getMinuteOfHour());
250         assertEquals(3, test.getSecondOfMinute());
251         assertEquals(4, test.getMillisOfSecond());
252     }
253
254     public void testConstructor_long_nullDateTimeZone() throws Throwable JavaDoc {
255         LocalTime test = new LocalTime(TEST_TIME1, (DateTimeZone) null);
256         assertEquals(ISO_UTC, test.getChronology());
257         assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
258         assertEquals(2, test.getMinuteOfHour());
259         assertEquals(3, test.getSecondOfMinute());
260         assertEquals(4, test.getMillisOfSecond());
261     }
262
263     //-----------------------------------------------------------------------
264
public void testConstructor_long1_Chronology() throws Throwable JavaDoc {
265         LocalTime test = new LocalTime(TEST_TIME1, JULIAN_PARIS);
266         assertEquals(JULIAN_UTC, test.getChronology());
267         assertEquals(1 + OFFSET_PARIS, test.getHourOfDay());
268         assertEquals(2, test.getMinuteOfHour());
269         assertEquals(3, test.getSecondOfMinute());
270         assertEquals(4, test.getMillisOfSecond());
271     }
272
273     public void testConstructor_long2_Chronology() throws Throwable JavaDoc {
274         LocalTime test = new LocalTime(TEST_TIME2, JULIAN_LONDON);
275         assertEquals(JULIAN_UTC, test.getChronology());
276         assertEquals(5 + OFFSET_LONDON, test.getHourOfDay());
277         assertEquals(6, test.getMinuteOfHour());
278         assertEquals(7, test.getSecondOfMinute());
279         assertEquals(8, test.getMillisOfSecond());
280     }
281
282     public void testConstructor_long_nullChronology() throws Throwable JavaDoc {
283         LocalTime test = new LocalTime(TEST_TIME1, (Chronology) null);
284         assertEquals(ISO_UTC, test.getChronology());
285         assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
286         assertEquals(2, test.getMinuteOfHour());
287         assertEquals(3, test.getSecondOfMinute());
288         assertEquals(4, test.getMillisOfSecond());
289     }
290
291     //-----------------------------------------------------------------------
292
public void testConstructor_Object1() throws Throwable JavaDoc {
293         Date JavaDoc date = new Date JavaDoc(TEST_TIME1);
294         LocalTime test = new LocalTime(date);
295         assertEquals(ISO_UTC, test.getChronology());
296         assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
297         assertEquals(2, test.getMinuteOfHour());
298         assertEquals(3, test.getSecondOfMinute());
299         assertEquals(4, test.getMillisOfSecond());
300     }
301
302     public void testConstructor_Object2() throws Throwable JavaDoc {
303         Calendar JavaDoc cal = new GregorianCalendar JavaDoc();
304         cal.setTime(new Date JavaDoc(TEST_TIME1));
305         LocalTime test = new LocalTime(cal);
306         assertEquals(GJChronology.getInstanceUTC(), test.getChronology());
307         assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
308         assertEquals(2, test.getMinuteOfHour());
309         assertEquals(3, test.getSecondOfMinute());
310         assertEquals(4, test.getMillisOfSecond());
311     }
312
313     public void testConstructor_nullObject() throws Throwable JavaDoc {
314         LocalTime test = new LocalTime((Object JavaDoc) null);
315         assertEquals(ISO_UTC, test.getChronology());
316         assertEquals(10 + OFFSET_LONDON, test.getHourOfDay());
317         assertEquals(20, test.getMinuteOfHour());
318         assertEquals(30, test.getSecondOfMinute());
319         assertEquals(40, test.getMillisOfSecond());
320     }
321
322     public void testConstructor_ObjectString1() throws Throwable JavaDoc {
323         LocalTime test = new LocalTime("10:20:30.040");
324         assertEquals(ISO_UTC, test.getChronology());
325         assertEquals(10, test.getHourOfDay());
326         assertEquals(20, test.getMinuteOfHour());
327         assertEquals(30, test.getSecondOfMinute());
328         assertEquals(40, test.getMillisOfSecond());
329     }
330
331     public void testConstructor_ObjectString1Tokyo() throws Throwable JavaDoc {
332         DateTimeZone.setDefault(TOKYO);
333         LocalTime test = new LocalTime("10:20:30.040");
334         assertEquals(ISO_UTC, test.getChronology());
335         assertEquals(10, test.getHourOfDay());
336         assertEquals(20, test.getMinuteOfHour());
337         assertEquals(30, test.getSecondOfMinute());
338         assertEquals(40, test.getMillisOfSecond());
339     }
340
341     public void testConstructor_ObjectString1NewYork() throws Throwable JavaDoc {
342         DateTimeZone.setDefault(NEW_YORK);
343         LocalTime test = new LocalTime("10:20:30.040");
344         assertEquals(ISO_UTC, test.getChronology());
345         assertEquals(10, test.getHourOfDay());
346         assertEquals(20, test.getMinuteOfHour());
347         assertEquals(30, test.getSecondOfMinute());
348         assertEquals(40, test.getMillisOfSecond());
349     }
350
351     public void testConstructor_ObjectString2() throws Throwable JavaDoc {
352         LocalTime test = new LocalTime("T10:20:30.040");
353         assertEquals(ISO_UTC, test.getChronology());
354         assertEquals(10, test.getHourOfDay());
355         assertEquals(20, test.getMinuteOfHour());
356         assertEquals(30, test.getSecondOfMinute());
357         assertEquals(40, test.getMillisOfSecond());
358     }
359
360     public void testConstructor_ObjectString3() throws Throwable JavaDoc {
361         LocalTime test = new LocalTime("10:20");
362         assertEquals(ISO_UTC, test.getChronology());
363         assertEquals(10, test.getHourOfDay());
364         assertEquals(20, test.getMinuteOfHour());
365         assertEquals(0, test.getSecondOfMinute());
366         assertEquals(0, test.getMillisOfSecond());
367     }
368
369     public void testConstructor_ObjectString4() throws Throwable JavaDoc {
370         LocalTime test = new LocalTime("10");
371         assertEquals(ISO_UTC, test.getChronology());
372         assertEquals(10, test.getHourOfDay());
373         assertEquals(0, test.getMinuteOfHour());
374         assertEquals(0, test.getSecondOfMinute());
375         assertEquals(0, test.getMillisOfSecond());
376     }
377
378     public void testConstructor_ObjectStringEx1() throws Throwable JavaDoc {
379         try {
380             new LocalTime("1970-04-06");
381             fail();
382         } catch (IllegalArgumentException JavaDoc ex) {}
383     }
384
385     public void testConstructor_ObjectStringEx2() throws Throwable JavaDoc {
386         try {
387             new LocalTime("1970-04-06T+14:00");
388             fail();
389         } catch (IllegalArgumentException JavaDoc ex) {}
390     }
391
392     public void testConstructor_ObjectStringEx3() throws Throwable JavaDoc {
393         try {
394             new LocalTime("1970-04-06T10:20:30.040");
395             fail();
396         } catch (IllegalArgumentException JavaDoc ex) {}
397     }
398
399     public void testConstructor_ObjectStringEx4() throws Throwable JavaDoc {
400         try {
401             new LocalTime("1970-04-06T10:20:30.040+14:00");
402             fail();
403         } catch (IllegalArgumentException JavaDoc ex) {}
404     }
405
406     public void testConstructor_ObjectStringEx5() throws Throwable JavaDoc {
407         try {
408             new LocalTime("T10:20:30.040+04:00");
409             fail();
410         } catch (IllegalArgumentException JavaDoc ex) {}
411     }
412
413     public void testConstructor_ObjectStringEx6() throws Throwable JavaDoc {
414         try {
415             new LocalTime("10:20:30.040+04:00");
416             fail();
417         } catch (IllegalArgumentException JavaDoc ex) {}
418     }
419
420     public void testConstructor_ObjectLocalTime() throws Throwable JavaDoc {
421         LocalTime time = new LocalTime(10, 20, 30, 40, BUDDHIST_UTC);
422         LocalTime test = new LocalTime(time);
423         assertEquals(BUDDHIST_UTC, test.getChronology());
424         assertEquals(10, test.getHourOfDay());
425         assertEquals(20, test.getMinuteOfHour());
426         assertEquals(30, test.getSecondOfMinute());
427         assertEquals(40, test.getMillisOfSecond());
428     }
429
430     public void testConstructor_ObjectLocalDate() throws Throwable JavaDoc {
431         LocalDate date = new LocalDate(1970, 4, 6, BUDDHIST_UTC);
432         try {
433             new LocalTime(date);
434             fail();
435         } catch (IllegalArgumentException JavaDoc ex) {}
436     }
437
438     public void testConstructor_ObjectLocalDateTime() throws Throwable JavaDoc {
439         LocalDateTime dt = new LocalDateTime(1970, 5, 6, 10, 20, 30, 40, BUDDHIST_UTC);
440         LocalTime test = new LocalTime(dt);
441         assertEquals(BUDDHIST_UTC, test.getChronology());
442         assertEquals(10, test.getHourOfDay());
443         assertEquals(20, test.getMinuteOfHour());
444         assertEquals(30, test.getSecondOfMinute());
445         assertEquals(40, test.getMillisOfSecond());
446     }
447
448     public void testConstructor_ObjectTimeOfDay() throws Throwable JavaDoc {
449         TimeOfDay time = new TimeOfDay(10, 20, 30, 40, BUDDHIST_UTC);
450         LocalTime test = new LocalTime(time);
451         assertEquals(BUDDHIST_UTC, test.getChronology());
452         assertEquals(10, test.getHourOfDay());
453         assertEquals(20, test.getMinuteOfHour());
454         assertEquals(30, test.getSecondOfMinute());
455         assertEquals(40, test.getMillisOfSecond());
456     }
457
458     //-----------------------------------------------------------------------
459
public void testConstructor_Object1_DateTimeZone() throws Throwable JavaDoc {
460         Date JavaDoc date = new Date JavaDoc(TEST_TIME1);
461         LocalTime test = new LocalTime(date, PARIS);
462         assertEquals(ISO_UTC, test.getChronology());
463         assertEquals(1 + OFFSET_PARIS, test.getHourOfDay());
464         assertEquals(2, test.getMinuteOfHour());
465         assertEquals(3, test.getSecondOfMinute());
466         assertEquals(4, test.getMillisOfSecond());
467     }
468
469     public void testConstructor_ObjectString_DateTimeZoneLondon() throws Throwable JavaDoc {
470         LocalTime test = new LocalTime("04:20", LONDON);
471         assertEquals(4, test.getHourOfDay());
472         assertEquals(20, test.getMinuteOfHour());
473     }
474
475     public void testConstructor_ObjectString_DateTimeZoneTokyo() throws Throwable JavaDoc {
476         LocalTime test = new LocalTime("04:20", TOKYO);
477         assertEquals(ISO_UTC, test.getChronology());
478         assertEquals(4, test.getHourOfDay());
479         assertEquals(20, test.getMinuteOfHour());
480     }
481
482     public void testConstructor_ObjectString_DateTimeZoneNewYork() throws Throwable JavaDoc {
483         LocalTime test = new LocalTime("04:20", NEW_YORK);
484         assertEquals(ISO_UTC, test.getChronology());
485         assertEquals(4, test.getHourOfDay());
486         assertEquals(20, test.getMinuteOfHour());
487     }
488
489     public void testConstructor_nullObject_DateTimeZone() throws Throwable JavaDoc {
490         LocalTime test = new LocalTime((Object JavaDoc) null, PARIS);
491         assertEquals(ISO_UTC, test.getChronology());
492         assertEquals(10 + OFFSET_PARIS, test.getHourOfDay());
493         assertEquals(20, test.getMinuteOfHour());
494         assertEquals(30, test.getSecondOfMinute());
495         assertEquals(40, test.getMillisOfSecond());
496     }
497
498     public void testConstructor_Object_nullDateTimeZone() throws Throwable JavaDoc {
499         Date JavaDoc date = new Date JavaDoc(TEST_TIME1);
500         LocalTime test = new LocalTime(date, (DateTimeZone) null);
501         assertEquals(ISO_UTC, test.getChronology());
502         assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
503         assertEquals(2, test.getMinuteOfHour());
504         assertEquals(3, test.getSecondOfMinute());
505         assertEquals(4, test.getMillisOfSecond());
506     }
507
508     public void testConstructor_nullObject_nullDateTimeZone() throws Throwable JavaDoc {
509         LocalTime test = new LocalTime((Object JavaDoc) null, (DateTimeZone) null);
510         assertEquals(ISO_UTC, test.getChronology());
511         assertEquals(10 + OFFSET_LONDON, test.getHourOfDay());
512         assertEquals(20, test.getMinuteOfHour());
513         assertEquals(30, test.getSecondOfMinute());
514         assertEquals(40, test.getMillisOfSecond());
515     }
516
517     //-----------------------------------------------------------------------
518
public void testConstructor_Object1_Chronology() throws Throwable JavaDoc {
519         Date JavaDoc date = new Date JavaDoc(TEST_TIME1);
520         LocalTime test = new LocalTime(date, JULIAN_LONDON);
521         assertEquals(JULIAN_UTC, test.getChronology());
522         assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
523         assertEquals(2, test.getMinuteOfHour());
524         assertEquals(3, test.getSecondOfMinute());
525         assertEquals(4, test.getMillisOfSecond());
526     }
527
528     public void testConstructor_Object2_Chronology() throws Throwable JavaDoc {
529         LocalTime test = new LocalTime("T10:20");
530         assertEquals(10, test.getHourOfDay());
531         assertEquals(20, test.getMinuteOfHour());
532         assertEquals(0, test.getSecondOfMinute());
533         assertEquals(0, test.getMillisOfSecond());
534         
535         try {
536             new LocalTime("T1020");
537             fail();
538         } catch (IllegalArgumentException JavaDoc ex) {}
539     }
540
541     public void testConstructor_nullObject_Chronology() throws Throwable JavaDoc {
542         LocalTime test = new LocalTime((Object JavaDoc) null, JULIAN_LONDON);
543         assertEquals(JULIAN_UTC, test.getChronology());
544         assertEquals(10 + OFFSET_LONDON, test.getHourOfDay());
545         assertEquals(20, test.getMinuteOfHour());
546         assertEquals(30, test.getSecondOfMinute());
547         assertEquals(40, test.getMillisOfSecond());
548     }
549
550     public void testConstructor_Object_nullChronology() throws Throwable JavaDoc {
551         Date JavaDoc date = new Date JavaDoc(TEST_TIME1);
552         LocalTime test = new LocalTime(date, (Chronology) null);
553         assertEquals(ISO_UTC, test.getChronology());
554         assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
555         assertEquals(2, test.getMinuteOfHour());
556         assertEquals(3, test.getSecondOfMinute());
557         assertEquals(4, test.getMillisOfSecond());
558     }
559
560     public void testConstructor_nullObject_nullChronology() throws Throwable JavaDoc {
561         LocalTime test = new LocalTime((Object JavaDoc) null, (Chronology) null);
562         assertEquals(ISO_UTC, test.getChronology());
563         assertEquals(10 + OFFSET_LONDON, test.getHourOfDay());
564         assertEquals(20, test.getMinuteOfHour());
565         assertEquals(30, test.getSecondOfMinute());
566         assertEquals(40, test.getMillisOfSecond());
567     }
568
569     //-----------------------------------------------------------------------
570
public void testConstructor_int_int() throws Throwable JavaDoc {
571         LocalTime test = new LocalTime(10, 20);
572         assertEquals(ISO_UTC, test.getChronology());
573         assertEquals(10, test.getHourOfDay());
574         assertEquals(20, test.getMinuteOfHour());
575         assertEquals(0, test.getSecondOfMinute());
576         assertEquals(0, test.getMillisOfSecond());
577         try {
578             new LocalTime(-1, 20);
579             fail();
580         } catch (IllegalArgumentException JavaDoc ex) {}
581         try {
582             new LocalTime(24, 20);
583             fail();
584         } catch (IllegalArgumentException JavaDoc ex) {}
585         try {
586             new LocalTime(10, -1);
587             fail();
588         } catch (IllegalArgumentException JavaDoc ex) {}
589         try {
590             new LocalTime(10, 60);
591             fail();
592         } catch (IllegalArgumentException JavaDoc ex) {}
593     }
594
595     public void testConstructor_int_int_int() throws Throwable JavaDoc {
596         LocalTime test = new LocalTime(10, 20, 30);
597         assertEquals(ISO_UTC, test.getChronology());
598         assertEquals(10, test.getHourOfDay());
599         assertEquals(20, test.getMinuteOfHour());
600         assertEquals(30, test.getSecondOfMinute());
601         assertEquals(0, test.getMillisOfSecond());
602         try {
603             new LocalTime(-1, 20, 30);
604             fail();
605         } catch (IllegalArgumentException JavaDoc ex) {}
606         try {
607             new LocalTime(24, 20, 30);
608             fail();
609         } catch (IllegalArgumentException JavaDoc ex) {}
610         try {
611             new LocalTime(10, -1, 30);
612             fail();
613         } catch (IllegalArgumentException JavaDoc ex) {}
614         try {
615             new LocalTime(10, 60, 30);
616             fail();
617         } catch (IllegalArgumentException JavaDoc ex) {}
618         try {
619             new LocalTime(10, 20, -1);
620             fail();
621         } catch (IllegalArgumentException JavaDoc ex) {}
622         try {
623             new LocalTime(10, 20, 60);
624             fail();
625         } catch (IllegalArgumentException JavaDoc ex) {}
626     }
627
628     public void testConstructor_int_int_int_int() throws Throwable JavaDoc {
629         LocalTime test = new LocalTime(10, 20, 30, 40);
630         assertEquals(ISO_UTC, test.getChronology());
631         assertEquals(10, test.getHourOfDay());
632         assertEquals(20, test.getMinuteOfHour());
633         assertEquals(30, test.getSecondOfMinute());
634         assertEquals(40, test.getMillisOfSecond());
635         try {
636             new LocalTime(-1, 20, 30, 40);
637             fail();
638         } catch (IllegalArgumentException JavaDoc ex) {}
639         try {
640             new LocalTime(24, 20, 30, 40);
641             fail();
642         } catch (IllegalArgumentException JavaDoc ex) {}
643         try {
644             new LocalTime(10, -1, 30, 40);
645             fail();
646         } catch (IllegalArgumentException JavaDoc ex) {}
647         try {
648             new LocalTime(10, 60, 30, 40);
649             fail();
650         } catch (IllegalArgumentException JavaDoc ex) {}
651         try {
652             new LocalTime(10, 20, -1, 40);
653             fail();
654         } catch (IllegalArgumentException JavaDoc ex) {}
655         try {
656             new LocalTime(10, 20, 60, 40);
657             fail();
658         } catch (IllegalArgumentException JavaDoc ex) {}
659         try {
660             new LocalTime(10, 20, 30, -1);
661             fail();
662         } catch (IllegalArgumentException JavaDoc ex) {}
663         try {
664             new LocalTime(10, 20, 30, 1000);
665             fail();
666         } catch (IllegalArgumentException JavaDoc ex) {}
667     }
668
669     public void testConstructor_int_int_int_int_Chronology() throws Throwable JavaDoc {
670         LocalTime test = new LocalTime(10, 20, 30, 40, JULIAN_LONDON);
671         assertEquals(JULIAN_UTC, test.getChronology());
672         assertEquals(10, test.getHourOfDay());
673         assertEquals(20, test.getMinuteOfHour());
674         assertEquals(30, test.getSecondOfMinute());
675         assertEquals(40, test.getMillisOfSecond());
676         try {
677             new LocalTime(-1, 20, 30, 40, JULIAN_LONDON);
678             fail();
679         } catch (IllegalArgumentException JavaDoc ex) {}
680         try {
681             new LocalTime(24, 20, 30, 40, JULIAN_LONDON);
682             fail();
683         } catch (IllegalArgumentException JavaDoc ex) {}
684         try {
685             new LocalTime(10, -1, 30, 40, JULIAN_LONDON);
686             fail();
687         } catch (IllegalArgumentException JavaDoc ex) {}
688         try {
689             new LocalTime(10, 60, 30, 40, JULIAN_LONDON);
690             fail();
691         } catch (IllegalArgumentException JavaDoc ex) {}
692         try {
693             new LocalTime(10, 20, -1, 40, JULIAN_LONDON);
694             fail();
695         } catch (IllegalArgumentException JavaDoc ex) {}
696         try {
697             new LocalTime(10, 20, 60, 40, JULIAN_LONDON);
698             fail();
699         } catch (IllegalArgumentException JavaDoc ex) {}
700         try {
701             new LocalTime(10, 20, 30, -1, JULIAN_LONDON);
702             fail();
703         } catch (IllegalArgumentException JavaDoc ex) {}
704         try {
705             new LocalTime(10, 20, 30, 1000, JULIAN_LONDON);
706             fail();
707         } catch (IllegalArgumentException JavaDoc ex) {}
708     }
709
710     public void testConstructor_int_int_int_int_nullChronology() throws Throwable JavaDoc {
711         LocalTime test = new LocalTime(10, 20, 30, 40, null);
712         assertEquals(ISO_UTC, test.getChronology());
713         assertEquals(10, test.getHourOfDay());
714         assertEquals(20, test.getMinuteOfHour());
715         assertEquals(30, test.getSecondOfMinute());
716         assertEquals(40, test.getMillisOfSecond());
717     }
718
719 }
720
Popular Tags