001: /*
002: * Copyright 2001-2006 Stephen Colebourne
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.joda.time;
017:
018: import java.util.Calendar;
019: import java.util.Date;
020: import java.util.GregorianCalendar;
021:
022: import junit.framework.TestCase;
023: import junit.framework.TestSuite;
024:
025: import org.joda.time.chrono.BuddhistChronology;
026: import org.joda.time.chrono.GJChronology;
027: import org.joda.time.chrono.ISOChronology;
028: import org.joda.time.chrono.JulianChronology;
029:
030: /**
031: * This class is a Junit unit test for LocalTime.
032: *
033: * @author Stephen Colebourne
034: */
035: public class TestLocalTime_Constructors extends TestCase {
036:
037: private static final DateTimeZone LONDON = DateTimeZone
038: .forID("Europe/London");
039: private static final DateTimeZone PARIS = DateTimeZone
040: .forID("Europe/Paris");
041: private static final DateTimeZone TOKYO = DateTimeZone
042: .forID("Asia/Tokyo");
043: private static final DateTimeZone NEW_YORK = DateTimeZone
044: .forID("America/New_York");
045: private static final ISOChronology ISO_UTC = ISOChronology
046: .getInstanceUTC();
047: private static final JulianChronology JULIAN_LONDON = JulianChronology
048: .getInstance(LONDON);
049: private static final JulianChronology JULIAN_PARIS = JulianChronology
050: .getInstance(PARIS);
051: private static final JulianChronology JULIAN_UTC = JulianChronology
052: .getInstanceUTC();
053: private static final Chronology BUDDHIST_UTC = BuddhistChronology
054: .getInstanceUTC();
055: private static final int OFFSET_LONDON = LONDON.getOffset(0L)
056: / DateTimeConstants.MILLIS_PER_HOUR;
057: private static final int OFFSET_PARIS = PARIS.getOffset(0L)
058: / DateTimeConstants.MILLIS_PER_HOUR;
059:
060: private long TEST_TIME_NOW = 10L
061: * DateTimeConstants.MILLIS_PER_HOUR + 20L
062: * DateTimeConstants.MILLIS_PER_MINUTE + 30L
063: * DateTimeConstants.MILLIS_PER_SECOND + 40L;
064:
065: private long TEST_TIME1 = 1L * DateTimeConstants.MILLIS_PER_HOUR
066: + 2L * DateTimeConstants.MILLIS_PER_MINUTE + 3L
067: * DateTimeConstants.MILLIS_PER_SECOND + 4L;
068:
069: private long TEST_TIME2 = 1L * DateTimeConstants.MILLIS_PER_DAY
070: + 5L * DateTimeConstants.MILLIS_PER_HOUR + 6L
071: * DateTimeConstants.MILLIS_PER_MINUTE + 7L
072: * DateTimeConstants.MILLIS_PER_SECOND + 8L;
073:
074: private DateTimeZone zone = null;
075:
076: public static void main(String[] args) {
077: junit.textui.TestRunner.run(suite());
078: }
079:
080: public static TestSuite suite() {
081: return new TestSuite(TestLocalTime_Constructors.class);
082: }
083:
084: public TestLocalTime_Constructors(String name) {
085: super (name);
086: }
087:
088: protected void setUp() throws Exception {
089: DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
090: zone = DateTimeZone.getDefault();
091: DateTimeZone.setDefault(LONDON);
092: java.util.TimeZone.setDefault(LONDON.toTimeZone());
093: }
094:
095: protected void tearDown() throws Exception {
096: DateTimeUtils.setCurrentMillisSystem();
097: DateTimeZone.setDefault(zone);
098: java.util.TimeZone.setDefault(zone.toTimeZone());
099: zone = null;
100: }
101:
102: //-----------------------------------------------------------------------
103: /**
104: * Test constructor ()
105: */
106: public void testConstantMidnight() throws Throwable {
107: LocalTime test = LocalTime.MIDNIGHT;
108: assertEquals(ISO_UTC, test.getChronology());
109: assertEquals(0, test.getHourOfDay());
110: assertEquals(0, test.getMinuteOfHour());
111: assertEquals(0, test.getSecondOfMinute());
112: assertEquals(0, test.getMillisOfSecond());
113: }
114:
115: //-----------------------------------------------------------------------
116: public void testFactory_FromCalendarFields_Calendar()
117: throws Exception {
118: GregorianCalendar cal = new GregorianCalendar(1970, 1, 3, 4, 5,
119: 6);
120: cal.set(Calendar.MILLISECOND, 7);
121: LocalTime expected = new LocalTime(4, 5, 6, 7);
122: assertEquals(expected, LocalTime.fromCalendarFields(cal));
123: try {
124: LocalTime.fromCalendarFields((Calendar) null);
125: fail();
126: } catch (IllegalArgumentException ex) {
127: }
128: }
129:
130: //-----------------------------------------------------------------------
131: public void testFactory_FromDateFields_Date() throws Exception {
132: GregorianCalendar cal = new GregorianCalendar(1970, 1, 3, 4, 5,
133: 6);
134: cal.set(Calendar.MILLISECOND, 7);
135: LocalTime expected = new LocalTime(4, 5, 6, 7);
136: assertEquals(expected, LocalTime.fromDateFields(cal.getTime()));
137: try {
138: LocalTime.fromDateFields((Date) null);
139: fail();
140: } catch (IllegalArgumentException ex) {
141: }
142: }
143:
144: //-----------------------------------------------------------------------
145: public void testFactoryMillisOfDay_long() throws Throwable {
146: LocalTime test = LocalTime.fromMillisOfDay(TEST_TIME1);
147: assertEquals(ISO_UTC, test.getChronology());
148: assertEquals(1, test.getHourOfDay());
149: assertEquals(2, test.getMinuteOfHour());
150: assertEquals(3, test.getSecondOfMinute());
151: assertEquals(4, test.getMillisOfSecond());
152: }
153:
154: //-----------------------------------------------------------------------
155: public void testFactoryMillisOfDay_long_Chronology()
156: throws Throwable {
157: LocalTime test = LocalTime.fromMillisOfDay(TEST_TIME1,
158: JULIAN_LONDON);
159: assertEquals(JULIAN_UTC, test.getChronology());
160: assertEquals(1, test.getHourOfDay());
161: assertEquals(2, test.getMinuteOfHour());
162: assertEquals(3, test.getSecondOfMinute());
163: assertEquals(4, test.getMillisOfSecond());
164: }
165:
166: public void testFactoryMillisOfDay_long_nullChronology()
167: throws Throwable {
168: LocalTime test = LocalTime.fromMillisOfDay(TEST_TIME1, null);
169: assertEquals(ISO_UTC, test.getChronology());
170: assertEquals(1, test.getHourOfDay());
171: assertEquals(2, test.getMinuteOfHour());
172: assertEquals(3, test.getSecondOfMinute());
173: assertEquals(4, test.getMillisOfSecond());
174: }
175:
176: //-----------------------------------------------------------------------
177: public void testConstructor() throws Throwable {
178: LocalTime test = new LocalTime();
179: assertEquals(ISO_UTC, test.getChronology());
180: assertEquals(10 + OFFSET_LONDON, test.getHourOfDay());
181: assertEquals(20, test.getMinuteOfHour());
182: assertEquals(30, test.getSecondOfMinute());
183: assertEquals(40, test.getMillisOfSecond());
184: }
185:
186: //-----------------------------------------------------------------------
187: public void testConstructor_DateTimeZone() throws Throwable {
188: DateTime dt = new DateTime(2005, 6, 8, 23, 59, 30, 40, LONDON);
189: DateTimeUtils.setCurrentMillisFixed(dt.getMillis());
190: // 23:59 in London is 00:59 the following day in Paris
191:
192: LocalTime test = new LocalTime(LONDON);
193: assertEquals(ISO_UTC, test.getChronology());
194: assertEquals(23, test.getHourOfDay());
195: assertEquals(59, test.getMinuteOfHour());
196: assertEquals(30, test.getSecondOfMinute());
197: assertEquals(40, test.getMillisOfSecond());
198:
199: test = new LocalTime(PARIS);
200: assertEquals(ISO_UTC, test.getChronology());
201: assertEquals(0, test.getHourOfDay());
202: assertEquals(59, test.getMinuteOfHour());
203: assertEquals(30, test.getSecondOfMinute());
204: assertEquals(40, test.getMillisOfSecond());
205: }
206:
207: public void testConstructor_nullDateTimeZone() throws Throwable {
208: DateTime dt = new DateTime(2005, 6, 8, 23, 59, 30, 40, LONDON);
209: DateTimeUtils.setCurrentMillisFixed(dt.getMillis());
210: // 23:59 in London is 00:59 the following day in Paris
211:
212: LocalTime test = new LocalTime((DateTimeZone) null);
213: assertEquals(ISO_UTC, test.getChronology());
214: assertEquals(23, test.getHourOfDay());
215: assertEquals(59, test.getMinuteOfHour());
216: assertEquals(30, test.getSecondOfMinute());
217: assertEquals(40, test.getMillisOfSecond());
218: }
219:
220: //-----------------------------------------------------------------------
221: public void testConstructor_Chronology() throws Throwable {
222: LocalTime test = new LocalTime(JULIAN_LONDON);
223: assertEquals(JULIAN_UTC, test.getChronology());
224: assertEquals(10 + OFFSET_LONDON, test.getHourOfDay());
225: assertEquals(20, test.getMinuteOfHour());
226: assertEquals(30, test.getSecondOfMinute());
227: assertEquals(40, test.getMillisOfSecond());
228: }
229:
230: public void testConstructor_nullChronology() throws Throwable {
231: LocalTime test = new LocalTime((Chronology) null);
232: assertEquals(ISO_UTC, test.getChronology());
233: assertEquals(10 + OFFSET_LONDON, test.getHourOfDay());
234: assertEquals(20, test.getMinuteOfHour());
235: assertEquals(30, test.getSecondOfMinute());
236: assertEquals(40, test.getMillisOfSecond());
237: }
238:
239: //-----------------------------------------------------------------------
240: public void testConstructor_long1() throws Throwable {
241: LocalTime test = new LocalTime(TEST_TIME1);
242: assertEquals(ISO_UTC, test.getChronology());
243: assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
244: assertEquals(2, test.getMinuteOfHour());
245: assertEquals(3, test.getSecondOfMinute());
246: assertEquals(4, test.getMillisOfSecond());
247: }
248:
249: public void testConstructor_long2() throws Throwable {
250: LocalTime test = new LocalTime(TEST_TIME2);
251: assertEquals(ISO_UTC, test.getChronology());
252: assertEquals(5 + OFFSET_LONDON, test.getHourOfDay());
253: assertEquals(6, test.getMinuteOfHour());
254: assertEquals(7, test.getSecondOfMinute());
255: assertEquals(8, test.getMillisOfSecond());
256: }
257:
258: //-----------------------------------------------------------------------
259: public void testConstructor_long_DateTimeZone() throws Throwable {
260: LocalTime test = new LocalTime(TEST_TIME1, PARIS);
261: assertEquals(ISO_UTC, test.getChronology());
262: assertEquals(1 + OFFSET_PARIS, test.getHourOfDay());
263: assertEquals(2, test.getMinuteOfHour());
264: assertEquals(3, test.getSecondOfMinute());
265: assertEquals(4, test.getMillisOfSecond());
266: }
267:
268: public void testConstructor_long_DateTimeZone_2() throws Throwable {
269: DateTime dt = new DateTime(2007, 6, 9, 1, 2, 3, 4, PARIS);
270: DateTime dtUTC = new DateTime(1970, 1, 1, 1, 2, 3, 4,
271: DateTimeZone.UTC);
272:
273: LocalTime test = new LocalTime(dt.getMillis(), PARIS);
274: assertEquals(ISO_UTC, test.getChronology());
275: assertEquals(1, test.getHourOfDay());
276: assertEquals(2, test.getMinuteOfHour());
277: assertEquals(3, test.getSecondOfMinute());
278: assertEquals(4, test.getMillisOfSecond());
279: assertEquals(dtUTC.getMillis(), test.getLocalMillis());
280: }
281:
282: public void testConstructor_long_nullDateTimeZone()
283: throws Throwable {
284: LocalTime test = new LocalTime(TEST_TIME1, (DateTimeZone) null);
285: assertEquals(ISO_UTC, test.getChronology());
286: assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
287: assertEquals(2, test.getMinuteOfHour());
288: assertEquals(3, test.getSecondOfMinute());
289: assertEquals(4, test.getMillisOfSecond());
290: }
291:
292: //-----------------------------------------------------------------------
293: public void testConstructor_long1_Chronology() throws Throwable {
294: LocalTime test = new LocalTime(TEST_TIME1, JULIAN_PARIS);
295: assertEquals(JULIAN_UTC, test.getChronology());
296: assertEquals(1 + OFFSET_PARIS, test.getHourOfDay());
297: assertEquals(2, test.getMinuteOfHour());
298: assertEquals(3, test.getSecondOfMinute());
299: assertEquals(4, test.getMillisOfSecond());
300: }
301:
302: public void testConstructor_long2_Chronology() throws Throwable {
303: LocalTime test = new LocalTime(TEST_TIME2, JULIAN_LONDON);
304: assertEquals(JULIAN_UTC, test.getChronology());
305: assertEquals(5 + OFFSET_LONDON, test.getHourOfDay());
306: assertEquals(6, test.getMinuteOfHour());
307: assertEquals(7, test.getSecondOfMinute());
308: assertEquals(8, test.getMillisOfSecond());
309: }
310:
311: public void testConstructor_long_nullChronology() throws Throwable {
312: LocalTime test = new LocalTime(TEST_TIME1, (Chronology) null);
313: assertEquals(ISO_UTC, test.getChronology());
314: assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
315: assertEquals(2, test.getMinuteOfHour());
316: assertEquals(3, test.getSecondOfMinute());
317: assertEquals(4, test.getMillisOfSecond());
318: }
319:
320: //-----------------------------------------------------------------------
321: public void testConstructor_Object1() throws Throwable {
322: Date date = new Date(TEST_TIME1);
323: LocalTime test = new LocalTime(date);
324: assertEquals(ISO_UTC, test.getChronology());
325: assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
326: assertEquals(2, test.getMinuteOfHour());
327: assertEquals(3, test.getSecondOfMinute());
328: assertEquals(4, test.getMillisOfSecond());
329: }
330:
331: public void testConstructor_Object2() throws Throwable {
332: Calendar cal = new GregorianCalendar();
333: cal.setTime(new Date(TEST_TIME1));
334: LocalTime test = new LocalTime(cal);
335: assertEquals(GJChronology.getInstanceUTC(), test
336: .getChronology());
337: assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
338: assertEquals(2, test.getMinuteOfHour());
339: assertEquals(3, test.getSecondOfMinute());
340: assertEquals(4, test.getMillisOfSecond());
341: }
342:
343: public void testConstructor_nullObject() throws Throwable {
344: LocalTime test = new LocalTime((Object) null);
345: assertEquals(ISO_UTC, test.getChronology());
346: assertEquals(10 + OFFSET_LONDON, test.getHourOfDay());
347: assertEquals(20, test.getMinuteOfHour());
348: assertEquals(30, test.getSecondOfMinute());
349: assertEquals(40, test.getMillisOfSecond());
350: }
351:
352: public void testConstructor_ObjectString1() throws Throwable {
353: LocalTime test = new LocalTime("10:20:30.040");
354: assertEquals(ISO_UTC, test.getChronology());
355: assertEquals(10, test.getHourOfDay());
356: assertEquals(20, test.getMinuteOfHour());
357: assertEquals(30, test.getSecondOfMinute());
358: assertEquals(40, test.getMillisOfSecond());
359: }
360:
361: public void testConstructor_ObjectString1Tokyo() throws Throwable {
362: DateTimeZone.setDefault(TOKYO);
363: LocalTime test = new LocalTime("10:20:30.040");
364: assertEquals(ISO_UTC, test.getChronology());
365: assertEquals(10, test.getHourOfDay());
366: assertEquals(20, test.getMinuteOfHour());
367: assertEquals(30, test.getSecondOfMinute());
368: assertEquals(40, test.getMillisOfSecond());
369: }
370:
371: public void testConstructor_ObjectString1NewYork() throws Throwable {
372: DateTimeZone.setDefault(NEW_YORK);
373: LocalTime test = new LocalTime("10:20:30.040");
374: assertEquals(ISO_UTC, test.getChronology());
375: assertEquals(10, test.getHourOfDay());
376: assertEquals(20, test.getMinuteOfHour());
377: assertEquals(30, test.getSecondOfMinute());
378: assertEquals(40, test.getMillisOfSecond());
379: }
380:
381: public void testConstructor_ObjectString2() throws Throwable {
382: LocalTime test = new LocalTime("T10:20:30.040");
383: assertEquals(ISO_UTC, test.getChronology());
384: assertEquals(10, test.getHourOfDay());
385: assertEquals(20, test.getMinuteOfHour());
386: assertEquals(30, test.getSecondOfMinute());
387: assertEquals(40, test.getMillisOfSecond());
388: }
389:
390: public void testConstructor_ObjectString3() throws Throwable {
391: LocalTime test = new LocalTime("10:20");
392: assertEquals(ISO_UTC, test.getChronology());
393: assertEquals(10, test.getHourOfDay());
394: assertEquals(20, test.getMinuteOfHour());
395: assertEquals(0, test.getSecondOfMinute());
396: assertEquals(0, test.getMillisOfSecond());
397: }
398:
399: public void testConstructor_ObjectString4() throws Throwable {
400: LocalTime test = new LocalTime("10");
401: assertEquals(ISO_UTC, test.getChronology());
402: assertEquals(10, test.getHourOfDay());
403: assertEquals(0, test.getMinuteOfHour());
404: assertEquals(0, test.getSecondOfMinute());
405: assertEquals(0, test.getMillisOfSecond());
406: }
407:
408: public void testConstructor_ObjectStringEx1() throws Throwable {
409: try {
410: new LocalTime("1970-04-06");
411: fail();
412: } catch (IllegalArgumentException ex) {
413: }
414: }
415:
416: public void testConstructor_ObjectStringEx2() throws Throwable {
417: try {
418: new LocalTime("1970-04-06T+14:00");
419: fail();
420: } catch (IllegalArgumentException ex) {
421: }
422: }
423:
424: public void testConstructor_ObjectStringEx3() throws Throwable {
425: try {
426: new LocalTime("1970-04-06T10:20:30.040");
427: fail();
428: } catch (IllegalArgumentException ex) {
429: }
430: }
431:
432: public void testConstructor_ObjectStringEx4() throws Throwable {
433: try {
434: new LocalTime("1970-04-06T10:20:30.040+14:00");
435: fail();
436: } catch (IllegalArgumentException ex) {
437: }
438: }
439:
440: public void testConstructor_ObjectStringEx5() throws Throwable {
441: try {
442: new LocalTime("T10:20:30.040+04:00");
443: fail();
444: } catch (IllegalArgumentException ex) {
445: }
446: }
447:
448: public void testConstructor_ObjectStringEx6() throws Throwable {
449: try {
450: new LocalTime("10:20:30.040+04:00");
451: fail();
452: } catch (IllegalArgumentException ex) {
453: }
454: }
455:
456: public void testConstructor_ObjectLocalTime() throws Throwable {
457: LocalTime time = new LocalTime(10, 20, 30, 40, BUDDHIST_UTC);
458: LocalTime test = new LocalTime(time);
459: assertEquals(BUDDHIST_UTC, test.getChronology());
460: assertEquals(10, test.getHourOfDay());
461: assertEquals(20, test.getMinuteOfHour());
462: assertEquals(30, test.getSecondOfMinute());
463: assertEquals(40, test.getMillisOfSecond());
464: }
465:
466: public void testConstructor_ObjectLocalDate() throws Throwable {
467: LocalDate date = new LocalDate(1970, 4, 6, BUDDHIST_UTC);
468: try {
469: new LocalTime(date);
470: fail();
471: } catch (IllegalArgumentException ex) {
472: }
473: }
474:
475: public void testConstructor_ObjectLocalDateTime() throws Throwable {
476: LocalDateTime dt = new LocalDateTime(1970, 5, 6, 10, 20, 30,
477: 40, BUDDHIST_UTC);
478: LocalTime test = new LocalTime(dt);
479: assertEquals(BUDDHIST_UTC, test.getChronology());
480: assertEquals(10, test.getHourOfDay());
481: assertEquals(20, test.getMinuteOfHour());
482: assertEquals(30, test.getSecondOfMinute());
483: assertEquals(40, test.getMillisOfSecond());
484: }
485:
486: public void testConstructor_ObjectTimeOfDay() throws Throwable {
487: TimeOfDay time = new TimeOfDay(10, 20, 30, 40, BUDDHIST_UTC);
488: LocalTime test = new LocalTime(time);
489: assertEquals(BUDDHIST_UTC, test.getChronology());
490: assertEquals(10, test.getHourOfDay());
491: assertEquals(20, test.getMinuteOfHour());
492: assertEquals(30, test.getSecondOfMinute());
493: assertEquals(40, test.getMillisOfSecond());
494: }
495:
496: //-----------------------------------------------------------------------
497: public void testConstructor_Object1_DateTimeZone() throws Throwable {
498: Date date = new Date(TEST_TIME1);
499: LocalTime test = new LocalTime(date, PARIS);
500: assertEquals(ISO_UTC, test.getChronology());
501: assertEquals(1 + OFFSET_PARIS, test.getHourOfDay());
502: assertEquals(2, test.getMinuteOfHour());
503: assertEquals(3, test.getSecondOfMinute());
504: assertEquals(4, test.getMillisOfSecond());
505: }
506:
507: public void testConstructor_ObjectString_DateTimeZoneLondon()
508: throws Throwable {
509: LocalTime test = new LocalTime("04:20", LONDON);
510: assertEquals(4, test.getHourOfDay());
511: assertEquals(20, test.getMinuteOfHour());
512: }
513:
514: public void testConstructor_ObjectString_DateTimeZoneTokyo()
515: throws Throwable {
516: LocalTime test = new LocalTime("04:20", TOKYO);
517: assertEquals(ISO_UTC, test.getChronology());
518: assertEquals(4, test.getHourOfDay());
519: assertEquals(20, test.getMinuteOfHour());
520: }
521:
522: public void testConstructor_ObjectString_DateTimeZoneNewYork()
523: throws Throwable {
524: LocalTime test = new LocalTime("04:20", NEW_YORK);
525: assertEquals(ISO_UTC, test.getChronology());
526: assertEquals(4, test.getHourOfDay());
527: assertEquals(20, test.getMinuteOfHour());
528: }
529:
530: public void testConstructor_nullObject_DateTimeZone()
531: throws Throwable {
532: LocalTime test = new LocalTime((Object) null, PARIS);
533: assertEquals(ISO_UTC, test.getChronology());
534: assertEquals(10 + OFFSET_PARIS, test.getHourOfDay());
535: assertEquals(20, test.getMinuteOfHour());
536: assertEquals(30, test.getSecondOfMinute());
537: assertEquals(40, test.getMillisOfSecond());
538: }
539:
540: public void testConstructor_Object_nullDateTimeZone()
541: throws Throwable {
542: Date date = new Date(TEST_TIME1);
543: LocalTime test = new LocalTime(date, (DateTimeZone) null);
544: assertEquals(ISO_UTC, test.getChronology());
545: assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
546: assertEquals(2, test.getMinuteOfHour());
547: assertEquals(3, test.getSecondOfMinute());
548: assertEquals(4, test.getMillisOfSecond());
549: }
550:
551: public void testConstructor_nullObject_nullDateTimeZone()
552: throws Throwable {
553: LocalTime test = new LocalTime((Object) null,
554: (DateTimeZone) null);
555: assertEquals(ISO_UTC, test.getChronology());
556: assertEquals(10 + OFFSET_LONDON, test.getHourOfDay());
557: assertEquals(20, test.getMinuteOfHour());
558: assertEquals(30, test.getSecondOfMinute());
559: assertEquals(40, test.getMillisOfSecond());
560: }
561:
562: //-----------------------------------------------------------------------
563: public void testConstructor_Object1_Chronology() throws Throwable {
564: Date date = new Date(TEST_TIME1);
565: LocalTime test = new LocalTime(date, JULIAN_LONDON);
566: assertEquals(JULIAN_UTC, test.getChronology());
567: assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
568: assertEquals(2, test.getMinuteOfHour());
569: assertEquals(3, test.getSecondOfMinute());
570: assertEquals(4, test.getMillisOfSecond());
571: }
572:
573: public void testConstructor_Object2_Chronology() throws Throwable {
574: LocalTime test = new LocalTime("T10:20");
575: assertEquals(10, test.getHourOfDay());
576: assertEquals(20, test.getMinuteOfHour());
577: assertEquals(0, test.getSecondOfMinute());
578: assertEquals(0, test.getMillisOfSecond());
579:
580: try {
581: new LocalTime("T1020");
582: fail();
583: } catch (IllegalArgumentException ex) {
584: }
585: }
586:
587: public void testConstructor_nullObject_Chronology()
588: throws Throwable {
589: LocalTime test = new LocalTime((Object) null, JULIAN_LONDON);
590: assertEquals(JULIAN_UTC, test.getChronology());
591: assertEquals(10 + OFFSET_LONDON, test.getHourOfDay());
592: assertEquals(20, test.getMinuteOfHour());
593: assertEquals(30, test.getSecondOfMinute());
594: assertEquals(40, test.getMillisOfSecond());
595: }
596:
597: public void testConstructor_Object_nullChronology()
598: throws Throwable {
599: Date date = new Date(TEST_TIME1);
600: LocalTime test = new LocalTime(date, (Chronology) null);
601: assertEquals(ISO_UTC, test.getChronology());
602: assertEquals(1 + OFFSET_LONDON, test.getHourOfDay());
603: assertEquals(2, test.getMinuteOfHour());
604: assertEquals(3, test.getSecondOfMinute());
605: assertEquals(4, test.getMillisOfSecond());
606: }
607:
608: public void testConstructor_nullObject_nullChronology()
609: throws Throwable {
610: LocalTime test = new LocalTime((Object) null, (Chronology) null);
611: assertEquals(ISO_UTC, test.getChronology());
612: assertEquals(10 + OFFSET_LONDON, test.getHourOfDay());
613: assertEquals(20, test.getMinuteOfHour());
614: assertEquals(30, test.getSecondOfMinute());
615: assertEquals(40, test.getMillisOfSecond());
616: }
617:
618: //-----------------------------------------------------------------------
619: public void testConstructor_int_int() throws Throwable {
620: LocalTime test = new LocalTime(10, 20);
621: assertEquals(ISO_UTC, test.getChronology());
622: assertEquals(10, test.getHourOfDay());
623: assertEquals(20, test.getMinuteOfHour());
624: assertEquals(0, test.getSecondOfMinute());
625: assertEquals(0, test.getMillisOfSecond());
626: try {
627: new LocalTime(-1, 20);
628: fail();
629: } catch (IllegalArgumentException ex) {
630: }
631: try {
632: new LocalTime(24, 20);
633: fail();
634: } catch (IllegalArgumentException ex) {
635: }
636: try {
637: new LocalTime(10, -1);
638: fail();
639: } catch (IllegalArgumentException ex) {
640: }
641: try {
642: new LocalTime(10, 60);
643: fail();
644: } catch (IllegalArgumentException ex) {
645: }
646: }
647:
648: public void testConstructor_int_int_int() throws Throwable {
649: LocalTime test = new LocalTime(10, 20, 30);
650: assertEquals(ISO_UTC, test.getChronology());
651: assertEquals(10, test.getHourOfDay());
652: assertEquals(20, test.getMinuteOfHour());
653: assertEquals(30, test.getSecondOfMinute());
654: assertEquals(0, test.getMillisOfSecond());
655: try {
656: new LocalTime(-1, 20, 30);
657: fail();
658: } catch (IllegalArgumentException ex) {
659: }
660: try {
661: new LocalTime(24, 20, 30);
662: fail();
663: } catch (IllegalArgumentException ex) {
664: }
665: try {
666: new LocalTime(10, -1, 30);
667: fail();
668: } catch (IllegalArgumentException ex) {
669: }
670: try {
671: new LocalTime(10, 60, 30);
672: fail();
673: } catch (IllegalArgumentException ex) {
674: }
675: try {
676: new LocalTime(10, 20, -1);
677: fail();
678: } catch (IllegalArgumentException ex) {
679: }
680: try {
681: new LocalTime(10, 20, 60);
682: fail();
683: } catch (IllegalArgumentException ex) {
684: }
685: }
686:
687: public void testConstructor_int_int_int_int() throws Throwable {
688: LocalTime test = new LocalTime(10, 20, 30, 40);
689: assertEquals(ISO_UTC, test.getChronology());
690: assertEquals(10, test.getHourOfDay());
691: assertEquals(20, test.getMinuteOfHour());
692: assertEquals(30, test.getSecondOfMinute());
693: assertEquals(40, test.getMillisOfSecond());
694: try {
695: new LocalTime(-1, 20, 30, 40);
696: fail();
697: } catch (IllegalArgumentException ex) {
698: }
699: try {
700: new LocalTime(24, 20, 30, 40);
701: fail();
702: } catch (IllegalArgumentException ex) {
703: }
704: try {
705: new LocalTime(10, -1, 30, 40);
706: fail();
707: } catch (IllegalArgumentException ex) {
708: }
709: try {
710: new LocalTime(10, 60, 30, 40);
711: fail();
712: } catch (IllegalArgumentException ex) {
713: }
714: try {
715: new LocalTime(10, 20, -1, 40);
716: fail();
717: } catch (IllegalArgumentException ex) {
718: }
719: try {
720: new LocalTime(10, 20, 60, 40);
721: fail();
722: } catch (IllegalArgumentException ex) {
723: }
724: try {
725: new LocalTime(10, 20, 30, -1);
726: fail();
727: } catch (IllegalArgumentException ex) {
728: }
729: try {
730: new LocalTime(10, 20, 30, 1000);
731: fail();
732: } catch (IllegalArgumentException ex) {
733: }
734: }
735:
736: public void testConstructor_int_int_int_int_Chronology()
737: throws Throwable {
738: LocalTime test = new LocalTime(10, 20, 30, 40, JULIAN_LONDON);
739: assertEquals(JULIAN_UTC, test.getChronology());
740: assertEquals(10, test.getHourOfDay());
741: assertEquals(20, test.getMinuteOfHour());
742: assertEquals(30, test.getSecondOfMinute());
743: assertEquals(40, test.getMillisOfSecond());
744: try {
745: new LocalTime(-1, 20, 30, 40, JULIAN_LONDON);
746: fail();
747: } catch (IllegalArgumentException ex) {
748: }
749: try {
750: new LocalTime(24, 20, 30, 40, JULIAN_LONDON);
751: fail();
752: } catch (IllegalArgumentException ex) {
753: }
754: try {
755: new LocalTime(10, -1, 30, 40, JULIAN_LONDON);
756: fail();
757: } catch (IllegalArgumentException ex) {
758: }
759: try {
760: new LocalTime(10, 60, 30, 40, JULIAN_LONDON);
761: fail();
762: } catch (IllegalArgumentException ex) {
763: }
764: try {
765: new LocalTime(10, 20, -1, 40, JULIAN_LONDON);
766: fail();
767: } catch (IllegalArgumentException ex) {
768: }
769: try {
770: new LocalTime(10, 20, 60, 40, JULIAN_LONDON);
771: fail();
772: } catch (IllegalArgumentException ex) {
773: }
774: try {
775: new LocalTime(10, 20, 30, -1, JULIAN_LONDON);
776: fail();
777: } catch (IllegalArgumentException ex) {
778: }
779: try {
780: new LocalTime(10, 20, 30, 1000, JULIAN_LONDON);
781: fail();
782: } catch (IllegalArgumentException ex) {
783: }
784: }
785:
786: public void testConstructor_int_int_int_int_nullChronology()
787: throws Throwable {
788: LocalTime test = new LocalTime(10, 20, 30, 40, null);
789: assertEquals(ISO_UTC, test.getChronology());
790: assertEquals(10, test.getHourOfDay());
791: assertEquals(20, test.getMinuteOfHour());
792: assertEquals(30, test.getSecondOfMinute());
793: assertEquals(40, test.getMillisOfSecond());
794: }
795:
796: }
|