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  import java.util.TimeZone;
20  
21  import junit.framework.TestCase;
22  import junit.framework.TestSuite;
23  
24  import org.joda.time.chrono.ISOChronology;
25  
26  /**
27   * This class is a JUnit test for MutableDuration.
28   *
29   * @author Stephen Colebourne
30   */
31  public class TestMutablePeriod_Updates extends TestCase {
32      // Test in 2002/03 as time zones are more well known
33      // (before the late 90's they were all over the place)
34  
35      private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
36      private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
37      
38      long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
39                       366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
40                       365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
41                       366 + 365;
42      long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
43                       366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
44                       365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
45                       366 + 365 + 365;
46      
47      // 2002-06-09
48      private long TEST_TIME_NOW =
49              (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
50              
51      // 2002-04-05
52      private long TEST_TIME1 =
53              (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY
54              + 12L * DateTimeConstants.MILLIS_PER_HOUR
55              + 24L * DateTimeConstants.MILLIS_PER_MINUTE;
56          
57      // 2003-05-06
58      private long TEST_TIME2 =
59              (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
60              + 14L * DateTimeConstants.MILLIS_PER_HOUR
61              + 28L * DateTimeConstants.MILLIS_PER_MINUTE;
62      
63      private DateTimeZone originalDateTimeZone = null;
64      private TimeZone originalTimeZone = null;
65      private Locale originalLocale = null;
66  
67      public static void main(String[] args) {
68          junit.textui.TestRunner.run(suite());
69      }
70  
71      public static TestSuite suite() {
72          return new TestSuite(TestMutablePeriod_Updates.class);
73      }
74  
75      public TestMutablePeriod_Updates(String name) {
76          super(name);
77      }
78  
79      protected void setUp() throws Exception {
80          DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
81          originalDateTimeZone = DateTimeZone.getDefault();
82          originalTimeZone = TimeZone.getDefault();
83          originalLocale = Locale.getDefault();
84          DateTimeZone.setDefault(LONDON);
85          TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
86          Locale.setDefault(Locale.UK);
87      }
88  
89      protected void tearDown() throws Exception {
90          DateTimeUtils.setCurrentMillisSystem();
91          DateTimeZone.setDefault(originalDateTimeZone);
92          TimeZone.setDefault(originalTimeZone);
93          Locale.setDefault(originalLocale);
94          originalDateTimeZone = null;
95          originalTimeZone = null;
96          originalLocale = null;
97      }
98  
99      //-----------------------------------------------------------------------
100     public void testTest() {
101         assertEquals("2002-06-09T00:00:00.000Z", new Instant(TEST_TIME_NOW).toString());
102         assertEquals("2002-04-05T12:24:00.000Z", new Instant(TEST_TIME1).toString());
103         assertEquals("2003-05-06T14:28:00.000Z", new Instant(TEST_TIME2).toString());
104     }
105 
106     //-----------------------------------------------------------------------
107     public void testClear() {
108         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
109         test.clear();
110         assertEquals(new MutablePeriod(), test);
111         
112         test = new MutablePeriod(1, 2, 0, 4, 5, 6, 7, 8, PeriodType.yearMonthDayTime());
113         test.clear();
114         assertEquals(new MutablePeriod(PeriodType.yearMonthDayTime()), test);
115     }
116 
117     //-----------------------------------------------------------------------
118     public void testAddYears() {
119         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
120         test.addYears(10);
121         assertEquals(11, test.getYears());
122         
123         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
124         test.addYears(-10);
125         assertEquals(-9, test.getYears());
126         
127         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
128         test.addYears(0);
129         assertEquals(1, test.getYears());
130     }
131 
132     //-----------------------------------------------------------------------
133     public void testAddMonths() {
134         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
135         test.addMonths(10);
136         assertEquals(12, test.getMonths());
137         
138         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
139         test.addMonths(-10);
140         assertEquals(-8, test.getMonths());
141         
142         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
143         test.addMonths(0);
144         assertEquals(2, test.getMonths());
145     }
146 
147     //-----------------------------------------------------------------------
148     public void testAddWeeks() {
149         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
150         test.addWeeks(10);
151         assertEquals(13, test.getWeeks());
152         
153         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
154         test.addWeeks(-10);
155         assertEquals(-7, test.getWeeks());
156         
157         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
158         test.addWeeks(0);
159         assertEquals(3, test.getWeeks());
160     }
161 
162     //-----------------------------------------------------------------------
163     public void testAddDays() {
164         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
165         test.addDays(10);
166         assertEquals(14, test.getDays());
167         
168         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
169         test.addDays(-10);
170         assertEquals(-6, test.getDays());
171         
172         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
173         test.addDays(0);
174         assertEquals(4, test.getDays());
175     }
176 
177     //-----------------------------------------------------------------------
178     public void testAddHours() {
179         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
180         test.addHours(10);
181         assertEquals(15, test.getHours());
182         
183         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
184         test.addHours(-10);
185         assertEquals(-5, test.getHours());
186         
187         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
188         test.addHours(0);
189         assertEquals(5, test.getHours());
190     }
191 
192     //-----------------------------------------------------------------------
193     public void testAddMinutes() {
194         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
195         test.addMinutes(10);
196         assertEquals(16, test.getMinutes());
197         
198         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
199         test.addMinutes(-10);
200         assertEquals(-4, test.getMinutes());
201         
202         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
203         test.addMinutes(0);
204         assertEquals(6, test.getMinutes());
205     }
206 
207     //-----------------------------------------------------------------------
208     public void testAddSeconds() {
209         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
210         test.addSeconds(10);
211         assertEquals(17, test.getSeconds());
212         
213         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
214         test.addSeconds(-10);
215         assertEquals(-3, test.getSeconds());
216         
217         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
218         test.addSeconds(0);
219         assertEquals(7, test.getSeconds());
220     }
221 
222     //-----------------------------------------------------------------------
223     public void testAddMillis() {
224         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
225         test.addMillis(10);
226         assertEquals(18, test.getMillis());
227         
228         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
229         test.addMillis(-10);
230         assertEquals(-2, test.getMillis());
231         
232         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
233         test.addMillis(0);
234         assertEquals(8, test.getMillis());
235     }
236 
237     //-----------------------------------------------------------------------
238     public void testSetYears() {
239         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
240         test.setYears(10);
241         assertEquals(10, test.getYears());
242         
243         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
244         test.setYears(-10);
245         assertEquals(-10, test.getYears());
246         
247         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
248         test.setYears(0);
249         assertEquals(0, test.getYears());
250         
251         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
252         test.setYears(1);
253         assertEquals(1, test.getYears());
254         
255         test = new MutablePeriod(0, 0, 0, 0, 0, 0, 0, 1, PeriodType.millis());
256         try {
257             test.setYears(1);
258             fail();
259         } catch (IllegalArgumentException ex) {}
260     }
261 
262     //-----------------------------------------------------------------------
263     public void testSetMonths() {
264         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
265         test.setMonths(10);
266         assertEquals(10, test.getMonths());
267         
268         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
269         test.setMonths(-10);
270         assertEquals(-10, test.getMonths());
271         
272         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
273         test.setMonths(0);
274         assertEquals(0, test.getMonths());
275         
276         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
277         test.setMonths(2);
278         assertEquals(2, test.getMonths());
279     }
280 
281     //-----------------------------------------------------------------------
282     public void testSetWeeks() {
283         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
284         test.setWeeks(10);
285         assertEquals(10, test.getWeeks());
286         
287         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
288         test.setWeeks(-10);
289         assertEquals(-10, test.getWeeks());
290         
291         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
292         test.setWeeks(0);
293         assertEquals(0, test.getWeeks());
294         
295         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
296         test.setWeeks(3);
297         assertEquals(3, test.getWeeks());
298     }
299 
300     //-----------------------------------------------------------------------
301     public void testSetDays() {
302         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
303         test.setDays(10);
304         assertEquals(10, test.getDays());
305         
306         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
307         test.setDays(-10);
308         assertEquals(-10, test.getDays());
309         
310         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
311         test.setDays(0);
312         assertEquals(0, test.getDays());
313         
314         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
315         test.setDays(4);
316         assertEquals(4, test.getDays());
317     }
318 
319     //-----------------------------------------------------------------------
320     public void testSetHours() {
321         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
322         test.setHours(10);
323         assertEquals(10, test.getHours());
324         
325         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
326         test.setHours(-10);
327         assertEquals(-10, test.getHours());
328         
329         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
330         test.setHours(0);
331         assertEquals(0, test.getHours());
332         
333         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
334         test.setHours(5);
335         assertEquals(5, test.getHours());
336     }
337 
338     //-----------------------------------------------------------------------
339     public void testSetMinutes() {
340         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
341         test.setMinutes(10);
342         assertEquals(10, test.getMinutes());
343         
344         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
345         test.setMinutes(-10);
346         assertEquals(-10, test.getMinutes());
347         
348         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
349         test.setMinutes(0);
350         assertEquals(0, test.getMinutes());
351         
352         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
353         test.setMinutes(6);
354         assertEquals(6, test.getMinutes());
355     }
356 
357     //-----------------------------------------------------------------------
358     public void testSetSeconds() {
359         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
360         test.setSeconds(10);
361         assertEquals(10, test.getSeconds());
362         
363         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
364         test.setSeconds(-10);
365         assertEquals(-10, test.getSeconds());
366         
367         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
368         test.setSeconds(0);
369         assertEquals(0, test.getSeconds());
370         
371         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
372         test.setSeconds(7);
373         assertEquals(7, test.getSeconds());
374     }
375 
376     //-----------------------------------------------------------------------
377     public void testSetMillis() {
378         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
379         test.setMillis(10);
380         assertEquals(10, test.getMillis());
381         
382         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
383         test.setMillis(-10);
384         assertEquals(-10, test.getMillis());
385         
386         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
387         test.setMillis(0);
388         assertEquals(0, test.getMillis());
389         
390         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
391         test.setMillis(8);
392         assertEquals(8, test.getMillis());
393     }
394 
395     //-----------------------------------------------------------------------
396     public void testSet_Field() {
397         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
398         test.set(DurationFieldType.years(), 10);
399         assertEquals(10, test.getYears());
400         
401         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
402         try {
403             test.set(null, 10);
404             fail();
405         } catch (IllegalArgumentException ex) {}
406     }
407 
408     //-----------------------------------------------------------------------
409     public void testAdd_Field() {
410         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
411         test.add(DurationFieldType.years(), 10);
412         assertEquals(11, test.getYears());
413         
414         test = new MutablePeriod(0, 0, 0, 0, 0, 0, 0, 1, PeriodType.millis());
415         test.add(DurationFieldType.years(), 0);
416         assertEquals(0, test.getYears());
417         assertEquals(1, test.getMillis());
418         
419         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
420         try {
421             test.add(null, 0);
422             fail();
423         } catch (IllegalArgumentException ex) {}
424         
425         test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
426         try {
427             test.add(null, 10);
428             fail();
429         } catch (IllegalArgumentException ex) {}
430     }
431 
432     //-----------------------------------------------------------------------
433     public void testSetPeriod_8ints1() {
434         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
435         test.setPeriod(11, 12, 13, 14, 15, 16, 17, 18);
436         assertEquals(11, test.getYears());
437         assertEquals(12, test.getMonths());
438         assertEquals(13, test.getWeeks());
439         assertEquals(14, test.getDays());
440         assertEquals(15, test.getHours());
441         assertEquals(16, test.getMinutes());
442         assertEquals(17, test.getSeconds());
443         assertEquals(18, test.getMillis());
444     }
445 
446     public void testSetPeriod_8ints2() {
447         MutablePeriod test = new MutablePeriod(100L, PeriodType.millis());
448         try {
449             test.setPeriod(11, 12, 13, 14, 15, 16, 17, 18);
450             fail();
451         } catch (IllegalArgumentException ex) {}
452         assertEquals(0, test.getYears());
453         assertEquals(0, test.getMonths());
454         assertEquals(0, test.getWeeks());
455         assertEquals(0, test.getDays());
456         assertEquals(0, test.getHours());
457         assertEquals(0, test.getMinutes());
458         assertEquals(0, test.getSeconds());
459         assertEquals(100, test.getMillis());
460     }
461 
462     public void testSetPeriod_8ints3() {
463         MutablePeriod test = new MutablePeriod(100L, PeriodType.millis());
464         test.setPeriod(0, 0, 0, 0, 0, 0, 0, 18);
465         assertEquals(0, test.getYears());
466         assertEquals(0, test.getMonths());
467         assertEquals(0, test.getWeeks());
468         assertEquals(0, test.getDays());
469         assertEquals(0, test.getHours());
470         assertEquals(0, test.getMinutes());
471         assertEquals(0, test.getSeconds());
472         assertEquals(18, test.getMillis());
473     }
474 
475     public void testSetPeriod_8ints4() {
476         MutablePeriod test = new MutablePeriod(0, 0, 0, 0, 5, 6, 7, 8);
477         test.setPeriod(11, 12, 13, 14, 15, 16, 17, 18);
478         assertEquals(11, test.getYears());
479         assertEquals(12, test.getMonths());
480         assertEquals(13, test.getWeeks());
481         assertEquals(14, test.getDays());
482         assertEquals(15, test.getHours());
483         assertEquals(16, test.getMinutes());
484         assertEquals(17, test.getSeconds());
485         assertEquals(18, test.getMillis());
486     }
487 
488     //-----------------------------------------------------------------------
489     public void testSetPeriod_RP1() {
490         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
491         test.setPeriod(new MutablePeriod(11, 12, 13, 14, 15, 16, 17, 18));
492         assertEquals(11, test.getYears());
493         assertEquals(12, test.getMonths());
494         assertEquals(13, test.getWeeks());
495         assertEquals(14, test.getDays());
496         assertEquals(15, test.getHours());
497         assertEquals(16, test.getMinutes());
498         assertEquals(17, test.getSeconds());
499         assertEquals(18, test.getMillis());
500     }
501 
502     public void testSetPeriod_RP2() {
503         MutablePeriod test = new MutablePeriod(100L, PeriodType.millis());
504         try {
505             test.setPeriod(new MutablePeriod(11, 12, 13, 14, 15, 16, 17, 18));
506             fail();
507         } catch (IllegalArgumentException ex) {}
508         assertEquals(0, test.getYears());
509         assertEquals(0, test.getMonths());
510         assertEquals(0, test.getWeeks());
511         assertEquals(0, test.getDays());
512         assertEquals(0, test.getHours());
513         assertEquals(0, test.getMinutes());
514         assertEquals(0, test.getSeconds());
515         assertEquals(100, test.getMillis());
516     }
517 
518     public void testSetPeriod_RP3() {
519         MutablePeriod test = new MutablePeriod(100L, PeriodType.millis());
520         test.setPeriod(new MutablePeriod(0, 0, 0, 0, 0, 0, 0, 18));
521         assertEquals(0, test.getYears());
522         assertEquals(0, test.getMonths());
523         assertEquals(0, test.getWeeks());
524         assertEquals(0, test.getDays());
525         assertEquals(0, test.getHours());
526         assertEquals(0, test.getMinutes());
527         assertEquals(0, test.getSeconds());
528         assertEquals(18, test.getMillis());
529     }
530 
531     public void testSetPeriod_RP4() {
532         MutablePeriod test = new MutablePeriod(0, 0, 0, 0, 5, 6, 7, 8);
533         test.setPeriod(new MutablePeriod(11, 12, 13, 14, 15, 16, 17, 18));
534         assertEquals(11, test.getYears());
535         assertEquals(12, test.getMonths());
536         assertEquals(13, test.getWeeks());
537         assertEquals(14, test.getDays());
538         assertEquals(15, test.getHours());
539         assertEquals(16, test.getMinutes());
540         assertEquals(17, test.getSeconds());
541         assertEquals(18, test.getMillis());
542     }
543 
544     public void testSetPeriod_RP5() {
545         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
546         test.setPeriod((ReadablePeriod) null);
547         assertEquals(0, test.getYears());
548         assertEquals(0, test.getMonths());
549         assertEquals(0, test.getWeeks());
550         assertEquals(0, test.getDays());
551         assertEquals(0, test.getHours());
552         assertEquals(0, test.getMinutes());
553         assertEquals(0, test.getSeconds());
554         assertEquals(0, test.getMillis());
555     }
556 
557     //-----------------------------------------------------------------------
558     public void testSetPeriod_long_long1() {
559         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
560         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
561         DateTime dt2 = new DateTime(2003, 7, 17, 14, 16, 18, 20);
562         test.setPeriod(dt1.getMillis(), dt2.getMillis());
563         assertEquals(1, test.getYears());
564         assertEquals(1, test.getMonths());
565         assertEquals(1, test.getWeeks());
566         assertEquals(1, test.getDays());
567         assertEquals(1, test.getHours());
568         assertEquals(1, test.getMinutes());
569         assertEquals(1, test.getSeconds());
570         assertEquals(1, test.getMillis());
571     }
572 
573     public void testSetPeriod_long_long2() {
574         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
575         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
576         DateTime dt2 = new DateTime(2003, 7, 17, 14, 16, 18, 20);
577         test.setPeriod(dt2.getMillis(), dt1.getMillis());
578         assertEquals(-1, test.getYears());
579         assertEquals(-1, test.getMonths());
580         assertEquals(-1, test.getWeeks());
581         assertEquals(-1, test.getDays());
582         assertEquals(-1, test.getHours());
583         assertEquals(-1, test.getMinutes());
584         assertEquals(-1, test.getSeconds());
585         assertEquals(-1, test.getMillis());
586     }
587 
588     public void testSetPeriod_long_long3() {
589         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
590         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
591         test.setPeriod(dt1.getMillis(), dt1.getMillis());
592         assertEquals(0, test.getYears());
593         assertEquals(0, test.getMonths());
594         assertEquals(0, test.getWeeks());
595         assertEquals(0, test.getDays());
596         assertEquals(0, test.getHours());
597         assertEquals(0, test.getMinutes());
598         assertEquals(0, test.getSeconds());
599         assertEquals(0, test.getMillis());
600     }
601 
602     public void testSetPeriod_long_long_NoYears() {
603         MutablePeriod test = new MutablePeriod(PeriodType.standard().withYearsRemoved());
604         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
605         DateTime dt2 = new DateTime(2003, 7, 17, 14, 16, 18, 20);
606         test.setPeriod(dt1.getMillis(), dt2.getMillis());
607         assertEquals(0, test.getYears());
608         assertEquals(13, test.getMonths());
609         assertEquals(1, test.getWeeks());
610         assertEquals(1, test.getDays());
611         assertEquals(1, test.getHours());
612         assertEquals(1, test.getMinutes());
613         assertEquals(1, test.getSeconds());
614         assertEquals(1, test.getMillis());
615     }
616 
617     public void testSetPeriod_long_long_NoMonths() {
618         MutablePeriod test = new MutablePeriod(PeriodType.standard().withMonthsRemoved());
619         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
620         DateTime dt2 = new DateTime(2003, 7, 17, 14, 16, 18, 20);
621         test.setPeriod(dt1.getMillis(), dt2.getMillis());
622         assertEquals(1, test.getYears());
623         assertEquals(0, test.getMonths());
624         assertEquals(5, test.getWeeks());
625         assertEquals(3, test.getDays());
626         assertEquals(1, test.getHours());
627         assertEquals(1, test.getMinutes());
628         assertEquals(1, test.getSeconds());
629         assertEquals(1, test.getMillis());
630     }
631 
632     public void testSetPeriod_long_long_NoWeeks() {
633         MutablePeriod test = new MutablePeriod(PeriodType.standard().withWeeksRemoved());
634         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
635         DateTime dt2 = new DateTime(2003, 7, 17, 14, 16, 18, 20);
636         test.setPeriod(dt1.getMillis(), dt2.getMillis());
637         assertEquals(1, test.getYears());
638         assertEquals(1, test.getMonths());
639         assertEquals(0, test.getWeeks());
640         assertEquals(8, test.getDays());
641         assertEquals(1, test.getHours());
642         assertEquals(1, test.getMinutes());
643         assertEquals(1, test.getSeconds());
644         assertEquals(1, test.getMillis());
645     }
646 
647     public void testSetPeriod_long_long_NoDays() {
648         MutablePeriod test = new MutablePeriod(PeriodType.standard().withDaysRemoved());
649         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
650         DateTime dt2 = new DateTime(2003, 7, 17, 14, 16, 18, 20);
651         test.setPeriod(dt1.getMillis(), dt2.getMillis());
652         assertEquals(1, test.getYears());
653         assertEquals(1, test.getMonths());
654         assertEquals(1, test.getWeeks());
655         assertEquals(0, test.getDays());
656         assertEquals(25, test.getHours());
657         assertEquals(1, test.getMinutes());
658         assertEquals(1, test.getSeconds());
659         assertEquals(1, test.getMillis());
660     }
661 
662     public void testSetPeriod_long_long_NoHours() {
663         MutablePeriod test = new MutablePeriod(PeriodType.standard().withHoursRemoved());
664         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
665         DateTime dt2 = new DateTime(2003, 7, 17, 14, 16, 18, 20);
666         test.setPeriod(dt1.getMillis(), dt2.getMillis());
667         assertEquals(1, test.getYears());
668         assertEquals(1, test.getMonths());
669         assertEquals(1, test.getWeeks());
670         assertEquals(1, test.getDays());
671         assertEquals(0, test.getHours());
672         assertEquals(61, test.getMinutes());
673         assertEquals(1, test.getSeconds());
674         assertEquals(1, test.getMillis());
675     }
676 
677     public void testSetPeriod_long_long_NoMinutes() {
678         MutablePeriod test = new MutablePeriod(PeriodType.standard().withMinutesRemoved());
679         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
680         DateTime dt2 = new DateTime(2003, 7, 17, 14, 16, 18, 20);
681         test.setPeriod(dt1.getMillis(), dt2.getMillis());
682         assertEquals(1, test.getYears());
683         assertEquals(1, test.getMonths());
684         assertEquals(1, test.getWeeks());
685         assertEquals(1, test.getDays());
686         assertEquals(1, test.getHours());
687         assertEquals(0, test.getMinutes());
688         assertEquals(61, test.getSeconds());
689         assertEquals(1, test.getMillis());
690     }
691 
692     public void testSetPeriod_long_long_NoSeconds() {
693         MutablePeriod test = new MutablePeriod(PeriodType.standard().withSecondsRemoved());
694         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
695         DateTime dt2 = new DateTime(2003, 7, 17, 14, 16, 18, 20);
696         test.setPeriod(dt1.getMillis(), dt2.getMillis());
697         assertEquals(1, test.getYears());
698         assertEquals(1, test.getMonths());
699         assertEquals(1, test.getWeeks());
700         assertEquals(1, test.getDays());
701         assertEquals(1, test.getHours());
702         assertEquals(1, test.getMinutes());
703         assertEquals(0, test.getSeconds());
704         assertEquals(1001, test.getMillis());
705     }
706 
707     public void testSetPeriod_long_long_NoMillis() {
708         MutablePeriod test = new MutablePeriod(PeriodType.standard().withMillisRemoved());
709         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
710         DateTime dt2 = new DateTime(2003, 7, 17, 14, 16, 18, 20);
711         test.setPeriod(dt1.getMillis(), dt2.getMillis());
712         assertEquals(1, test.getYears());
713         assertEquals(1, test.getMonths());
714         assertEquals(1, test.getWeeks());
715         assertEquals(1, test.getDays());
716         assertEquals(1, test.getHours());
717         assertEquals(1, test.getMinutes());
718         assertEquals(1, test.getSeconds());
719         assertEquals(0, test.getMillis());
720     }
721 
722     //-----------------------------------------------------------------------
723     public void testSetPeriod_RI_RI1() {
724         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
725         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
726         DateTime dt2 = new DateTime(2003, 7, 17, 14, 16, 18, 20);
727         test.setPeriod(dt1, dt2);
728         assertEquals(1, test.getYears());
729         assertEquals(1, test.getMonths());
730         assertEquals(1, test.getWeeks());
731         assertEquals(1, test.getDays());
732         assertEquals(1, test.getHours());
733         assertEquals(1, test.getMinutes());
734         assertEquals(1, test.getSeconds());
735         assertEquals(1, test.getMillis());
736     }
737 
738     public void testSetPeriod_RI_RI2() {
739         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
740         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
741         DateTime dt2 = new DateTime(2003, 7, 17, 14, 16, 18, 20);
742         test.setPeriod(dt2, dt1);
743         assertEquals(-1, test.getYears());
744         assertEquals(-1, test.getMonths());
745         assertEquals(-1, test.getWeeks());
746         assertEquals(-1, test.getDays());
747         assertEquals(-1, test.getHours());
748         assertEquals(-1, test.getMinutes());
749         assertEquals(-1, test.getSeconds());
750         assertEquals(-1, test.getMillis());
751     }
752 
753     public void testSetPeriod_RI_RI3() {
754         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
755         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
756         test.setPeriod(dt1, dt1);
757         assertEquals(0, test.getYears());
758         assertEquals(0, test.getMonths());
759         assertEquals(0, test.getWeeks());
760         assertEquals(0, test.getDays());
761         assertEquals(0, test.getHours());
762         assertEquals(0, test.getMinutes());
763         assertEquals(0, test.getSeconds());
764         assertEquals(0, test.getMillis());
765     }
766 
767     //-----------------------------------------------------------------------
768     public void testSetPeriod_RInterval1() {
769         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
770         DateTime dt1 = new DateTime(2002, 6, 9, 13, 15, 17, 19);
771         DateTime dt2 = new DateTime(2003, 7, 17, 14, 16, 18, 20);
772         test.setPeriod(new Interval(dt1, dt2));
773         assertEquals(1, test.getYears());
774         assertEquals(1, test.getMonths());
775         assertEquals(1, test.getWeeks());
776         assertEquals(1, test.getDays());
777         assertEquals(1, test.getHours());
778         assertEquals(1, test.getMinutes());
779         assertEquals(1, test.getSeconds());
780         assertEquals(1, test.getMillis());
781     }
782 
783     public void testSetPeriod_RInterval2() {
784         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
785         test.setPeriod((ReadableInterval) null);
786         assertEquals(0, test.getYears());
787         assertEquals(0, test.getMonths());
788         assertEquals(0, test.getWeeks());
789         assertEquals(0, test.getDays());
790         assertEquals(0, test.getHours());
791         assertEquals(0, test.getMinutes());
792         assertEquals(0, test.getSeconds());
793         assertEquals(0, test.getMillis());
794     }
795 
796     //-----------------------------------------------------------------------
797     public void testSetPeriod_long1() {
798         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
799         test.setPeriod(100L);
800         assertEquals(0, test.getYears());
801         assertEquals(0, test.getMonths());
802         assertEquals(0, test.getWeeks());
803         assertEquals(0, test.getDays());
804         assertEquals(0, test.getHours());
805         assertEquals(0, test.getMinutes());
806         assertEquals(0, test.getSeconds());
807         assertEquals(100, test.getMillis());
808     }
809 
810     public void testSetPeriod_long2() {
811         MutablePeriod test = new MutablePeriod();
812         test.setPeriod(
813             (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
814             5L * DateTimeConstants.MILLIS_PER_HOUR +
815             6L * DateTimeConstants.MILLIS_PER_MINUTE +
816             7L * DateTimeConstants.MILLIS_PER_SECOND + 8L);
817         // only time fields are precise
818         assertEquals(0, test.getYears());  // (4 + (3 * 7) + (2 * 30) + 365) == 450
819         assertEquals(0, test.getMonths());
820         assertEquals(0, test.getWeeks());
821         assertEquals(0, test.getDays());
822         assertEquals((450 * 24) + 5, test.getHours());
823         assertEquals(6, test.getMinutes());
824         assertEquals(7, test.getSeconds());
825         assertEquals(8, test.getMillis());
826     }
827 
828 //    public void testSetPeriod_long3() {
829 //        MutablePeriod test = new MutablePeriod(PeriodType.getPreciseYearMonthType());
830 //        test.setPeriod(
831 //            (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
832 //            5L * DateTimeConstants.MILLIS_PER_HOUR +
833 //            6L * DateTimeConstants.MILLIS_PER_MINUTE +
834 //            7L * DateTimeConstants.MILLIS_PER_SECOND + 8L);
835 //        assertEquals(1, test.getYears());
836 //        assertEquals(2, test.getMonths());
837 //        assertEquals(0, test.getWeeks());
838 //        assertEquals(25, test.getDays());
839 //        assertEquals(5, test.getHours());
840 //        assertEquals(6, test.getMinutes());
841 //        assertEquals(7, test.getSeconds());
842 //        assertEquals(8, test.getMillis());
843 //    }
844 //
845 //    public void testSetPeriod_long4() {
846 //        MutablePeriod test = new MutablePeriod(PeriodType.getPreciseYearWeekType());
847 //        test.setPeriod(
848 //            (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
849 //            5L * DateTimeConstants.MILLIS_PER_HOUR +
850 //            6L * DateTimeConstants.MILLIS_PER_MINUTE +
851 //            7L * DateTimeConstants.MILLIS_PER_SECOND + 8L);
852 //        assertEquals(1, test.getYears());
853 //        assertEquals(0, test.getMonths());
854 //        assertEquals(12, test.getWeeks());
855 //        assertEquals(1, test.getDays());
856 //        assertEquals(5, test.getHours());
857 //        assertEquals(6, test.getMinutes());
858 //        assertEquals(7, test.getSeconds());
859 //        assertEquals(8, test.getMillis());
860 //    }
861 //
862 //    public void testSetPeriod_long_NoYears() {
863 //        long ms =
864 //            (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
865 //            5L * DateTimeConstants.MILLIS_PER_HOUR +
866 //            6L * DateTimeConstants.MILLIS_PER_MINUTE +
867 //            7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
868 //        MutablePeriod test = new MutablePeriod(PeriodType.getPreciseYearMonthType().withYearsRemoved());
869 //        test.setPeriod(ms);
870 //        assertEquals(0, test.getYears());
871 //        assertEquals(15, test.getMonths()); // totalDays=365+85=450=15*30
872 //        assertEquals(0, test.getWeeks());
873 //        assertEquals(0, test.getDays());
874 //        assertEquals(5, test.getHours());
875 //        assertEquals(6, test.getMinutes());
876 //        assertEquals(7, test.getSeconds());
877 //        assertEquals(8, test.getMillis());
878 //        assertEquals(ms, test.toDurationMillis());
879 //    }
880 //
881 //    public void testSetPeriod_long_NoMonths() {
882 //        long ms =
883 //            (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
884 //            5L * DateTimeConstants.MILLIS_PER_HOUR +
885 //            6L * DateTimeConstants.MILLIS_PER_MINUTE +
886 //            7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
887 //        MutablePeriod test = new MutablePeriod(PeriodType.getPreciseYearMonthType().withMonthsRemoved());
888 //        test.setPeriod(ms);
889 //        assertEquals(1, test.getYears());
890 //        assertEquals(0, test.getMonths());
891 //        assertEquals(0, test.getWeeks());
892 //        assertEquals(85, test.getDays());
893 //        assertEquals(5, test.getHours());
894 //        assertEquals(6, test.getMinutes());
895 //        assertEquals(7, test.getSeconds());
896 //        assertEquals(8, test.getMillis());
897 //        assertEquals(ms, test.toDurationMillis());
898 //    }
899 //
900 //    public void testSetPeriod_long_NoWeeks() {
901 //        long ms =
902 //            (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
903 //            5L * DateTimeConstants.MILLIS_PER_HOUR +
904 //            6L * DateTimeConstants.MILLIS_PER_MINUTE +
905 //            7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
906 //        MutablePeriod test = new MutablePeriod(PeriodType.getPreciseYearWeekType().withWeeksRemoved());
907 //        test.setPeriod(ms);
908 //        assertEquals(1, test.getYears());
909 //        assertEquals(0, test.getMonths());
910 //        assertEquals(0, test.getWeeks());
911 //        assertEquals(85, test.getDays());
912 //        assertEquals(5, test.getHours());
913 //        assertEquals(6, test.getMinutes());
914 //        assertEquals(7, test.getSeconds());
915 //        assertEquals(8, test.getMillis());
916 //        assertEquals(ms, test.toDurationMillis());
917 //    }
918 //
919 //    public void testSetPeriod_long_NoDays() {
920 //        long ms =
921 //            (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
922 //            5L * DateTimeConstants.MILLIS_PER_HOUR +
923 //            6L * DateTimeConstants.MILLIS_PER_MINUTE +
924 //            7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
925 //        MutablePeriod test = new MutablePeriod(PeriodType.getPreciseYearMonthType().withDaysRemoved());
926 //        test.setPeriod(ms);
927 //        assertEquals(1, test.getYears());
928 //        assertEquals(2, test.getMonths());
929 //        assertEquals(0, test.getWeeks());
930 //        assertEquals(0, test.getDays());
931 //        assertEquals(5 + 25 * 24, test.getHours());
932 //        assertEquals(6, test.getMinutes());
933 //        assertEquals(7, test.getSeconds());
934 //        assertEquals(8, test.getMillis());
935 //        assertEquals(ms, test.toDurationMillis());
936 //    }
937 //
938 //    public void testSetPeriod_long_NoHours() {
939 //        long ms =
940 //            (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
941 //            5L * DateTimeConstants.MILLIS_PER_HOUR +
942 //            6L * DateTimeConstants.MILLIS_PER_MINUTE +
943 //            7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
944 //        MutablePeriod test = new MutablePeriod(PeriodType.getPreciseYearMonthType().withHoursRemoved());
945 //        test.setPeriod(ms);
946 //        assertEquals(1, test.getYears());
947 //        assertEquals(2, test.getMonths());
948 //        assertEquals(0, test.getWeeks());
949 //        assertEquals(25, test.getDays());
950 //        assertEquals(0, test.getHours());
951 //        assertEquals(6 + 5 * 60, test.getMinutes());
952 //        assertEquals(7, test.getSeconds());
953 //        assertEquals(8, test.getMillis());
954 //        assertEquals(ms, test.toDurationMillis());
955 //    }
956 //
957 //    public void testSetPeriod_long_NoMinutes() {
958 //        long ms =
959 //            (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
960 //            5L * DateTimeConstants.MILLIS_PER_HOUR +
961 //            6L * DateTimeConstants.MILLIS_PER_MINUTE +
962 //            7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
963 //        MutablePeriod test = new MutablePeriod(PeriodType.getPreciseYearMonthType().withMinutesRemoved());
964 //        test.setPeriod(ms);
965 //        assertEquals(1, test.getYears());
966 //        assertEquals(2, test.getMonths());
967 //        assertEquals(0, test.getWeeks());
968 //        assertEquals(25, test.getDays());
969 //        assertEquals(5, test.getHours());
970 //        assertEquals(0, test.getMinutes());
971 //        assertEquals(7 + 6 * 60, test.getSeconds());
972 //        assertEquals(8, test.getMillis());
973 //        assertEquals(ms, test.toDurationMillis());
974 //    }
975 //
976 //    public void testSetPeriod_long_NoSeconds() {
977 //        long ms =
978 //            (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
979 //            5L * DateTimeConstants.MILLIS_PER_HOUR +
980 //            6L * DateTimeConstants.MILLIS_PER_MINUTE +
981 //            7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
982 //        MutablePeriod test = new MutablePeriod(PeriodType.getPreciseYearMonthType().withSecondsRemoved());
983 //        test.setPeriod(ms);
984 //        assertEquals(1, test.getYears());
985 //        assertEquals(2, test.getMonths());
986 //        assertEquals(0, test.getWeeks());
987 //        assertEquals(25, test.getDays());
988 //        assertEquals(5, test.getHours());
989 //        assertEquals(6, test.getMinutes());
990 //        assertEquals(0, test.getSeconds());
991 //        assertEquals(8 + 7 * 1000, test.getMillis());
992 //        assertEquals(ms, test.toDurationMillis());
993 //    }
994 //
995 //    public void testSetPeriod_long_NoMillis() {
996 //        long ms =
997 //            (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
998 //            5L * DateTimeConstants.MILLIS_PER_HOUR +
999 //            6L * DateTimeConstants.MILLIS_PER_MINUTE +
1000 //            7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
1001 //        MutablePeriod test = new MutablePeriod(PeriodType.getPreciseYearMonthType().withMillisRemoved());
1002 //        test.setPeriod(ms);
1003 //        assertEquals(1, test.getYears());
1004 //        assertEquals(2, test.getMonths());
1005 //        assertEquals(0, test.getWeeks());
1006 //        assertEquals(25, test.getDays());
1007 //        assertEquals(5, test.getHours());
1008 //        assertEquals(6, test.getMinutes());
1009 //        assertEquals(7, test.getSeconds());
1010 //        assertEquals(0, test.getMillis());
1011 //        assertEquals(ms - 8, test.toDurationMillis());
1012 //    }
1013 
1014     //-----------------------------------------------------------------------
1015     public void testSetPeriod_RD1() {
1016         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
1017         test.setPeriod(new Duration(100L));
1018         assertEquals(0, test.getYears());
1019         assertEquals(0, test.getMonths());
1020         assertEquals(0, test.getWeeks());
1021         assertEquals(0, test.getDays());
1022         assertEquals(0, test.getHours());
1023         assertEquals(0, test.getMinutes());
1024         assertEquals(0, test.getSeconds());
1025         assertEquals(100, test.getMillis());
1026     }
1027 
1028     public void testSetPeriod_RD2() {
1029         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
1030         long length =
1031             (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
1032             5L * DateTimeConstants.MILLIS_PER_HOUR +
1033             6L * DateTimeConstants.MILLIS_PER_MINUTE +
1034             7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
1035         test.setPeriod(new Duration(length));
1036         // only time fields are precise
1037         assertEquals(0, test.getYears());  // (4 + (3 * 7) + (2 * 30) + 365) == 450
1038         assertEquals(0, test.getMonths());
1039         assertEquals(0, test.getWeeks());
1040         assertEquals(0, test.getDays());
1041         assertEquals((450 * 24) + 5, test.getHours());
1042         assertEquals(6, test.getMinutes());
1043         assertEquals(7, test.getSeconds());
1044         assertEquals(8, test.getMillis());
1045     }
1046 
1047     public void testSetPeriod_RD3() {
1048         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
1049         test.setPeriod((ReadableDuration) null);
1050         assertEquals(0, test.getYears());
1051         assertEquals(0, test.getMonths());
1052         assertEquals(0, test.getWeeks());
1053         assertEquals(0, test.getDays());
1054         assertEquals(0, test.getHours());
1055         assertEquals(0, test.getMinutes());
1056         assertEquals(0, test.getSeconds());
1057         assertEquals(0, test.getMillis());
1058     }
1059 
1060     //-----------------------------------------------------------------------
1061     public void testAdd_8ints1() {
1062         MutablePeriod test = new MutablePeriod(100L);
1063         test.add(1, 2, 3, 4, 5, 6, 7, 8);
1064         assertEquals(1, test.getYears());
1065         assertEquals(2, test.getMonths());
1066         assertEquals(3, test.getWeeks());
1067         assertEquals(4, test.getDays());
1068         assertEquals(5, test.getHours());
1069         assertEquals(6, test.getMinutes());
1070         assertEquals(7, test.getSeconds());
1071         assertEquals(108, test.getMillis());
1072     }
1073 
1074     public void testAdd_8ints2() {
1075         MutablePeriod test = new MutablePeriod(100L, PeriodType.yearMonthDayTime());
1076         try {
1077             test.add(1, 2, 3, 4, 5, 6, 7, 8);
1078             fail();
1079         } catch (IllegalArgumentException ex) {}
1080         assertEquals(0, test.getYears());
1081         assertEquals(0, test.getMonths());
1082         assertEquals(0, test.getWeeks());
1083         assertEquals(0, test.getDays());
1084         assertEquals(0, test.getHours());
1085         assertEquals(0, test.getMinutes());
1086         assertEquals(0, test.getSeconds());
1087         assertEquals(100, test.getMillis());
1088     }
1089 
1090     //-----------------------------------------------------------------------
1091     public void testAdd_long1() {
1092         MutablePeriod test = new MutablePeriod(100L);
1093         test.add(100L);
1094         assertEquals(0, test.getYears());
1095         assertEquals(0, test.getMonths());
1096         assertEquals(0, test.getWeeks());
1097         assertEquals(0, test.getDays());
1098         assertEquals(0, test.getHours());
1099         assertEquals(0, test.getMinutes());
1100         assertEquals(0, test.getSeconds());
1101         assertEquals(200, test.getMillis());
1102     }
1103 
1104     public void testAdd_long2() {
1105         MutablePeriod test = new MutablePeriod(100L, PeriodType.standard());
1106         long ms =
1107             (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
1108             5L * DateTimeConstants.MILLIS_PER_HOUR +
1109             6L * DateTimeConstants.MILLIS_PER_MINUTE +
1110             7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
1111         test.add(ms);
1112         // only time fields are precise
1113         assertEquals(0, test.getYears());  // (4 + (3 * 7) + (2 * 30) + 365) == 450
1114         assertEquals(0, test.getMonths());
1115         assertEquals(0, test.getWeeks());
1116         assertEquals(0, test.getDays());
1117         assertEquals((450 * 24) + 5, test.getHours());
1118         assertEquals(6, test.getMinutes());
1119         assertEquals(7, test.getSeconds());
1120         assertEquals(108, test.getMillis());
1121     }
1122 
1123     public void testAdd_long3() {
1124         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
1125         test.add(2100L);
1126         assertEquals(1, test.getYears());
1127         assertEquals(2, test.getMonths());
1128         assertEquals(3, test.getWeeks());
1129         assertEquals(4, test.getDays());
1130         assertEquals(5, test.getHours());
1131         assertEquals(6, test.getMinutes());
1132         assertEquals(9, test.getSeconds());
1133         assertEquals(108, test.getMillis());
1134     }
1135 
1136     //-----------------------------------------------------------------------
1137     public void testAdd_long_Chronology1() {
1138         MutablePeriod test = new MutablePeriod(100L);
1139         test.add(100L, ISOChronology.getInstance());
1140         assertEquals(0, test.getYears());
1141         assertEquals(0, test.getMonths());
1142         assertEquals(0, test.getWeeks());
1143         assertEquals(0, test.getDays());
1144         assertEquals(0, test.getHours());
1145         assertEquals(0, test.getMinutes());
1146         assertEquals(0, test.getSeconds());
1147         assertEquals(200, test.getMillis());
1148     }
1149 
1150     public void testAdd_long_Chronology2() {
1151         MutablePeriod test = new MutablePeriod(100L, PeriodType.standard());
1152         long ms =
1153             (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
1154             5L * DateTimeConstants.MILLIS_PER_HOUR +
1155             6L * DateTimeConstants.MILLIS_PER_MINUTE +
1156             7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
1157         test.add(ms, ISOChronology.getInstance());
1158         // only time fields are precise
1159         assertEquals(0, test.getYears());  // (4 + (3 * 7) + (2 * 30) + 365) == 450 days
1160         assertEquals(0, test.getMonths());
1161         assertEquals(0, test.getWeeks());
1162         assertEquals(0, test.getDays());
1163         assertEquals((450 * 24) + 5, test.getHours());
1164         assertEquals(6, test.getMinutes());
1165         assertEquals(7, test.getSeconds());
1166         assertEquals(108, test.getMillis());
1167     }
1168 
1169     public void testAdd_long_Chronology3() {
1170         MutablePeriod test = new MutablePeriod(100L, PeriodType.standard());
1171         long ms =
1172             (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
1173             5L * DateTimeConstants.MILLIS_PER_HOUR +
1174             6L * DateTimeConstants.MILLIS_PER_MINUTE +
1175             7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
1176         test.add(ms, ISOChronology.getInstanceUTC());
1177         // UTC, so weeks and day also precise
1178         assertEquals(0, test.getYears());  // (4 + (3 * 7) + (2 * 30) + 365) == 450 days
1179         assertEquals(0, test.getMonths());
1180         assertEquals(64, test.getWeeks());
1181         assertEquals(2, test.getDays());
1182         assertEquals(5, test.getHours());
1183         assertEquals(6, test.getMinutes());
1184         assertEquals(7, test.getSeconds());
1185         assertEquals(108, test.getMillis());
1186     }
1187 
1188     //-----------------------------------------------------------------------
1189     public void testAdd_RD1() {
1190         MutablePeriod test = new MutablePeriod(100L);
1191         test.add(new Duration(100L));
1192         assertEquals(0, test.getYears());
1193         assertEquals(0, test.getMonths());
1194         assertEquals(0, test.getWeeks());
1195         assertEquals(0, test.getDays());
1196         assertEquals(0, test.getHours());
1197         assertEquals(0, test.getMinutes());
1198         assertEquals(0, test.getSeconds());
1199         assertEquals(200, test.getMillis());
1200     }
1201 
1202     public void testAdd_RD2() {
1203         MutablePeriod test = new MutablePeriod(100L, PeriodType.yearMonthDayTime());
1204         long ms =
1205             (4L + (3L * 7L)) * DateTimeConstants.MILLIS_PER_DAY +
1206             5L * DateTimeConstants.MILLIS_PER_HOUR +
1207             6L * DateTimeConstants.MILLIS_PER_MINUTE +
1208             7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
1209         test.add(new Duration(ms));
1210         assertEquals(0, test.getYears());
1211         assertEquals(0, test.getMonths());
1212         assertEquals(0, test.getWeeks());
1213         assertEquals(0, test.getDays());
1214         assertEquals((4 + (3 * 7)) * 24 + 5, test.getHours());
1215         assertEquals(6, test.getMinutes());
1216         assertEquals(7, test.getSeconds());
1217         assertEquals(108, test.getMillis());
1218     }
1219 
1220     public void testAdd_RD3() {
1221         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
1222         test.add((ReadableDuration) null);
1223         assertEquals(1, test.getYears());
1224         assertEquals(2, test.getMonths());
1225         assertEquals(3, test.getWeeks());
1226         assertEquals(4, test.getDays());
1227         assertEquals(5, test.getHours());
1228         assertEquals(6, test.getMinutes());
1229         assertEquals(7, test.getSeconds());
1230         assertEquals(8, test.getMillis());
1231     }
1232 
1233     //-----------------------------------------------------------------------
1234     public void testAdd_RP1() {
1235         MutablePeriod test = new MutablePeriod(100L);
1236         test.add(new Period(100L));
1237         assertEquals(0, test.getYears());
1238         assertEquals(0, test.getMonths());
1239         assertEquals(0, test.getWeeks());
1240         assertEquals(0, test.getDays());
1241         assertEquals(0, test.getHours());
1242         assertEquals(0, test.getMinutes());
1243         assertEquals(0, test.getSeconds());
1244         assertEquals(200, test.getMillis());
1245     }
1246 
1247     public void testAdd_RP2() {
1248         MutablePeriod test = new MutablePeriod(100L, PeriodType.standard());  // All type
1249         test.add(new Period(1, 2, 3, 4, 5, 6, 7, 0, PeriodType.standard().withMillisRemoved()));
1250         // add field value, ignore different types
1251         assertEquals(1, test.getYears());
1252         assertEquals(2, test.getMonths());
1253         assertEquals(3, test.getWeeks());
1254         assertEquals(4, test.getDays());
1255         assertEquals(5, test.getHours());
1256         assertEquals(6, test.getMinutes());
1257         assertEquals(7, test.getSeconds());
1258         assertEquals(100, test.getMillis());
1259     }
1260 
1261     public void testAdd_RP3() {
1262         MutablePeriod test = new MutablePeriod(100L, PeriodType.standard());
1263         test.add(new Period(0L));
1264         assertEquals(0, test.getYears());
1265         assertEquals(0, test.getMonths());
1266         assertEquals(0, test.getWeeks());
1267         assertEquals(0, test.getDays());
1268         assertEquals(0, test.getHours());
1269         assertEquals(0, test.getMinutes());
1270         assertEquals(0, test.getSeconds());
1271         assertEquals(100, test.getMillis());
1272     }
1273 
1274     public void testAdd_RP4() {
1275         MutablePeriod test = new MutablePeriod(1, 2, 0, 4, 5, 6, 7, 8, PeriodType.yearMonthDayTime());
1276         try {
1277             test.add(new Period(1, 2, 3, 4, 5, 6, 7, 8));  // cannot set weeks
1278             fail();
1279         } catch (IllegalArgumentException ex) {}
1280         assertEquals(1, test.getYears());
1281         assertEquals(2, test.getMonths());
1282         assertEquals(0, test.getWeeks());
1283         assertEquals(4, test.getDays());
1284         assertEquals(5, test.getHours());
1285         assertEquals(6, test.getMinutes());
1286         assertEquals(7, test.getSeconds());
1287         assertEquals(8, test.getMillis());
1288     }
1289 
1290     public void testAdd_RP5() {
1291         MutablePeriod test = new MutablePeriod(1, 2, 0, 4, 5, 6, 7, 8, PeriodType.yearMonthDayTime());
1292         test.add(new Period(1, 2, 0, 4, 5, 6, 7, 8));  // can set weeks as zero
1293         assertEquals(2, test.getYears());
1294         assertEquals(4, test.getMonths());
1295         assertEquals(0, test.getWeeks());
1296         assertEquals(8, test.getDays());
1297         assertEquals(10, test.getHours());
1298         assertEquals(12, test.getMinutes());
1299         assertEquals(14, test.getSeconds());
1300         assertEquals(16, test.getMillis());
1301     }
1302 
1303     public void testAdd_RP6() {
1304         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
1305         test.add((ReadablePeriod) null);
1306         assertEquals(1, test.getYears());
1307         assertEquals(2, test.getMonths());
1308         assertEquals(3, test.getWeeks());
1309         assertEquals(4, test.getDays());
1310         assertEquals(5, test.getHours());
1311         assertEquals(6, test.getMinutes());
1312         assertEquals(7, test.getSeconds());
1313         assertEquals(8, test.getMillis());
1314     }
1315 
1316     //-----------------------------------------------------------------------
1317     public void testAdd_RInterval1() {
1318         MutablePeriod test = new MutablePeriod(100L);
1319         test.add(new Interval(100L, 200L));
1320         assertEquals(0, test.getYears());
1321         assertEquals(0, test.getMonths());
1322         assertEquals(0, test.getWeeks());
1323         assertEquals(0, test.getDays());
1324         assertEquals(0, test.getHours());
1325         assertEquals(0, test.getMinutes());
1326         assertEquals(0, test.getSeconds());
1327         assertEquals(200, test.getMillis());
1328     }
1329 
1330     public void testAdd_RInterval2() {
1331         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1332         DateTime dt2 = new DateTime(2005, 12, 18, 0, 0, 0, 8);
1333         MutablePeriod test = new MutablePeriod(100L);  // All type
1334         test.add(new Interval(dt1, dt2));
1335         assertEquals(1, test.getYears());  // add field value from interval
1336         assertEquals(6, test.getMonths());  // add field value from interval
1337         assertEquals(1, test.getWeeks());  // add field value from interval
1338         assertEquals(2, test.getDays());  // add field value from interval
1339         assertEquals(0, test.getHours());  // time zone OK
1340         assertEquals(0, test.getMinutes());
1341         assertEquals(0, test.getSeconds());
1342         assertEquals(108, test.getMillis());
1343     }
1344 
1345     public void testAdd_RInterval3() {
1346         MutablePeriod test = new MutablePeriod(100L, PeriodType.yearMonthDayTime());
1347         test.add(new Interval(0L, 0L));
1348         assertEquals(0, test.getYears());
1349         assertEquals(0, test.getMonths());
1350         assertEquals(0, test.getWeeks());
1351         assertEquals(0, test.getDays());
1352         assertEquals(0, test.getHours());
1353         assertEquals(0, test.getMinutes());
1354         assertEquals(0, test.getSeconds());
1355         assertEquals(100, test.getMillis());
1356     }
1357 
1358     public void testAdd_RInterval4() {
1359         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1360         DateTime dt2 = new DateTime(2005, 7, 17, 0, 0, 0, 8);
1361         MutablePeriod test = new MutablePeriod(100L, PeriodType.yearMonthDayTime());
1362         test.add(new Interval(dt1, dt2));
1363         assertEquals(1, test.getYears());
1364         assertEquals(1, test.getMonths());
1365         assertEquals(0, test.getWeeks());  // no weeks
1366         assertEquals(8, test.getDays());  // week added to days
1367         assertEquals(0, test.getHours());
1368         assertEquals(0, test.getMinutes());
1369         assertEquals(0, test.getSeconds());
1370         assertEquals(108, test.getMillis());
1371     }
1372 
1373     public void testAdd_RInterval5() {
1374         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
1375         test.add((ReadableInterval) null);
1376         assertEquals(1, test.getYears());
1377         assertEquals(2, test.getMonths());
1378         assertEquals(3, test.getWeeks());
1379         assertEquals(4, test.getDays());
1380         assertEquals(5, test.getHours());
1381         assertEquals(6, test.getMinutes());
1382         assertEquals(7, test.getSeconds());
1383         assertEquals(8, test.getMillis());
1384     }
1385 
1386     //-----------------------------------------------------------------------
1387     public void testMergePeriod_RP1() {
1388         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
1389         test.mergePeriod(new MutablePeriod(0, 0, 0, 14, 15, 16, 17, 18, PeriodType.dayTime()));
1390         assertEquals(1, test.getYears());
1391         assertEquals(2, test.getMonths());
1392         assertEquals(3, test.getWeeks());
1393         assertEquals(14, test.getDays());
1394         assertEquals(15, test.getHours());
1395         assertEquals(16, test.getMinutes());
1396         assertEquals(17, test.getSeconds());
1397         assertEquals(18, test.getMillis());
1398     }
1399 
1400     public void testMergePeriod_RP2() {
1401         MutablePeriod test = new MutablePeriod(100L, PeriodType.millis());
1402         try {
1403             test.mergePeriod(new MutablePeriod(11, 12, 13, 14, 15, 16, 17, 18));
1404             fail();
1405         } catch (IllegalArgumentException ex) {}
1406         assertEquals(0, test.getYears());
1407         assertEquals(0, test.getMonths());
1408         assertEquals(0, test.getWeeks());
1409         assertEquals(0, test.getDays());
1410         assertEquals(0, test.getHours());
1411         assertEquals(0, test.getMinutes());
1412         assertEquals(0, test.getSeconds());
1413         assertEquals(100, test.getMillis());
1414     }
1415 
1416     public void testMergePeriod_RP3() {
1417         MutablePeriod test = new MutablePeriod(100L, PeriodType.millis());
1418         test.mergePeriod(new MutablePeriod(0, 0, 0, 0, 0, 0, 0, 18));
1419         assertEquals(0, test.getYears());
1420         assertEquals(0, test.getMonths());
1421         assertEquals(0, test.getWeeks());
1422         assertEquals(0, test.getDays());
1423         assertEquals(0, test.getHours());
1424         assertEquals(0, test.getMinutes());
1425         assertEquals(0, test.getSeconds());
1426         assertEquals(18, test.getMillis());
1427     }
1428 
1429     public void testMergePeriod_RP4() {
1430         MutablePeriod test = new MutablePeriod(0, 0, 0, 0, 5, 6, 7, 8);
1431         test.mergePeriod(new MutablePeriod(11, 12, 13, 14, 15, 16, 17, 18));
1432         assertEquals(11, test.getYears());
1433         assertEquals(12, test.getMonths());
1434         assertEquals(13, test.getWeeks());
1435         assertEquals(14, test.getDays());
1436         assertEquals(15, test.getHours());
1437         assertEquals(16, test.getMinutes());
1438         assertEquals(17, test.getSeconds());
1439         assertEquals(18, test.getMillis());
1440     }
1441 
1442     public void testMergePeriod_RP5() {
1443         MutablePeriod test = new MutablePeriod(1, 2, 3, 4, 5, 6, 7, 8);
1444         test.mergePeriod((ReadablePeriod) null);
1445         assertEquals(1, test.getYears());
1446         assertEquals(2, test.getMonths());
1447         assertEquals(3, test.getWeeks());
1448         assertEquals(4, test.getDays());
1449         assertEquals(5, test.getHours());
1450         assertEquals(6, test.getMinutes());
1451         assertEquals(7, test.getSeconds());
1452         assertEquals(8, test.getMillis());
1453     }
1454 
1455 }