View Javadoc

1   /*
2    *  Copyright 2001-2005 Stephen Colebourne
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package org.joda.time;
17  
18  import java.util.Locale;
19  
20  import junit.framework.TestCase;
21  import junit.framework.TestSuite;
22  
23  /**
24   * This class is a Junit unit test for TimeOfDay.
25   *
26   * @author Stephen Colebourne
27   */
28  public class TestTimeOfDay_Properties extends TestCase {
29  
30      private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
31      private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
32      
33      private long TEST_TIME_NOW =
34              10L * DateTimeConstants.MILLIS_PER_HOUR
35              + 20L * DateTimeConstants.MILLIS_PER_MINUTE
36              + 30L * DateTimeConstants.MILLIS_PER_SECOND
37              + 40L;
38              
39      private long TEST_TIME1 =
40          1L * DateTimeConstants.MILLIS_PER_HOUR
41          + 2L * DateTimeConstants.MILLIS_PER_MINUTE
42          + 3L * DateTimeConstants.MILLIS_PER_SECOND
43          + 4L;
44          
45      private long TEST_TIME2 =
46          1L * DateTimeConstants.MILLIS_PER_DAY
47          + 5L * DateTimeConstants.MILLIS_PER_HOUR
48          + 6L * DateTimeConstants.MILLIS_PER_MINUTE
49          + 7L * DateTimeConstants.MILLIS_PER_SECOND
50          + 8L;
51          
52      private DateTimeZone zone = null;
53  
54      public static void main(String[] args) {
55          junit.textui.TestRunner.run(suite());
56      }
57  
58      public static TestSuite suite() {
59          return new TestSuite(TestTimeOfDay_Properties.class);
60      }
61  
62      public TestTimeOfDay_Properties(String name) {
63          super(name);
64      }
65  
66      protected void setUp() throws Exception {
67          DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
68          zone = DateTimeZone.getDefault();
69          DateTimeZone.setDefault(LONDON);
70      }
71  
72      protected void tearDown() throws Exception {
73          DateTimeUtils.setCurrentMillisSystem();
74          DateTimeZone.setDefault(zone);
75          zone = null;
76      }
77  
78      //-----------------------------------------------------------------------
79      public void testPropertyGetHour() {
80          TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
81          assertSame(test.getChronology().hourOfDay(), test.hourOfDay().getField());
82          assertEquals("hourOfDay", test.hourOfDay().getName());
83          assertEquals("Property[hourOfDay]", test.hourOfDay().toString());
84          assertSame(test, test.hourOfDay().getReadablePartial());
85          assertSame(test, test.hourOfDay().getTimeOfDay());
86          assertEquals(10, test.hourOfDay().get());
87          assertEquals("10", test.hourOfDay().getAsString());
88          assertEquals("10", test.hourOfDay().getAsText());
89          assertEquals("10", test.hourOfDay().getAsText(Locale.FRENCH));
90          assertEquals("10", test.hourOfDay().getAsShortText());
91          assertEquals("10", test.hourOfDay().getAsShortText(Locale.FRENCH));
92          assertEquals(test.getChronology().hours(), test.hourOfDay().getDurationField());
93          assertEquals(test.getChronology().days(), test.hourOfDay().getRangeDurationField());
94          assertEquals(2, test.hourOfDay().getMaximumTextLength(null));
95          assertEquals(2, test.hourOfDay().getMaximumShortTextLength(null));
96      }
97  
98      public void testPropertyGetMaxMinValuesHour() {
99          TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
100         assertEquals(0, test.hourOfDay().getMinimumValue());
101         assertEquals(0, test.hourOfDay().getMinimumValueOverall());
102         assertEquals(23, test.hourOfDay().getMaximumValue());
103         assertEquals(23, test.hourOfDay().getMaximumValueOverall());
104     }
105 
106     public void testPropertyAddHour() {
107         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
108         TimeOfDay copy = test.hourOfDay().addToCopy(9);
109         check(test, 10, 20, 30, 40);
110         check(copy, 19, 20, 30, 40);
111         
112         copy = test.hourOfDay().addToCopy(0);
113         check(copy, 10, 20, 30, 40);
114         
115         copy = test.hourOfDay().addToCopy(13);
116         check(copy, 23, 20, 30, 40);
117         
118         copy = test.hourOfDay().addToCopy(14);
119         check(copy, 0, 20, 30, 40);
120         
121         copy = test.hourOfDay().addToCopy(-10);
122         check(copy, 0, 20, 30, 40);
123         
124         copy = test.hourOfDay().addToCopy(-11);
125         check(copy, 23, 20, 30, 40);
126     }
127 
128     public void testPropertyAddNoWrapHour() {
129         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
130         TimeOfDay copy = test.hourOfDay().addNoWrapToCopy(9);
131         check(test, 10, 20, 30, 40);
132         check(copy, 19, 20, 30, 40);
133         
134         copy = test.hourOfDay().addNoWrapToCopy(0);
135         check(copy, 10, 20, 30, 40);
136         
137         copy = test.hourOfDay().addNoWrapToCopy(13);
138         check(copy, 23, 20, 30, 40);
139         
140         try {
141             test.hourOfDay().addNoWrapToCopy(14);
142             fail();
143         } catch (IllegalArgumentException ex) {}
144         check(test, 10, 20, 30, 40);
145         
146         copy = test.hourOfDay().addNoWrapToCopy(-10);
147         check(copy, 0, 20, 30, 40);
148         
149         try {
150             test.hourOfDay().addNoWrapToCopy(-11);
151             fail();
152         } catch (IllegalArgumentException ex) {}
153         check(test, 10, 20, 30, 40);
154     }
155 
156     public void testPropertyAddWrapFieldHour() {
157         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
158         TimeOfDay copy = test.hourOfDay().addWrapFieldToCopy(9);
159         check(test, 10, 20, 30, 40);
160         check(copy, 19, 20, 30, 40);
161         
162         copy = test.hourOfDay().addWrapFieldToCopy(0);
163         check(copy, 10, 20, 30, 40);
164         
165         copy = test.hourOfDay().addWrapFieldToCopy(18);
166         check(copy, 4, 20, 30, 40);
167         
168         copy = test.hourOfDay().addWrapFieldToCopy(-15);
169         check(copy, 19, 20, 30, 40);
170     }
171 
172     public void testPropertySetHour() {
173         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
174         TimeOfDay copy = test.hourOfDay().setCopy(12);
175         check(test, 10, 20, 30, 40);
176         check(copy, 12, 20, 30, 40);
177         
178         try {
179             test.hourOfDay().setCopy(24);
180             fail();
181         } catch (IllegalArgumentException ex) {}
182         try {
183             test.hourOfDay().setCopy(-1);
184             fail();
185         } catch (IllegalArgumentException ex) {}
186     }
187 
188     public void testPropertySetTextHour() {
189         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
190         TimeOfDay copy = test.hourOfDay().setCopy("12");
191         check(test, 10, 20, 30, 40);
192         check(copy, 12, 20, 30, 40);
193     }
194 
195     public void testPropertyWithMaximumValueHour() {
196         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
197         TimeOfDay copy = test.hourOfDay().withMaximumValue();
198         check(test, 10, 20, 30, 40);
199         check(copy, 23, 20, 30, 40);
200     }
201 
202     public void testPropertyWithMinimumValueHour() {
203         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
204         TimeOfDay copy = test.hourOfDay().withMinimumValue();
205         check(test, 10, 20, 30, 40);
206         check(copy, 0, 20, 30, 40);
207     }
208 
209     public void testPropertyCompareToHour() {
210         TimeOfDay test1 = new TimeOfDay(TEST_TIME1);
211         TimeOfDay test2 = new TimeOfDay(TEST_TIME2);
212         assertEquals(true, test1.hourOfDay().compareTo(test2) < 0);
213         assertEquals(true, test2.hourOfDay().compareTo(test1) > 0);
214         assertEquals(true, test1.hourOfDay().compareTo(test1) == 0);
215         try {
216             test1.hourOfDay().compareTo((ReadablePartial) null);
217             fail();
218         } catch (IllegalArgumentException ex) {}
219         
220         DateTime dt1 = new DateTime(TEST_TIME1);
221         DateTime dt2 = new DateTime(TEST_TIME2);
222         assertEquals(true, test1.hourOfDay().compareTo(dt2) < 0);
223         assertEquals(true, test2.hourOfDay().compareTo(dt1) > 0);
224         assertEquals(true, test1.hourOfDay().compareTo(dt1) == 0);
225         try {
226             test1.hourOfDay().compareTo((ReadableInstant) null);
227             fail();
228         } catch (IllegalArgumentException ex) {}
229     }
230 
231     //-----------------------------------------------------------------------
232     public void testPropertyGetMinute() {
233         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
234         assertSame(test.getChronology().minuteOfHour(), test.minuteOfHour().getField());
235         assertEquals("minuteOfHour", test.minuteOfHour().getName());
236         assertEquals("Property[minuteOfHour]", test.minuteOfHour().toString());
237         assertSame(test, test.minuteOfHour().getReadablePartial());
238         assertSame(test, test.minuteOfHour().getTimeOfDay());
239         assertEquals(20, test.minuteOfHour().get());
240         assertEquals("20", test.minuteOfHour().getAsString());
241         assertEquals("20", test.minuteOfHour().getAsText());
242         assertEquals("20", test.minuteOfHour().getAsText(Locale.FRENCH));
243         assertEquals("20", test.minuteOfHour().getAsShortText());
244         assertEquals("20", test.minuteOfHour().getAsShortText(Locale.FRENCH));
245         assertEquals(test.getChronology().minutes(), test.minuteOfHour().getDurationField());
246         assertEquals(test.getChronology().hours(), test.minuteOfHour().getRangeDurationField());
247         assertEquals(2, test.minuteOfHour().getMaximumTextLength(null));
248         assertEquals(2, test.minuteOfHour().getMaximumShortTextLength(null));
249     }
250 
251     public void testPropertyGetMaxMinValuesMinute() {
252         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
253         assertEquals(0, test.minuteOfHour().getMinimumValue());
254         assertEquals(0, test.minuteOfHour().getMinimumValueOverall());
255         assertEquals(59, test.minuteOfHour().getMaximumValue());
256         assertEquals(59, test.minuteOfHour().getMaximumValueOverall());
257     }
258 
259     public void testPropertyAddMinute() {
260         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
261         TimeOfDay copy = test.minuteOfHour().addToCopy(9);
262         check(test, 10, 20, 30, 40);
263         check(copy, 10, 29, 30, 40);
264         
265         copy = test.minuteOfHour().addToCopy(39);
266         check(copy, 10, 59, 30, 40);
267         
268         copy = test.minuteOfHour().addToCopy(40);
269         check(copy, 11, 0, 30, 40);
270         
271         copy = test.minuteOfHour().addToCopy(1 * 60 + 45);
272         check(copy, 12, 5, 30, 40);
273         
274         copy = test.minuteOfHour().addToCopy(13 * 60 + 39);
275         check(copy, 23, 59, 30, 40);
276         
277         copy = test.minuteOfHour().addToCopy(13 * 60 + 40);
278         check(copy, 0, 0, 30, 40);
279         
280         copy = test.minuteOfHour().addToCopy(-9);
281         check(copy, 10, 11, 30, 40);
282         
283         copy = test.minuteOfHour().addToCopy(-19);
284         check(copy, 10, 1, 30, 40);
285         
286         copy = test.minuteOfHour().addToCopy(-20);
287         check(copy, 10, 0, 30, 40);
288         
289         copy = test.minuteOfHour().addToCopy(-21);
290         check(copy, 9, 59, 30, 40);
291         
292         copy = test.minuteOfHour().addToCopy(-(10 * 60 + 20));
293         check(copy, 0, 0, 30, 40);
294         
295         copy = test.minuteOfHour().addToCopy(-(10 * 60 + 21));
296         check(copy, 23, 59, 30, 40);
297     }
298 
299     public void testPropertyAddNoWrapMinute() {
300         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
301         TimeOfDay copy = test.minuteOfHour().addNoWrapToCopy(9);
302         check(test, 10, 20, 30, 40);
303         check(copy, 10, 29, 30, 40);
304         
305         copy = test.minuteOfHour().addNoWrapToCopy(39);
306         check(copy, 10, 59, 30, 40);
307         
308         copy = test.minuteOfHour().addNoWrapToCopy(40);
309         check(copy, 11, 0, 30, 40);
310         
311         copy = test.minuteOfHour().addNoWrapToCopy(1 * 60 + 45);
312         check(copy, 12, 5, 30, 40);
313         
314         copy = test.minuteOfHour().addNoWrapToCopy(13 * 60 + 39);
315         check(copy, 23, 59, 30, 40);
316         
317         try {
318             test.minuteOfHour().addNoWrapToCopy(13 * 60 + 40);
319             fail();
320         } catch (IllegalArgumentException ex) {}
321         check(test, 10, 20, 30, 40);
322         
323         copy = test.minuteOfHour().addNoWrapToCopy(-9);
324         check(copy, 10, 11, 30, 40);
325         
326         copy = test.minuteOfHour().addNoWrapToCopy(-19);
327         check(copy, 10, 1, 30, 40);
328         
329         copy = test.minuteOfHour().addNoWrapToCopy(-20);
330         check(copy, 10, 0, 30, 40);
331         
332         copy = test.minuteOfHour().addNoWrapToCopy(-21);
333         check(copy, 9, 59, 30, 40);
334         
335         copy = test.minuteOfHour().addNoWrapToCopy(-(10 * 60 + 20));
336         check(copy, 0, 0, 30, 40);
337         
338         try {
339             test.minuteOfHour().addNoWrapToCopy(-(10 * 60 + 21));
340             fail();
341         } catch (IllegalArgumentException ex) {}
342         check(test, 10, 20, 30, 40);
343     }
344 
345     public void testPropertyAddWrapFieldMinute() {
346         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
347         TimeOfDay copy = test.minuteOfHour().addWrapFieldToCopy(9);
348         check(test, 10, 20, 30, 40);
349         check(copy, 10, 29, 30, 40);
350         
351         copy = test.minuteOfHour().addWrapFieldToCopy(49);
352         check(copy, 10, 9, 30, 40);
353         
354         copy = test.minuteOfHour().addWrapFieldToCopy(-47);
355         check(copy, 10, 33, 30, 40);
356     }
357 
358     public void testPropertySetMinute() {
359         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
360         TimeOfDay copy = test.minuteOfHour().setCopy(12);
361         check(test, 10, 20, 30, 40);
362         check(copy, 10, 12, 30, 40);
363         
364         try {
365             test.minuteOfHour().setCopy(60);
366             fail();
367         } catch (IllegalArgumentException ex) {}
368         try {
369             test.minuteOfHour().setCopy(-1);
370             fail();
371         } catch (IllegalArgumentException ex) {}
372     }
373 
374     public void testPropertySetTextMinute() {
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 
381     public void testPropertyCompareToMinute() {
382         TimeOfDay test1 = new TimeOfDay(TEST_TIME1);
383         TimeOfDay test2 = new TimeOfDay(TEST_TIME2);
384         assertEquals(true, test1.minuteOfHour().compareTo(test2) < 0);
385         assertEquals(true, test2.minuteOfHour().compareTo(test1) > 0);
386         assertEquals(true, test1.minuteOfHour().compareTo(test1) == 0);
387         try {
388             test1.minuteOfHour().compareTo((ReadablePartial) null);
389             fail();
390         } catch (IllegalArgumentException ex) {}
391         
392         DateTime dt1 = new DateTime(TEST_TIME1);
393         DateTime dt2 = new DateTime(TEST_TIME2);
394         assertEquals(true, test1.minuteOfHour().compareTo(dt2) < 0);
395         assertEquals(true, test2.minuteOfHour().compareTo(dt1) > 0);
396         assertEquals(true, test1.minuteOfHour().compareTo(dt1) == 0);
397         try {
398             test1.minuteOfHour().compareTo((ReadableInstant) null);
399             fail();
400         } catch (IllegalArgumentException ex) {}
401     }
402 
403     //-----------------------------------------------------------------------
404     public void testPropertyGetSecond() {
405         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
406         assertSame(test.getChronology().secondOfMinute(), test.secondOfMinute().getField());
407         assertEquals("secondOfMinute", test.secondOfMinute().getName());
408         assertEquals("Property[secondOfMinute]", test.secondOfMinute().toString());
409         assertSame(test, test.secondOfMinute().getReadablePartial());
410         assertSame(test, test.secondOfMinute().getTimeOfDay());
411         assertEquals(30, test.secondOfMinute().get());
412         assertEquals("30", test.secondOfMinute().getAsString());
413         assertEquals("30", test.secondOfMinute().getAsText());
414         assertEquals("30", test.secondOfMinute().getAsText(Locale.FRENCH));
415         assertEquals("30", test.secondOfMinute().getAsShortText());
416         assertEquals("30", test.secondOfMinute().getAsShortText(Locale.FRENCH));
417         assertEquals(test.getChronology().seconds(), test.secondOfMinute().getDurationField());
418         assertEquals(test.getChronology().minutes(), test.secondOfMinute().getRangeDurationField());
419         assertEquals(2, test.secondOfMinute().getMaximumTextLength(null));
420         assertEquals(2, test.secondOfMinute().getMaximumShortTextLength(null));
421     }
422 
423     public void testPropertyGetMaxMinValuesSecond() {
424         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
425         assertEquals(0, test.secondOfMinute().getMinimumValue());
426         assertEquals(0, test.secondOfMinute().getMinimumValueOverall());
427         assertEquals(59, test.secondOfMinute().getMaximumValue());
428         assertEquals(59, test.secondOfMinute().getMaximumValueOverall());
429     }
430 
431     public void testPropertyAddSecond() {
432         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
433         TimeOfDay copy = test.secondOfMinute().addToCopy(9);
434         check(test, 10, 20, 30, 40);
435         check(copy, 10, 20, 39, 40);
436         
437         copy = test.secondOfMinute().addToCopy(29);
438         check(copy, 10, 20, 59, 40);
439         
440         copy = test.secondOfMinute().addToCopy(30);
441         check(copy, 10, 21, 0, 40);
442         
443         copy = test.secondOfMinute().addToCopy(39 * 60 + 29);
444         check(copy, 10, 59, 59, 40);
445         
446         copy = test.secondOfMinute().addToCopy(39 * 60 + 30);
447         check(copy, 11, 0, 0, 40);
448         
449         copy = test.secondOfMinute().addToCopy(13 * 60 * 60 + 39 * 60 + 30);
450         check(copy, 0, 0, 0, 40);
451         
452         copy = test.secondOfMinute().addToCopy(-9);
453         check(copy, 10, 20, 21, 40);
454         
455         copy = test.secondOfMinute().addToCopy(-30);
456         check(copy, 10, 20, 0, 40);
457         
458         copy = test.secondOfMinute().addToCopy(-31);
459         check(copy, 10, 19, 59, 40);
460         
461         copy = test.secondOfMinute().addToCopy(-(10 * 60 * 60 + 20 * 60 + 30));
462         check(copy, 0, 0, 0, 40);
463         
464         copy = test.secondOfMinute().addToCopy(-(10 * 60 * 60 + 20 * 60 + 31));
465         check(copy, 23, 59, 59, 40);
466     }
467 
468     public void testPropertyAddNoWrapSecond() {
469         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
470         TimeOfDay copy = test.secondOfMinute().addNoWrapToCopy(9);
471         check(test, 10, 20, 30, 40);
472         check(copy, 10, 20, 39, 40);
473         
474         copy = test.secondOfMinute().addNoWrapToCopy(29);
475         check(copy, 10, 20, 59, 40);
476         
477         copy = test.secondOfMinute().addNoWrapToCopy(30);
478         check(copy, 10, 21, 0, 40);
479         
480         copy = test.secondOfMinute().addNoWrapToCopy(39 * 60 + 29);
481         check(copy, 10, 59, 59, 40);
482         
483         copy = test.secondOfMinute().addNoWrapToCopy(39 * 60 + 30);
484         check(copy, 11, 0, 0, 40);
485         
486         try {
487             test.secondOfMinute().addNoWrapToCopy(13 * 60 * 60 + 39 * 60 + 30);
488             fail();
489         } catch (IllegalArgumentException ex) {}
490         check(test, 10, 20, 30, 40);
491         
492         copy = test.secondOfMinute().addNoWrapToCopy(-9);
493         check(copy, 10, 20, 21, 40);
494         
495         copy = test.secondOfMinute().addNoWrapToCopy(-30);
496         check(copy, 10, 20, 0, 40);
497         
498         copy = test.secondOfMinute().addNoWrapToCopy(-31);
499         check(copy, 10, 19, 59, 40);
500         
501         copy = test.secondOfMinute().addNoWrapToCopy(-(10 * 60 * 60 + 20 * 60 + 30));
502         check(copy, 0, 0, 0, 40);
503         
504         try {
505             test.secondOfMinute().addNoWrapToCopy(-(10 * 60 * 60 + 20 * 60 + 31));
506             fail();
507         } catch (IllegalArgumentException ex) {}
508         check(test, 10, 20, 30, 40);
509     }
510 
511     public void testPropertyAddWrapFieldSecond() {
512         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
513         TimeOfDay copy = test.secondOfMinute().addWrapFieldToCopy(9);
514         check(test, 10, 20, 30, 40);
515         check(copy, 10, 20, 39, 40);
516         
517         copy = test.secondOfMinute().addWrapFieldToCopy(49);
518         check(copy, 10, 20, 19, 40);
519         
520         copy = test.secondOfMinute().addWrapFieldToCopy(-47);
521         check(copy, 10, 20, 43, 40);
522     }
523 
524     public void testPropertySetSecond() {
525         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
526         TimeOfDay copy = test.secondOfMinute().setCopy(12);
527         check(test, 10, 20, 30, 40);
528         check(copy, 10, 20, 12, 40);
529         
530         try {
531             test.secondOfMinute().setCopy(60);
532             fail();
533         } catch (IllegalArgumentException ex) {}
534         try {
535             test.secondOfMinute().setCopy(-1);
536             fail();
537         } catch (IllegalArgumentException ex) {}
538     }
539 
540     public void testPropertySetTextSecond() {
541         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
542         TimeOfDay copy = test.secondOfMinute().setCopy("12");
543         check(test, 10, 20, 30, 40);
544         check(copy, 10, 20, 12, 40);
545     }
546 
547     public void testPropertyCompareToSecond() {
548         TimeOfDay test1 = new TimeOfDay(TEST_TIME1);
549         TimeOfDay test2 = new TimeOfDay(TEST_TIME2);
550         assertEquals(true, test1.secondOfMinute().compareTo(test2) < 0);
551         assertEquals(true, test2.secondOfMinute().compareTo(test1) > 0);
552         assertEquals(true, test1.secondOfMinute().compareTo(test1) == 0);
553         try {
554             test1.secondOfMinute().compareTo((ReadablePartial) null);
555             fail();
556         } catch (IllegalArgumentException ex) {}
557         
558         DateTime dt1 = new DateTime(TEST_TIME1);
559         DateTime dt2 = new DateTime(TEST_TIME2);
560         assertEquals(true, test1.secondOfMinute().compareTo(dt2) < 0);
561         assertEquals(true, test2.secondOfMinute().compareTo(dt1) > 0);
562         assertEquals(true, test1.secondOfMinute().compareTo(dt1) == 0);
563         try {
564             test1.secondOfMinute().compareTo((ReadableInstant) null);
565             fail();
566         } catch (IllegalArgumentException ex) {}
567     }
568 
569     //-----------------------------------------------------------------------
570     public void testPropertyGetMilli() {
571         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
572         assertSame(test.getChronology().millisOfSecond(), test.millisOfSecond().getField());
573         assertEquals("millisOfSecond", test.millisOfSecond().getName());
574         assertEquals("Property[millisOfSecond]", test.millisOfSecond().toString());
575         assertSame(test, test.millisOfSecond().getReadablePartial());
576         assertSame(test, test.millisOfSecond().getTimeOfDay());
577         assertEquals(40, test.millisOfSecond().get());
578         assertEquals("40", test.millisOfSecond().getAsString());
579         assertEquals("40", test.millisOfSecond().getAsText());
580         assertEquals("40", test.millisOfSecond().getAsText(Locale.FRENCH));
581         assertEquals("40", test.millisOfSecond().getAsShortText());
582         assertEquals("40", test.millisOfSecond().getAsShortText(Locale.FRENCH));
583         assertEquals(test.getChronology().millis(), test.millisOfSecond().getDurationField());
584         assertEquals(test.getChronology().seconds(), test.millisOfSecond().getRangeDurationField());
585         assertEquals(3, test.millisOfSecond().getMaximumTextLength(null));
586         assertEquals(3, test.millisOfSecond().getMaximumShortTextLength(null));
587     }
588 
589     public void testPropertyGetMaxMinValuesMilli() {
590         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
591         assertEquals(0, test.millisOfSecond().getMinimumValue());
592         assertEquals(0, test.millisOfSecond().getMinimumValueOverall());
593         assertEquals(999, test.millisOfSecond().getMaximumValue());
594         assertEquals(999, test.millisOfSecond().getMaximumValueOverall());
595     }
596 
597     public void testPropertyAddMilli() {
598         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
599         TimeOfDay copy = test.millisOfSecond().addToCopy(9);
600         check(test, 10, 20, 30, 40);
601         check(copy, 10, 20, 30, 49);
602         
603         copy = test.millisOfSecond().addToCopy(959);
604         check(copy, 10, 20, 30, 999);
605         
606         copy = test.millisOfSecond().addToCopy(960);
607         check(copy, 10, 20, 31, 0);
608         
609         copy = test.millisOfSecond().addToCopy(13 * 60 * 60 * 1000 + 39 * 60 * 1000 + 29 * 1000 + 959);
610         check(copy, 23, 59, 59, 999);
611         
612         copy = test.millisOfSecond().addToCopy(13 * 60 * 60 * 1000 + 39 * 60 * 1000 + 29 * 1000 + 960);
613         check(copy, 0, 0, 0, 0);
614         
615         copy = test.millisOfSecond().addToCopy(-9);
616         check(copy, 10, 20, 30, 31);
617         
618         copy = test.millisOfSecond().addToCopy(-40);
619         check(copy, 10, 20, 30, 0);
620         
621         copy = test.millisOfSecond().addToCopy(-41);
622         check(copy, 10, 20, 29, 999);
623         
624         copy = test.millisOfSecond().addToCopy(-(10 * 60 * 60 * 1000 + 20 * 60 * 1000 + 30 * 1000 + 40));
625         check(copy, 0, 0, 0, 0);
626         
627         copy = test.millisOfSecond().addToCopy(-(10 * 60 * 60 * 1000 + 20 * 60 * 1000 + 30 * 1000 + 41));
628         check(copy, 23, 59, 59, 999);
629     }
630 
631     public void testPropertyAddNoWrapMilli() {
632         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
633         TimeOfDay copy = test.millisOfSecond().addNoWrapToCopy(9);
634         check(test, 10, 20, 30, 40);
635         check(copy, 10, 20, 30, 49);
636         
637         copy = test.millisOfSecond().addNoWrapToCopy(959);
638         check(copy, 10, 20, 30, 999);
639         
640         copy = test.millisOfSecond().addNoWrapToCopy(960);
641         check(copy, 10, 20, 31, 0);
642         
643         copy = test.millisOfSecond().addNoWrapToCopy(13 * 60 * 60 * 1000 + 39 * 60 * 1000 + 29 * 1000 + 959);
644         check(copy, 23, 59, 59, 999);
645         
646         try {
647             test.millisOfSecond().addNoWrapToCopy(13 * 60 * 60 * 1000 + 39 * 60 * 1000 + 29 * 1000 + 960);
648             fail();
649         } catch (IllegalArgumentException ex) {}
650         check(test, 10, 20, 30, 40);
651         
652         copy = test.millisOfSecond().addNoWrapToCopy(-9);
653         check(copy, 10, 20, 30, 31);
654         
655         copy = test.millisOfSecond().addNoWrapToCopy(-40);
656         check(copy, 10, 20, 30, 0);
657         
658         copy = test.millisOfSecond().addNoWrapToCopy(-41);
659         check(copy, 10, 20, 29, 999);
660         
661         copy = test.millisOfSecond().addNoWrapToCopy(-(10 * 60 * 60 * 1000 + 20 * 60 * 1000 + 30 * 1000 + 40));
662         check(copy, 0, 0, 0, 0);
663         
664         try {
665             test.millisOfSecond().addNoWrapToCopy(-(10 * 60 * 60 * 1000 + 20 * 60 * 1000 + 30 * 1000 + 41));
666             fail();
667         } catch (IllegalArgumentException ex) {}
668         check(test, 10, 20, 30, 40);
669     }
670 
671     public void testPropertyAddWrapFieldMilli() {
672         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
673         TimeOfDay copy = test.millisOfSecond().addWrapFieldToCopy(9);
674         check(test, 10, 20, 30, 40);
675         check(copy, 10, 20, 30, 49);
676         
677         copy = test.millisOfSecond().addWrapFieldToCopy(995);
678         check(copy, 10, 20, 30, 35);
679         
680         copy = test.millisOfSecond().addWrapFieldToCopy(-47);
681         check(copy, 10, 20, 30, 993);
682     }
683 
684     public void testPropertySetMilli() {
685         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
686         TimeOfDay copy = test.millisOfSecond().setCopy(12);
687         check(test, 10, 20, 30, 40);
688         check(copy, 10, 20, 30, 12);
689         
690         try {
691             test.millisOfSecond().setCopy(1000);
692             fail();
693         } catch (IllegalArgumentException ex) {}
694         try {
695             test.millisOfSecond().setCopy(-1);
696             fail();
697         } catch (IllegalArgumentException ex) {}
698     }
699 
700     public void testPropertySetTextMilli() {
701         TimeOfDay test = new TimeOfDay(10, 20, 30, 40);
702         TimeOfDay copy = test.millisOfSecond().setCopy("12");
703         check(test, 10, 20, 30, 40);
704         check(copy, 10, 20, 30, 12);
705     }
706 
707     public void testPropertyCompareToMilli() {
708         TimeOfDay test1 = new TimeOfDay(TEST_TIME1);
709         TimeOfDay test2 = new TimeOfDay(TEST_TIME2);
710         assertEquals(true, test1.millisOfSecond().compareTo(test2) < 0);
711         assertEquals(true, test2.millisOfSecond().compareTo(test1) > 0);
712         assertEquals(true, test1.millisOfSecond().compareTo(test1) == 0);
713         try {
714             test1.millisOfSecond().compareTo((ReadablePartial) null);
715             fail();
716         } catch (IllegalArgumentException ex) {}
717         
718         DateTime dt1 = new DateTime(TEST_TIME1);
719         DateTime dt2 = new DateTime(TEST_TIME2);
720         assertEquals(true, test1.millisOfSecond().compareTo(dt2) < 0);
721         assertEquals(true, test2.millisOfSecond().compareTo(dt1) > 0);
722         assertEquals(true, test1.millisOfSecond().compareTo(dt1) == 0);
723         try {
724             test1.millisOfSecond().compareTo((ReadableInstant) null);
725             fail();
726         } catch (IllegalArgumentException ex) {}
727     }
728 
729     //-----------------------------------------------------------------------
730     private void check(TimeOfDay test, int hour, int min, int sec, int milli) {
731         assertEquals(hour, test.getHourOfDay());
732         assertEquals(min, test.getMinuteOfHour());
733         assertEquals(sec, test.getSecondOfMinute());
734         assertEquals(milli, test.getMillisOfSecond());
735     }
736 }