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