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