001: /*
002: * Copyright 2001-2005 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.Locale;
019:
020: import junit.framework.TestCase;
021: import junit.framework.TestSuite;
022:
023: /**
024: * This class is a Junit unit test for TimeOfDay.
025: *
026: * @author Stephen Colebourne
027: */
028: public class TestTimeOfDay_Properties extends TestCase {
029:
030: private static final DateTimeZone LONDON = DateTimeZone
031: .forID("Europe/London");
032: private static final DateTimeZone PARIS = DateTimeZone
033: .forID("Europe/Paris");
034:
035: private long TEST_TIME_NOW = 10L
036: * DateTimeConstants.MILLIS_PER_HOUR + 20L
037: * DateTimeConstants.MILLIS_PER_MINUTE + 30L
038: * DateTimeConstants.MILLIS_PER_SECOND + 40L;
039:
040: private long TEST_TIME1 = 1L * DateTimeConstants.MILLIS_PER_HOUR
041: + 2L * DateTimeConstants.MILLIS_PER_MINUTE + 3L
042: * DateTimeConstants.MILLIS_PER_SECOND + 4L;
043:
044: private long TEST_TIME2 = 1L * DateTimeConstants.MILLIS_PER_DAY
045: + 5L * DateTimeConstants.MILLIS_PER_HOUR + 6L
046: * DateTimeConstants.MILLIS_PER_MINUTE + 7L
047: * DateTimeConstants.MILLIS_PER_SECOND + 8L;
048:
049: private DateTimeZone zone = null;
050:
051: public static void main(String[] args) {
052: junit.textui.TestRunner.run(suite());
053: }
054:
055: public static TestSuite suite() {
056: return new TestSuite(TestTimeOfDay_Properties.class);
057: }
058:
059: public TestTimeOfDay_Properties(String name) {
060: super (name);
061: }
062:
063: protected void setUp() throws Exception {
064: DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
065: zone = DateTimeZone.getDefault();
066: DateTimeZone.setDefault(LONDON);
067: }
068:
069: protected void tearDown() throws Exception {
070: DateTimeUtils.setCurrentMillisSystem();
071: DateTimeZone.setDefault(zone);
072: zone = null;
073: }
074:
075: //-----------------------------------------------------------------------
076: public void testPropertyGetHour() {
077: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
078: assertSame(test.getChronology().hourOfDay(), test.hourOfDay()
079: .getField());
080: assertEquals("hourOfDay", test.hourOfDay().getName());
081: assertEquals("Property[hourOfDay]", test.hourOfDay().toString());
082: assertSame(test, test.hourOfDay().getReadablePartial());
083: assertSame(test, test.hourOfDay().getTimeOfDay());
084: assertEquals(10, test.hourOfDay().get());
085: assertEquals("10", test.hourOfDay().getAsString());
086: assertEquals("10", test.hourOfDay().getAsText());
087: assertEquals("10", test.hourOfDay().getAsText(Locale.FRENCH));
088: assertEquals("10", test.hourOfDay().getAsShortText());
089: assertEquals("10", test.hourOfDay().getAsShortText(
090: Locale.FRENCH));
091: assertEquals(test.getChronology().hours(), test.hourOfDay()
092: .getDurationField());
093: assertEquals(test.getChronology().days(), test.hourOfDay()
094: .getRangeDurationField());
095: assertEquals(2, test.hourOfDay().getMaximumTextLength(null));
096: assertEquals(2, test.hourOfDay()
097: .getMaximumShortTextLength(null));
098: }
099:
100: public void testPropertyGetMaxMinValuesHour() {
101: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
102: assertEquals(0, test.hourOfDay().getMinimumValue());
103: assertEquals(0, test.hourOfDay().getMinimumValueOverall());
104: assertEquals(23, test.hourOfDay().getMaximumValue());
105: assertEquals(23, test.hourOfDay().getMaximumValueOverall());
106: }
107:
108: public void testPropertyAddHour() {
109: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
110: TimeOfDay copy = test.hourOfDay().addToCopy(9);
111: check(test, 10, 20, 30, 40);
112: check(copy, 19, 20, 30, 40);
113:
114: copy = test.hourOfDay().addToCopy(0);
115: check(copy, 10, 20, 30, 40);
116:
117: copy = test.hourOfDay().addToCopy(13);
118: check(copy, 23, 20, 30, 40);
119:
120: copy = test.hourOfDay().addToCopy(14);
121: check(copy, 0, 20, 30, 40);
122:
123: copy = test.hourOfDay().addToCopy(-10);
124: check(copy, 0, 20, 30, 40);
125:
126: copy = test.hourOfDay().addToCopy(-11);
127: check(copy, 23, 20, 30, 40);
128: }
129:
130: public void testPropertyAddNoWrapHour() {
131: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
132: TimeOfDay copy = test.hourOfDay().addNoWrapToCopy(9);
133: check(test, 10, 20, 30, 40);
134: check(copy, 19, 20, 30, 40);
135:
136: copy = test.hourOfDay().addNoWrapToCopy(0);
137: check(copy, 10, 20, 30, 40);
138:
139: copy = test.hourOfDay().addNoWrapToCopy(13);
140: check(copy, 23, 20, 30, 40);
141:
142: try {
143: test.hourOfDay().addNoWrapToCopy(14);
144: fail();
145: } catch (IllegalArgumentException ex) {
146: }
147: check(test, 10, 20, 30, 40);
148:
149: copy = test.hourOfDay().addNoWrapToCopy(-10);
150: check(copy, 0, 20, 30, 40);
151:
152: try {
153: test.hourOfDay().addNoWrapToCopy(-11);
154: fail();
155: } catch (IllegalArgumentException ex) {
156: }
157: check(test, 10, 20, 30, 40);
158: }
159:
160: public void testPropertyAddWrapFieldHour() {
161: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
162: TimeOfDay copy = test.hourOfDay().addWrapFieldToCopy(9);
163: check(test, 10, 20, 30, 40);
164: check(copy, 19, 20, 30, 40);
165:
166: copy = test.hourOfDay().addWrapFieldToCopy(0);
167: check(copy, 10, 20, 30, 40);
168:
169: copy = test.hourOfDay().addWrapFieldToCopy(18);
170: check(copy, 4, 20, 30, 40);
171:
172: copy = test.hourOfDay().addWrapFieldToCopy(-15);
173: check(copy, 19, 20, 30, 40);
174: }
175:
176: public void testPropertySetHour() {
177: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
178: TimeOfDay copy = test.hourOfDay().setCopy(12);
179: check(test, 10, 20, 30, 40);
180: check(copy, 12, 20, 30, 40);
181:
182: try {
183: test.hourOfDay().setCopy(24);
184: fail();
185: } catch (IllegalArgumentException ex) {
186: }
187: try {
188: test.hourOfDay().setCopy(-1);
189: fail();
190: } catch (IllegalArgumentException ex) {
191: }
192: }
193:
194: public void testPropertySetTextHour() {
195: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
196: TimeOfDay copy = test.hourOfDay().setCopy("12");
197: check(test, 10, 20, 30, 40);
198: check(copy, 12, 20, 30, 40);
199: }
200:
201: public void testPropertyWithMaximumValueHour() {
202: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
203: TimeOfDay copy = test.hourOfDay().withMaximumValue();
204: check(test, 10, 20, 30, 40);
205: check(copy, 23, 20, 30, 40);
206: }
207:
208: public void testPropertyWithMinimumValueHour() {
209: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
210: TimeOfDay copy = test.hourOfDay().withMinimumValue();
211: check(test, 10, 20, 30, 40);
212: check(copy, 0, 20, 30, 40);
213: }
214:
215: public void testPropertyCompareToHour() {
216: TimeOfDay test1 = new TimeOfDay(TEST_TIME1);
217: TimeOfDay test2 = new TimeOfDay(TEST_TIME2);
218: assertEquals(true, test1.hourOfDay().compareTo(test2) < 0);
219: assertEquals(true, test2.hourOfDay().compareTo(test1) > 0);
220: assertEquals(true, test1.hourOfDay().compareTo(test1) == 0);
221: try {
222: test1.hourOfDay().compareTo((ReadablePartial) null);
223: fail();
224: } catch (IllegalArgumentException ex) {
225: }
226:
227: DateTime dt1 = new DateTime(TEST_TIME1);
228: DateTime dt2 = new DateTime(TEST_TIME2);
229: assertEquals(true, test1.hourOfDay().compareTo(dt2) < 0);
230: assertEquals(true, test2.hourOfDay().compareTo(dt1) > 0);
231: assertEquals(true, test1.hourOfDay().compareTo(dt1) == 0);
232: try {
233: test1.hourOfDay().compareTo((ReadableInstant) null);
234: fail();
235: } catch (IllegalArgumentException ex) {
236: }
237: }
238:
239: //-----------------------------------------------------------------------
240: public void testPropertyGetMinute() {
241: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
242: assertSame(test.getChronology().minuteOfHour(), test
243: .minuteOfHour().getField());
244: assertEquals("minuteOfHour", test.minuteOfHour().getName());
245: assertEquals("Property[minuteOfHour]", test.minuteOfHour()
246: .toString());
247: assertSame(test, test.minuteOfHour().getReadablePartial());
248: assertSame(test, test.minuteOfHour().getTimeOfDay());
249: assertEquals(20, test.minuteOfHour().get());
250: assertEquals("20", test.minuteOfHour().getAsString());
251: assertEquals("20", test.minuteOfHour().getAsText());
252: assertEquals("20", test.minuteOfHour().getAsText(Locale.FRENCH));
253: assertEquals("20", test.minuteOfHour().getAsShortText());
254: assertEquals("20", test.minuteOfHour().getAsShortText(
255: Locale.FRENCH));
256: assertEquals(test.getChronology().minutes(), test
257: .minuteOfHour().getDurationField());
258: assertEquals(test.getChronology().hours(), test.minuteOfHour()
259: .getRangeDurationField());
260: assertEquals(2, test.minuteOfHour().getMaximumTextLength(null));
261: assertEquals(2, test.minuteOfHour().getMaximumShortTextLength(
262: null));
263: }
264:
265: public void testPropertyGetMaxMinValuesMinute() {
266: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
267: assertEquals(0, test.minuteOfHour().getMinimumValue());
268: assertEquals(0, test.minuteOfHour().getMinimumValueOverall());
269: assertEquals(59, test.minuteOfHour().getMaximumValue());
270: assertEquals(59, test.minuteOfHour().getMaximumValueOverall());
271: }
272:
273: public void testPropertyAddMinute() {
274: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
275: TimeOfDay copy = test.minuteOfHour().addToCopy(9);
276: check(test, 10, 20, 30, 40);
277: check(copy, 10, 29, 30, 40);
278:
279: copy = test.minuteOfHour().addToCopy(39);
280: check(copy, 10, 59, 30, 40);
281:
282: copy = test.minuteOfHour().addToCopy(40);
283: check(copy, 11, 0, 30, 40);
284:
285: copy = test.minuteOfHour().addToCopy(1 * 60 + 45);
286: check(copy, 12, 5, 30, 40);
287:
288: copy = test.minuteOfHour().addToCopy(13 * 60 + 39);
289: check(copy, 23, 59, 30, 40);
290:
291: copy = test.minuteOfHour().addToCopy(13 * 60 + 40);
292: check(copy, 0, 0, 30, 40);
293:
294: copy = test.minuteOfHour().addToCopy(-9);
295: check(copy, 10, 11, 30, 40);
296:
297: copy = test.minuteOfHour().addToCopy(-19);
298: check(copy, 10, 1, 30, 40);
299:
300: copy = test.minuteOfHour().addToCopy(-20);
301: check(copy, 10, 0, 30, 40);
302:
303: copy = test.minuteOfHour().addToCopy(-21);
304: check(copy, 9, 59, 30, 40);
305:
306: copy = test.minuteOfHour().addToCopy(-(10 * 60 + 20));
307: check(copy, 0, 0, 30, 40);
308:
309: copy = test.minuteOfHour().addToCopy(-(10 * 60 + 21));
310: check(copy, 23, 59, 30, 40);
311: }
312:
313: public void testPropertyAddNoWrapMinute() {
314: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
315: TimeOfDay copy = test.minuteOfHour().addNoWrapToCopy(9);
316: check(test, 10, 20, 30, 40);
317: check(copy, 10, 29, 30, 40);
318:
319: copy = test.minuteOfHour().addNoWrapToCopy(39);
320: check(copy, 10, 59, 30, 40);
321:
322: copy = test.minuteOfHour().addNoWrapToCopy(40);
323: check(copy, 11, 0, 30, 40);
324:
325: copy = test.minuteOfHour().addNoWrapToCopy(1 * 60 + 45);
326: check(copy, 12, 5, 30, 40);
327:
328: copy = test.minuteOfHour().addNoWrapToCopy(13 * 60 + 39);
329: check(copy, 23, 59, 30, 40);
330:
331: try {
332: test.minuteOfHour().addNoWrapToCopy(13 * 60 + 40);
333: fail();
334: } catch (IllegalArgumentException ex) {
335: }
336: check(test, 10, 20, 30, 40);
337:
338: copy = test.minuteOfHour().addNoWrapToCopy(-9);
339: check(copy, 10, 11, 30, 40);
340:
341: copy = test.minuteOfHour().addNoWrapToCopy(-19);
342: check(copy, 10, 1, 30, 40);
343:
344: copy = test.minuteOfHour().addNoWrapToCopy(-20);
345: check(copy, 10, 0, 30, 40);
346:
347: copy = test.minuteOfHour().addNoWrapToCopy(-21);
348: check(copy, 9, 59, 30, 40);
349:
350: copy = test.minuteOfHour().addNoWrapToCopy(-(10 * 60 + 20));
351: check(copy, 0, 0, 30, 40);
352:
353: try {
354: test.minuteOfHour().addNoWrapToCopy(-(10 * 60 + 21));
355: fail();
356: } catch (IllegalArgumentException ex) {
357: }
358: check(test, 10, 20, 30, 40);
359: }
360:
361: public void testPropertyAddWrapFieldMinute() {
362: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
363: TimeOfDay copy = test.minuteOfHour().addWrapFieldToCopy(9);
364: check(test, 10, 20, 30, 40);
365: check(copy, 10, 29, 30, 40);
366:
367: copy = test.minuteOfHour().addWrapFieldToCopy(49);
368: check(copy, 10, 9, 30, 40);
369:
370: copy = test.minuteOfHour().addWrapFieldToCopy(-47);
371: check(copy, 10, 33, 30, 40);
372: }
373:
374: public void testPropertySetMinute() {
375: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
376: TimeOfDay copy = test.minuteOfHour().setCopy(12);
377: check(test, 10, 20, 30, 40);
378: check(copy, 10, 12, 30, 40);
379:
380: try {
381: test.minuteOfHour().setCopy(60);
382: fail();
383: } catch (IllegalArgumentException ex) {
384: }
385: try {
386: test.minuteOfHour().setCopy(-1);
387: fail();
388: } catch (IllegalArgumentException ex) {
389: }
390: }
391:
392: public void testPropertySetTextMinute() {
393: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
394: TimeOfDay copy = test.minuteOfHour().setCopy("12");
395: check(test, 10, 20, 30, 40);
396: check(copy, 10, 12, 30, 40);
397: }
398:
399: public void testPropertyCompareToMinute() {
400: TimeOfDay test1 = new TimeOfDay(TEST_TIME1);
401: TimeOfDay test2 = new TimeOfDay(TEST_TIME2);
402: assertEquals(true, test1.minuteOfHour().compareTo(test2) < 0);
403: assertEquals(true, test2.minuteOfHour().compareTo(test1) > 0);
404: assertEquals(true, test1.minuteOfHour().compareTo(test1) == 0);
405: try {
406: test1.minuteOfHour().compareTo((ReadablePartial) null);
407: fail();
408: } catch (IllegalArgumentException ex) {
409: }
410:
411: DateTime dt1 = new DateTime(TEST_TIME1);
412: DateTime dt2 = new DateTime(TEST_TIME2);
413: assertEquals(true, test1.minuteOfHour().compareTo(dt2) < 0);
414: assertEquals(true, test2.minuteOfHour().compareTo(dt1) > 0);
415: assertEquals(true, test1.minuteOfHour().compareTo(dt1) == 0);
416: try {
417: test1.minuteOfHour().compareTo((ReadableInstant) null);
418: fail();
419: } catch (IllegalArgumentException ex) {
420: }
421: }
422:
423: //-----------------------------------------------------------------------
424: public void testPropertyGetSecond() {
425: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
426: assertSame(test.getChronology().secondOfMinute(), test
427: .secondOfMinute().getField());
428: assertEquals("secondOfMinute", test.secondOfMinute().getName());
429: assertEquals("Property[secondOfMinute]", test.secondOfMinute()
430: .toString());
431: assertSame(test, test.secondOfMinute().getReadablePartial());
432: assertSame(test, test.secondOfMinute().getTimeOfDay());
433: assertEquals(30, test.secondOfMinute().get());
434: assertEquals("30", test.secondOfMinute().getAsString());
435: assertEquals("30", test.secondOfMinute().getAsText());
436: assertEquals("30", test.secondOfMinute().getAsText(
437: Locale.FRENCH));
438: assertEquals("30", test.secondOfMinute().getAsShortText());
439: assertEquals("30", test.secondOfMinute().getAsShortText(
440: Locale.FRENCH));
441: assertEquals(test.getChronology().seconds(), test
442: .secondOfMinute().getDurationField());
443: assertEquals(test.getChronology().minutes(), test
444: .secondOfMinute().getRangeDurationField());
445: assertEquals(2, test.secondOfMinute()
446: .getMaximumTextLength(null));
447: assertEquals(2, test.secondOfMinute()
448: .getMaximumShortTextLength(null));
449: }
450:
451: public void testPropertyGetMaxMinValuesSecond() {
452: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
453: assertEquals(0, test.secondOfMinute().getMinimumValue());
454: assertEquals(0, test.secondOfMinute().getMinimumValueOverall());
455: assertEquals(59, test.secondOfMinute().getMaximumValue());
456: assertEquals(59, test.secondOfMinute().getMaximumValueOverall());
457: }
458:
459: public void testPropertyAddSecond() {
460: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
461: TimeOfDay copy = test.secondOfMinute().addToCopy(9);
462: check(test, 10, 20, 30, 40);
463: check(copy, 10, 20, 39, 40);
464:
465: copy = test.secondOfMinute().addToCopy(29);
466: check(copy, 10, 20, 59, 40);
467:
468: copy = test.secondOfMinute().addToCopy(30);
469: check(copy, 10, 21, 0, 40);
470:
471: copy = test.secondOfMinute().addToCopy(39 * 60 + 29);
472: check(copy, 10, 59, 59, 40);
473:
474: copy = test.secondOfMinute().addToCopy(39 * 60 + 30);
475: check(copy, 11, 0, 0, 40);
476:
477: copy = test.secondOfMinute().addToCopy(
478: 13 * 60 * 60 + 39 * 60 + 30);
479: check(copy, 0, 0, 0, 40);
480:
481: copy = test.secondOfMinute().addToCopy(-9);
482: check(copy, 10, 20, 21, 40);
483:
484: copy = test.secondOfMinute().addToCopy(-30);
485: check(copy, 10, 20, 0, 40);
486:
487: copy = test.secondOfMinute().addToCopy(-31);
488: check(copy, 10, 19, 59, 40);
489:
490: copy = test.secondOfMinute().addToCopy(
491: -(10 * 60 * 60 + 20 * 60 + 30));
492: check(copy, 0, 0, 0, 40);
493:
494: copy = test.secondOfMinute().addToCopy(
495: -(10 * 60 * 60 + 20 * 60 + 31));
496: check(copy, 23, 59, 59, 40);
497: }
498:
499: public void testPropertyAddNoWrapSecond() {
500: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
501: TimeOfDay copy = test.secondOfMinute().addNoWrapToCopy(9);
502: check(test, 10, 20, 30, 40);
503: check(copy, 10, 20, 39, 40);
504:
505: copy = test.secondOfMinute().addNoWrapToCopy(29);
506: check(copy, 10, 20, 59, 40);
507:
508: copy = test.secondOfMinute().addNoWrapToCopy(30);
509: check(copy, 10, 21, 0, 40);
510:
511: copy = test.secondOfMinute().addNoWrapToCopy(39 * 60 + 29);
512: check(copy, 10, 59, 59, 40);
513:
514: copy = test.secondOfMinute().addNoWrapToCopy(39 * 60 + 30);
515: check(copy, 11, 0, 0, 40);
516:
517: try {
518: test.secondOfMinute().addNoWrapToCopy(
519: 13 * 60 * 60 + 39 * 60 + 30);
520: fail();
521: } catch (IllegalArgumentException ex) {
522: }
523: check(test, 10, 20, 30, 40);
524:
525: copy = test.secondOfMinute().addNoWrapToCopy(-9);
526: check(copy, 10, 20, 21, 40);
527:
528: copy = test.secondOfMinute().addNoWrapToCopy(-30);
529: check(copy, 10, 20, 0, 40);
530:
531: copy = test.secondOfMinute().addNoWrapToCopy(-31);
532: check(copy, 10, 19, 59, 40);
533:
534: copy = test.secondOfMinute().addNoWrapToCopy(
535: -(10 * 60 * 60 + 20 * 60 + 30));
536: check(copy, 0, 0, 0, 40);
537:
538: try {
539: test.secondOfMinute().addNoWrapToCopy(
540: -(10 * 60 * 60 + 20 * 60 + 31));
541: fail();
542: } catch (IllegalArgumentException ex) {
543: }
544: check(test, 10, 20, 30, 40);
545: }
546:
547: public void testPropertyAddWrapFieldSecond() {
548: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
549: TimeOfDay copy = test.secondOfMinute().addWrapFieldToCopy(9);
550: check(test, 10, 20, 30, 40);
551: check(copy, 10, 20, 39, 40);
552:
553: copy = test.secondOfMinute().addWrapFieldToCopy(49);
554: check(copy, 10, 20, 19, 40);
555:
556: copy = test.secondOfMinute().addWrapFieldToCopy(-47);
557: check(copy, 10, 20, 43, 40);
558: }
559:
560: public void testPropertySetSecond() {
561: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
562: TimeOfDay copy = test.secondOfMinute().setCopy(12);
563: check(test, 10, 20, 30, 40);
564: check(copy, 10, 20, 12, 40);
565:
566: try {
567: test.secondOfMinute().setCopy(60);
568: fail();
569: } catch (IllegalArgumentException ex) {
570: }
571: try {
572: test.secondOfMinute().setCopy(-1);
573: fail();
574: } catch (IllegalArgumentException ex) {
575: }
576: }
577:
578: public void testPropertySetTextSecond() {
579: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
580: TimeOfDay copy = test.secondOfMinute().setCopy("12");
581: check(test, 10, 20, 30, 40);
582: check(copy, 10, 20, 12, 40);
583: }
584:
585: public void testPropertyCompareToSecond() {
586: TimeOfDay test1 = new TimeOfDay(TEST_TIME1);
587: TimeOfDay test2 = new TimeOfDay(TEST_TIME2);
588: assertEquals(true, test1.secondOfMinute().compareTo(test2) < 0);
589: assertEquals(true, test2.secondOfMinute().compareTo(test1) > 0);
590: assertEquals(true, test1.secondOfMinute().compareTo(test1) == 0);
591: try {
592: test1.secondOfMinute().compareTo((ReadablePartial) null);
593: fail();
594: } catch (IllegalArgumentException ex) {
595: }
596:
597: DateTime dt1 = new DateTime(TEST_TIME1);
598: DateTime dt2 = new DateTime(TEST_TIME2);
599: assertEquals(true, test1.secondOfMinute().compareTo(dt2) < 0);
600: assertEquals(true, test2.secondOfMinute().compareTo(dt1) > 0);
601: assertEquals(true, test1.secondOfMinute().compareTo(dt1) == 0);
602: try {
603: test1.secondOfMinute().compareTo((ReadableInstant) null);
604: fail();
605: } catch (IllegalArgumentException ex) {
606: }
607: }
608:
609: //-----------------------------------------------------------------------
610: public void testPropertyGetMilli() {
611: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
612: assertSame(test.getChronology().millisOfSecond(), test
613: .millisOfSecond().getField());
614: assertEquals("millisOfSecond", test.millisOfSecond().getName());
615: assertEquals("Property[millisOfSecond]", test.millisOfSecond()
616: .toString());
617: assertSame(test, test.millisOfSecond().getReadablePartial());
618: assertSame(test, test.millisOfSecond().getTimeOfDay());
619: assertEquals(40, test.millisOfSecond().get());
620: assertEquals("40", test.millisOfSecond().getAsString());
621: assertEquals("40", test.millisOfSecond().getAsText());
622: assertEquals("40", test.millisOfSecond().getAsText(
623: Locale.FRENCH));
624: assertEquals("40", test.millisOfSecond().getAsShortText());
625: assertEquals("40", test.millisOfSecond().getAsShortText(
626: Locale.FRENCH));
627: assertEquals(test.getChronology().millis(), test
628: .millisOfSecond().getDurationField());
629: assertEquals(test.getChronology().seconds(), test
630: .millisOfSecond().getRangeDurationField());
631: assertEquals(3, test.millisOfSecond()
632: .getMaximumTextLength(null));
633: assertEquals(3, test.millisOfSecond()
634: .getMaximumShortTextLength(null));
635: }
636:
637: public void testPropertyGetMaxMinValuesMilli() {
638: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
639: assertEquals(0, test.millisOfSecond().getMinimumValue());
640: assertEquals(0, test.millisOfSecond().getMinimumValueOverall());
641: assertEquals(999, test.millisOfSecond().getMaximumValue());
642: assertEquals(999, test.millisOfSecond()
643: .getMaximumValueOverall());
644: }
645:
646: public void testPropertyAddMilli() {
647: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
648: TimeOfDay copy = test.millisOfSecond().addToCopy(9);
649: check(test, 10, 20, 30, 40);
650: check(copy, 10, 20, 30, 49);
651:
652: copy = test.millisOfSecond().addToCopy(959);
653: check(copy, 10, 20, 30, 999);
654:
655: copy = test.millisOfSecond().addToCopy(960);
656: check(copy, 10, 20, 31, 0);
657:
658: copy = test.millisOfSecond().addToCopy(
659: 13 * 60 * 60 * 1000 + 39 * 60 * 1000 + 29 * 1000 + 959);
660: check(copy, 23, 59, 59, 999);
661:
662: copy = test.millisOfSecond().addToCopy(
663: 13 * 60 * 60 * 1000 + 39 * 60 * 1000 + 29 * 1000 + 960);
664: check(copy, 0, 0, 0, 0);
665:
666: copy = test.millisOfSecond().addToCopy(-9);
667: check(copy, 10, 20, 30, 31);
668:
669: copy = test.millisOfSecond().addToCopy(-40);
670: check(copy, 10, 20, 30, 0);
671:
672: copy = test.millisOfSecond().addToCopy(-41);
673: check(copy, 10, 20, 29, 999);
674:
675: copy = test.millisOfSecond()
676: .addToCopy(
677: -(10 * 60 * 60 * 1000 + 20 * 60 * 1000 + 30
678: * 1000 + 40));
679: check(copy, 0, 0, 0, 0);
680:
681: copy = test.millisOfSecond()
682: .addToCopy(
683: -(10 * 60 * 60 * 1000 + 20 * 60 * 1000 + 30
684: * 1000 + 41));
685: check(copy, 23, 59, 59, 999);
686: }
687:
688: public void testPropertyAddNoWrapMilli() {
689: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
690: TimeOfDay copy = test.millisOfSecond().addNoWrapToCopy(9);
691: check(test, 10, 20, 30, 40);
692: check(copy, 10, 20, 30, 49);
693:
694: copy = test.millisOfSecond().addNoWrapToCopy(959);
695: check(copy, 10, 20, 30, 999);
696:
697: copy = test.millisOfSecond().addNoWrapToCopy(960);
698: check(copy, 10, 20, 31, 0);
699:
700: copy = test.millisOfSecond().addNoWrapToCopy(
701: 13 * 60 * 60 * 1000 + 39 * 60 * 1000 + 29 * 1000 + 959);
702: check(copy, 23, 59, 59, 999);
703:
704: try {
705: test.millisOfSecond().addNoWrapToCopy(
706: 13 * 60 * 60 * 1000 + 39 * 60 * 1000 + 29 * 1000
707: + 960);
708: fail();
709: } catch (IllegalArgumentException ex) {
710: }
711: check(test, 10, 20, 30, 40);
712:
713: copy = test.millisOfSecond().addNoWrapToCopy(-9);
714: check(copy, 10, 20, 30, 31);
715:
716: copy = test.millisOfSecond().addNoWrapToCopy(-40);
717: check(copy, 10, 20, 30, 0);
718:
719: copy = test.millisOfSecond().addNoWrapToCopy(-41);
720: check(copy, 10, 20, 29, 999);
721:
722: copy = test.millisOfSecond()
723: .addNoWrapToCopy(
724: -(10 * 60 * 60 * 1000 + 20 * 60 * 1000 + 30
725: * 1000 + 40));
726: check(copy, 0, 0, 0, 0);
727:
728: try {
729: test.millisOfSecond()
730: .addNoWrapToCopy(
731: -(10 * 60 * 60 * 1000 + 20 * 60 * 1000 + 30
732: * 1000 + 41));
733: fail();
734: } catch (IllegalArgumentException ex) {
735: }
736: check(test, 10, 20, 30, 40);
737: }
738:
739: public void testPropertyAddWrapFieldMilli() {
740: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
741: TimeOfDay copy = test.millisOfSecond().addWrapFieldToCopy(9);
742: check(test, 10, 20, 30, 40);
743: check(copy, 10, 20, 30, 49);
744:
745: copy = test.millisOfSecond().addWrapFieldToCopy(995);
746: check(copy, 10, 20, 30, 35);
747:
748: copy = test.millisOfSecond().addWrapFieldToCopy(-47);
749: check(copy, 10, 20, 30, 993);
750: }
751:
752: public void testPropertySetMilli() {
753: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
754: TimeOfDay copy = test.millisOfSecond().setCopy(12);
755: check(test, 10, 20, 30, 40);
756: check(copy, 10, 20, 30, 12);
757:
758: try {
759: test.millisOfSecond().setCopy(1000);
760: fail();
761: } catch (IllegalArgumentException ex) {
762: }
763: try {
764: test.millisOfSecond().setCopy(-1);
765: fail();
766: } catch (IllegalArgumentException ex) {
767: }
768: }
769:
770: public void testPropertySetTextMilli() {
771: TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
772: TimeOfDay copy = test.millisOfSecond().setCopy("12");
773: check(test, 10, 20, 30, 40);
774: check(copy, 10, 20, 30, 12);
775: }
776:
777: public void testPropertyCompareToMilli() {
778: TimeOfDay test1 = new TimeOfDay(TEST_TIME1);
779: TimeOfDay test2 = new TimeOfDay(TEST_TIME2);
780: assertEquals(true, test1.millisOfSecond().compareTo(test2) < 0);
781: assertEquals(true, test2.millisOfSecond().compareTo(test1) > 0);
782: assertEquals(true, test1.millisOfSecond().compareTo(test1) == 0);
783: try {
784: test1.millisOfSecond().compareTo((ReadablePartial) null);
785: fail();
786: } catch (IllegalArgumentException ex) {
787: }
788:
789: DateTime dt1 = new DateTime(TEST_TIME1);
790: DateTime dt2 = new DateTime(TEST_TIME2);
791: assertEquals(true, test1.millisOfSecond().compareTo(dt2) < 0);
792: assertEquals(true, test2.millisOfSecond().compareTo(dt1) > 0);
793: assertEquals(true, test1.millisOfSecond().compareTo(dt1) == 0);
794: try {
795: test1.millisOfSecond().compareTo((ReadableInstant) null);
796: fail();
797: } catch (IllegalArgumentException ex) {
798: }
799: }
800:
801: //-----------------------------------------------------------------------
802: private void check(TimeOfDay test, int hour, int min, int sec,
803: int milli) {
804: assertEquals(hour, test.getHourOfDay());
805: assertEquals(min, test.getMinuteOfHour());
806: assertEquals(sec, test.getSecondOfMinute());
807: assertEquals(milli, test.getMillisOfSecond());
808: }
809: }
|