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