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.BuddhistChronology;
25  import org.joda.time.chrono.GJChronology;
26  import org.joda.time.chrono.ISOChronology;
27  import org.joda.time.convert.ConverterManager;
28  import org.joda.time.convert.IntervalConverter;
29  
30  /**
31   * This class is a JUnit test for Interval.
32   *
33   * @author Stephen Colebourne
34   */
35  public class TestMutableInterval_Constructors extends TestCase {
36      // Test in 2002/03 as time zones are more well known
37      // (before the late 90's they were all over the place)
38  
39      private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
40      private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
41      
42      long y2002days = 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;
46      long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
47                       366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
48                       365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
49                       366 + 365 + 365;
50      
51      // 2002-06-09
52      private long TEST_TIME_NOW =
53              (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
54              
55      // 2002-04-05
56      private long TEST_TIME1 =
57              (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY
58              + 12L * DateTimeConstants.MILLIS_PER_HOUR
59              + 24L * DateTimeConstants.MILLIS_PER_MINUTE;
60          
61      // 2003-05-06
62      private long TEST_TIME2 =
63              (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
64              + 14L * DateTimeConstants.MILLIS_PER_HOUR
65              + 28L * DateTimeConstants.MILLIS_PER_MINUTE;
66      
67      private DateTimeZone originalDateTimeZone = null;
68      private TimeZone originalTimeZone = null;
69      private Locale originalLocale = null;
70  
71      public static void main(String[] args) {
72          junit.textui.TestRunner.run(suite());
73      }
74  
75      public static TestSuite suite() {
76          return new TestSuite(TestMutableInterval_Constructors.class);
77      }
78  
79      public TestMutableInterval_Constructors(String name) {
80          super(name);
81      }
82  
83      protected void setUp() throws Exception {
84          DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
85          originalDateTimeZone = DateTimeZone.getDefault();
86          originalTimeZone = TimeZone.getDefault();
87          originalLocale = Locale.getDefault();
88          DateTimeZone.setDefault(PARIS);
89          TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
90          Locale.setDefault(Locale.UK);
91      }
92  
93      protected void tearDown() throws Exception {
94          DateTimeUtils.setCurrentMillisSystem();
95          DateTimeZone.setDefault(originalDateTimeZone);
96          TimeZone.setDefault(originalTimeZone);
97          Locale.setDefault(originalLocale);
98          originalDateTimeZone = null;
99          originalTimeZone = null;
100         originalLocale = null;
101     }
102 
103     //-----------------------------------------------------------------------
104     public void testTest() {
105         assertEquals("2002-06-09T00:00:00.000Z", new Instant(TEST_TIME_NOW).toString());
106         assertEquals("2002-04-05T12:24:00.000Z", new Instant(TEST_TIME1).toString());
107         assertEquals("2003-05-06T14:28:00.000Z", new Instant(TEST_TIME2).toString());
108     }
109 
110     //-----------------------------------------------------------------------
111     public void testParse_noFormatter() throws Throwable {
112         DateTime start = new DateTime(2010, 6, 30, 12, 30, ISOChronology.getInstance(PARIS));
113         DateTime end = new DateTime(2010, 7, 1, 14, 30, ISOChronology.getInstance(PARIS));
114         assertEquals(new MutableInterval(start, end), MutableInterval.parse("2010-06-30T12:30/2010-07-01T14:30"));
115         assertEquals(new MutableInterval(start, end), MutableInterval.parse("2010-06-30T12:30/P1DT2H"));
116         assertEquals(new MutableInterval(start, end), MutableInterval.parse("P1DT2H/2010-07-01T14:30"));
117     }
118 
119     //-----------------------------------------------------------------------
120     public void testConstructor() throws Throwable {
121         MutableInterval test = new MutableInterval();
122         assertEquals(0L, test.getStartMillis());
123         assertEquals(0L, test.getEndMillis());
124     }
125 
126     //-----------------------------------------------------------------------
127     public void testConstructor_long_long1() throws Throwable {
128         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
129         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
130         MutableInterval test = new MutableInterval(dt1.getMillis(), dt2.getMillis());
131         assertEquals(dt1.getMillis(), test.getStartMillis());
132         assertEquals(dt2.getMillis(), test.getEndMillis());
133         assertEquals(ISOChronology.getInstance(), test.getChronology());
134     }
135 
136     public void testConstructor_long_long2() throws Throwable {
137         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
138         MutableInterval test = new MutableInterval(dt1.getMillis(), dt1.getMillis());
139         assertEquals(dt1.getMillis(), test.getStartMillis());
140         assertEquals(dt1.getMillis(), test.getEndMillis());
141         assertEquals(ISOChronology.getInstance(), test.getChronology());
142     }
143 
144     public void testConstructor_long_long3() throws Throwable {
145         DateTime dt1 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
146         DateTime dt2 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
147         try {
148             new MutableInterval(dt1.getMillis(), dt2.getMillis());
149             fail();
150         } catch (IllegalArgumentException ex) {}
151     }
152 
153     //-----------------------------------------------------------------------
154     public void testConstructor_long_long_Chronology1() throws Throwable {
155         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
156         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
157         MutableInterval test = new MutableInterval(dt1.getMillis(), dt2.getMillis(), GJChronology.getInstance());
158         assertEquals(dt1.getMillis(), test.getStartMillis());
159         assertEquals(dt2.getMillis(), test.getEndMillis());
160         assertEquals(GJChronology.getInstance(), test.getChronology());
161     }
162 
163     public void testConstructor_long_long_Chronology2() throws Throwable {
164         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
165         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
166         MutableInterval test = new MutableInterval(dt1.getMillis(), dt2.getMillis(), null);
167         assertEquals(dt1.getMillis(), test.getStartMillis());
168         assertEquals(dt2.getMillis(), test.getEndMillis());
169         assertEquals(ISOChronology.getInstance(), test.getChronology());
170     }
171 
172     //-----------------------------------------------------------------------
173     public void testConstructor_RI_RI1() throws Throwable {
174         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
175         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
176         MutableInterval test = new MutableInterval(dt1, dt2);
177         assertEquals(dt1.getMillis(), test.getStartMillis());
178         assertEquals(dt2.getMillis(), test.getEndMillis());
179     }
180 
181     public void testConstructor_RI_RI2() throws Throwable {
182         Instant dt1 = new Instant(new DateTime(2004, 6, 9, 0, 0, 0, 0));
183         Instant dt2 = new Instant(new DateTime(2005, 7, 10, 1, 1, 1, 1));
184         MutableInterval test = new MutableInterval(dt1, dt2);
185         assertEquals(dt1.getMillis(), test.getStartMillis());
186         assertEquals(dt2.getMillis(), test.getEndMillis());
187     }
188 
189     public void testConstructor_RI_RI3() throws Throwable {
190         MutableInterval test = new MutableInterval((ReadableInstant) null, (ReadableInstant) null);
191         assertEquals(TEST_TIME_NOW, test.getStartMillis());
192         assertEquals(TEST_TIME_NOW, test.getEndMillis());
193     }
194 
195     public void testConstructor_RI_RI4() throws Throwable {
196         DateTime dt1 = new DateTime(2000, 6, 9, 0, 0, 0, 0);
197         MutableInterval test = new MutableInterval(dt1, (ReadableInstant) null);
198         assertEquals(dt1.getMillis(), test.getStartMillis());
199         assertEquals(TEST_TIME_NOW, test.getEndMillis());
200     }
201 
202     public void testConstructor_RI_RI5() throws Throwable {
203         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
204         MutableInterval test = new MutableInterval((ReadableInstant) null, dt2);
205         assertEquals(TEST_TIME_NOW, test.getStartMillis());
206         assertEquals(dt2.getMillis(), test.getEndMillis());
207     }
208 
209     public void testConstructor_RI_RI6() throws Throwable {
210         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
211         MutableInterval test = new MutableInterval(dt1, dt1);
212         assertEquals(dt1.getMillis(), test.getStartMillis());
213         assertEquals(dt1.getMillis(), test.getEndMillis());
214     }
215 
216     public void testConstructor_RI_RI7() throws Throwable {
217         DateTime dt1 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
218         DateTime dt2 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
219         try {
220             new MutableInterval(dt1, dt2);
221             fail();
222         } catch (IllegalArgumentException ex) {}
223     }
224 
225     public void testConstructor_RI_RI8() throws Throwable {
226         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0, GJChronology.getInstance());
227         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
228         MutableInterval test = new MutableInterval(dt1, dt2);
229         assertEquals(dt1.getMillis(), test.getStartMillis());
230         assertEquals(dt2.getMillis(), test.getEndMillis());
231         assertEquals(GJChronology.getInstance(), test.getChronology());
232     }
233 
234     public void testConstructor_RI_RI9() throws Throwable {
235         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
236         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1, GJChronology.getInstance());
237         MutableInterval test = new MutableInterval(dt1, dt2);
238         assertEquals(dt1.getMillis(), test.getStartMillis());
239         assertEquals(dt2.getMillis(), test.getEndMillis());
240         assertEquals(ISOChronology.getInstance(), test.getChronology());
241     }
242 
243     //-----------------------------------------------------------------------
244     public void testConstructor_RI_RP1() throws Throwable {
245         DateTime dt = new DateTime(TEST_TIME_NOW);
246         Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
247         long result = TEST_TIME_NOW;
248         result = ISOChronology.getInstance().months().add(result, 6);
249         result = ISOChronology.getInstance().hours().add(result, 1);
250         
251         MutableInterval test = new MutableInterval(dt, dur);
252         assertEquals(dt.getMillis(), test.getStartMillis());
253         assertEquals(result, test.getEndMillis());
254     }
255 
256     public void testConstructor_RI_RP2() throws Throwable {
257         Instant dt = new Instant(new DateTime(TEST_TIME_NOW));
258         Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0);
259         long result = TEST_TIME_NOW;
260         result = ISOChronology.getInstanceUTC().months().add(result, 6);
261         result = ISOChronology.getInstanceUTC().days().add(result, 3);
262         result = ISOChronology.getInstanceUTC().hours().add(result, 1);
263         
264         MutableInterval test = new MutableInterval(dt, dur);
265         assertEquals(dt.getMillis(), test.getStartMillis());
266         assertEquals(result, test.getEndMillis());
267     }
268 
269     public void testConstructor_RI_RP3() throws Throwable {
270         DateTime dt = new DateTime(TEST_TIME_NOW, ISOChronology.getInstanceUTC());
271         Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0, PeriodType.standard());
272         long result = TEST_TIME_NOW;
273         result = ISOChronology.getInstanceUTC().months().add(result, 6);
274         result = ISOChronology.getInstanceUTC().days().add(result, 3);
275         result = ISOChronology.getInstanceUTC().hours().add(result, 1);
276         
277         MutableInterval test = new MutableInterval(dt, dur);
278         assertEquals(dt.getMillis(), test.getStartMillis());
279         assertEquals(result, test.getEndMillis());
280     }
281 
282     public void testConstructor_RI_RP4() throws Throwable {
283         DateTime dt = new DateTime(TEST_TIME_NOW);
284         Period dur = new Period(1 * DateTimeConstants.MILLIS_PER_HOUR + 23L);
285         long result = TEST_TIME_NOW;
286         result = ISOChronology.getInstance().hours().add(result, 1);
287         result = ISOChronology.getInstance().millis().add(result, 23);
288         
289         MutableInterval test = new MutableInterval(dt, dur);
290         assertEquals(dt.getMillis(), test.getStartMillis());
291         assertEquals(result, test.getEndMillis());
292     }
293 
294     public void testConstructor_RI_RP5() throws Throwable {
295         MutableInterval test = new MutableInterval((ReadableInstant) null, (ReadablePeriod) null);
296         assertEquals(TEST_TIME_NOW, test.getStartMillis());
297         assertEquals(TEST_TIME_NOW, test.getEndMillis());
298     }
299 
300     public void testConstructor_RI_RP6() throws Throwable {
301         DateTime dt = new DateTime(TEST_TIME_NOW);
302         MutableInterval test = new MutableInterval(dt, (ReadablePeriod) null);
303         assertEquals(dt.getMillis(), test.getStartMillis());
304         assertEquals(dt.getMillis(), test.getEndMillis());
305     }
306 
307     public void testConstructor_RI_RP7() throws Throwable {
308         Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
309         long result = TEST_TIME_NOW;
310         result = ISOChronology.getInstance().monthOfYear().add(result, 6);
311         result = ISOChronology.getInstance().hourOfDay().add(result, 1);
312         
313         MutableInterval test = new MutableInterval((ReadableInstant) null, dur);
314         assertEquals(TEST_TIME_NOW, test.getStartMillis());
315         assertEquals(result, test.getEndMillis());
316     }
317 
318     public void testConstructor_RI_RP8() throws Throwable {
319         DateTime dt = new DateTime(TEST_TIME_NOW);
320         Period dur = new Period(0, 0, 0, 0, 0, 0, 0, -1);
321         try {
322             new MutableInterval(dt, dur);
323             fail();
324         } catch (IllegalArgumentException ex) {}
325     }
326 
327     //-----------------------------------------------------------------------
328     public void testConstructor_RP_RI1() throws Throwable {
329         DateTime dt = new DateTime(TEST_TIME_NOW);
330         Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
331         long result = TEST_TIME_NOW;
332         result = ISOChronology.getInstance().months().add(result, -6);
333         result = ISOChronology.getInstance().hours().add(result, -1);
334         
335         MutableInterval test = new MutableInterval(dur, dt);
336         assertEquals(result, test.getStartMillis());
337         assertEquals(dt.getMillis(), test.getEndMillis());
338     }
339 
340     public void testConstructor_RP_RI2() throws Throwable {
341         Instant dt = new Instant(new DateTime(TEST_TIME_NOW));
342         Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0);
343         long result = TEST_TIME_NOW;
344         result = ISOChronology.getInstanceUTC().months().add(result, -6);
345         result = ISOChronology.getInstanceUTC().days().add(result, -3);
346         result = ISOChronology.getInstanceUTC().hours().add(result, -1);
347         
348         MutableInterval test = new MutableInterval(dur, dt);
349         assertEquals(result, test.getStartMillis());
350         assertEquals(dt.getMillis(), test.getEndMillis());
351     }
352 
353     public void testConstructor_RP_RI3() throws Throwable {
354         DateTime dt = new DateTime(TEST_TIME_NOW, ISOChronology.getInstanceUTC());
355         Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0, PeriodType.standard());
356         long result = TEST_TIME_NOW;
357         result = ISOChronology.getInstanceUTC().months().add(result, -6);
358         result = ISOChronology.getInstanceUTC().days().add(result, -3);
359         result = ISOChronology.getInstanceUTC().hours().add(result, -1);
360         
361         MutableInterval test = new MutableInterval(dur, dt);
362         assertEquals(result, test.getStartMillis());
363         assertEquals(dt.getMillis(), test.getEndMillis());
364     }
365 
366     public void testConstructor_RP_RI4() throws Throwable {
367         DateTime dt = new DateTime(TEST_TIME_NOW);
368         Period dur = new Period(1 * DateTimeConstants.MILLIS_PER_HOUR + 23L);
369         long result = TEST_TIME_NOW;
370         result = ISOChronology.getInstance().hours().add(result, -1);
371         result = ISOChronology.getInstance().millis().add(result, -23);
372         
373         MutableInterval test = new MutableInterval(dur, dt);
374         assertEquals(result, test.getStartMillis());
375         assertEquals(dt.getMillis(), test.getEndMillis());
376     }
377 
378     public void testConstructor_RP_RI5() throws Throwable {
379         MutableInterval test = new MutableInterval((ReadablePeriod) null, (ReadableInstant) null);
380         assertEquals(TEST_TIME_NOW, test.getStartMillis());
381         assertEquals(TEST_TIME_NOW, test.getEndMillis());
382     }
383 
384     public void testConstructor_RP_RI6() throws Throwable {
385         DateTime dt = new DateTime(TEST_TIME_NOW);
386         MutableInterval test = new MutableInterval((ReadablePeriod) null, dt);
387         assertEquals(dt.getMillis(), test.getStartMillis());
388         assertEquals(dt.getMillis(), test.getEndMillis());
389     }
390 
391     public void testConstructor_RP_RI7() throws Throwable {
392         Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
393         long result = TEST_TIME_NOW;
394         result = ISOChronology.getInstance().monthOfYear().add(result, -6);
395         result = ISOChronology.getInstance().hourOfDay().add(result, -1);
396         
397         MutableInterval test = new MutableInterval(dur, (ReadableInstant) null);
398         assertEquals(result, test.getStartMillis());
399         assertEquals(TEST_TIME_NOW, test.getEndMillis());
400     }
401 
402     public void testConstructor_RP_RI8() throws Throwable {
403         DateTime dt = new DateTime(TEST_TIME_NOW);
404         Period dur = new Period(0, 0, 0, 0, 0, 0, 0, -1);
405         try {
406             new MutableInterval(dur, dt);
407             fail();
408         } catch (IllegalArgumentException ex) {}
409     }
410 
411     //-----------------------------------------------------------------------
412     public void testConstructor_RI_RD1() throws Throwable {
413         long result = TEST_TIME_NOW;
414         result = ISOChronology.getInstance().months().add(result, 6);
415         result = ISOChronology.getInstance().hours().add(result, 1);
416         
417         DateTime dt = new DateTime(TEST_TIME_NOW);
418         Duration dur = new Duration(result - TEST_TIME_NOW);
419         
420         MutableInterval test = new MutableInterval(dt, dur);
421         assertEquals(dt.getMillis(), test.getStartMillis());
422         assertEquals(result, test.getEndMillis());
423     }
424 
425     public void testConstructor_RI_RD2() throws Throwable {
426         MutableInterval test = new MutableInterval((ReadableInstant) null, (ReadableDuration) null);
427         assertEquals(TEST_TIME_NOW, test.getStartMillis());
428         assertEquals(TEST_TIME_NOW, test.getEndMillis());
429     }
430 
431     public void testConstructor_RI_RD3() throws Throwable {
432         DateTime dt = new DateTime(TEST_TIME_NOW);
433         MutableInterval test = new MutableInterval(dt, (ReadableDuration) null);
434         assertEquals(dt.getMillis(), test.getStartMillis());
435         assertEquals(dt.getMillis(), test.getEndMillis());
436     }
437 
438     public void testConstructor_RI_RD4() throws Throwable {
439         long result = TEST_TIME_NOW;
440         result = ISOChronology.getInstance().monthOfYear().add(result, 6);
441         result = ISOChronology.getInstance().hourOfDay().add(result, 1);
442         
443         Duration dur = new Duration(result - TEST_TIME_NOW);
444         
445         MutableInterval test = new MutableInterval((ReadableInstant) null, dur);
446         assertEquals(TEST_TIME_NOW, test.getStartMillis());
447         assertEquals(result, test.getEndMillis());
448     }
449 
450     public void testConstructor_RI_RD5() throws Throwable {
451         DateTime dt = new DateTime(TEST_TIME_NOW);
452         Duration dur = new Duration(-1);
453         try {
454             new MutableInterval(dt, dur);
455             fail();
456         } catch (IllegalArgumentException ex) {}
457     }
458 
459     //-----------------------------------------------------------------------
460     public void testConstructor_RD_RI1() throws Throwable {
461         long result = TEST_TIME_NOW;
462         result = ISOChronology.getInstance().months().add(result, -6);
463         result = ISOChronology.getInstance().hours().add(result, -1);
464         
465         DateTime dt = new DateTime(TEST_TIME_NOW);
466         Duration dur = new Duration(TEST_TIME_NOW - result);
467         
468         MutableInterval test = new MutableInterval(dur, dt);
469         assertEquals(result, test.getStartMillis());
470         assertEquals(dt.getMillis(), test.getEndMillis());
471     }
472 
473     public void testConstructor_RD_RI2() throws Throwable {
474         MutableInterval test = new MutableInterval((ReadableDuration) null, (ReadableInstant) null);
475         assertEquals(TEST_TIME_NOW, test.getStartMillis());
476         assertEquals(TEST_TIME_NOW, test.getEndMillis());
477     }
478 
479     public void testConstructor_RD_RI3() throws Throwable {
480         DateTime dt = new DateTime(TEST_TIME_NOW);
481         MutableInterval test = new MutableInterval((ReadableDuration) null, dt);
482         assertEquals(dt.getMillis(), test.getStartMillis());
483         assertEquals(dt.getMillis(), test.getEndMillis());
484     }
485 
486     public void testConstructor_RD_RI4() throws Throwable {
487         long result = TEST_TIME_NOW;
488         result = ISOChronology.getInstance().monthOfYear().add(result, -6);
489         result = ISOChronology.getInstance().hourOfDay().add(result, -1);
490         
491         Duration dur = new Duration(TEST_TIME_NOW - result);
492         
493         MutableInterval test = new MutableInterval(dur, (ReadableInstant) null);
494         assertEquals(result, test.getStartMillis());
495         assertEquals(TEST_TIME_NOW, test.getEndMillis());
496     }
497 
498     public void testConstructor_RD_RI5() throws Throwable {
499         DateTime dt = new DateTime(TEST_TIME_NOW);
500         Duration dur = new Duration(-1);
501         try {
502             new MutableInterval(dur, dt);
503             fail();
504         } catch (IllegalArgumentException ex) {}
505     }
506 
507     //-----------------------------------------------------------------------
508     public void testConstructor_Object1() throws Throwable {
509         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
510         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
511         MutableInterval test = new MutableInterval(dt1.toString() + '/' + dt2.toString());
512         assertEquals(dt1.getMillis(), test.getStartMillis());
513         assertEquals(dt2.getMillis(), test.getEndMillis());
514     }
515 
516     public void testConstructor_Object2() throws Throwable {
517         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
518         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
519         MutableInterval base = new MutableInterval(dt1, dt2);
520         
521         MutableInterval test = new MutableInterval(base);
522         assertEquals(dt1.getMillis(), test.getStartMillis());
523         assertEquals(dt2.getMillis(), test.getEndMillis());
524     }
525 
526     public void testConstructor_Object3() throws Throwable {
527         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
528         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
529         Interval base = new Interval(dt1, dt2);
530         
531         MutableInterval test = new MutableInterval(base);
532         assertEquals(dt1.getMillis(), test.getStartMillis());
533         assertEquals(dt2.getMillis(), test.getEndMillis());
534     }
535 
536     public void testConstructor_Object4() throws Throwable {
537         MockInterval base = new MockInterval();
538         MutableInterval test = new MutableInterval(base);
539         assertEquals(base.getStartMillis(), test.getStartMillis());
540         assertEquals(base.getEndMillis(), test.getEndMillis());
541     }
542 
543     public void testConstructor_Object5() throws Throwable {
544         IntervalConverter oldConv = ConverterManager.getInstance().getIntervalConverter("");
545         IntervalConverter conv = new IntervalConverter() {
546             public boolean isReadableInterval(Object object, Chronology chrono) {
547                 return false;
548             }
549             public void setInto(ReadWritableInterval interval, Object object, Chronology chrono) {
550                 interval.setChronology(chrono);
551                 interval.setInterval(1234L, 5678L);
552             }
553             public Class<?> getSupportedType() {
554                 return String.class;
555             }
556         };
557         try {
558             ConverterManager.getInstance().addIntervalConverter(conv);
559             DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
560             DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
561             MutableInterval test = new MutableInterval(dt1.toString() + '/' + dt2.toString());
562             assertEquals(1234L, test.getStartMillis());
563             assertEquals(5678L, test.getEndMillis());
564         } finally {
565             ConverterManager.getInstance().addIntervalConverter(oldConv);
566         }
567     }
568 
569     public void testConstructor_Object6() throws Throwable {
570         IntervalConverter oldConv = ConverterManager.getInstance().getIntervalConverter(new MutableInterval(0L, 0L));
571         IntervalConverter conv = new IntervalConverter() {
572             public boolean isReadableInterval(Object object, Chronology chrono) {
573                 return false;
574             }
575             public void setInto(ReadWritableInterval interval, Object object, Chronology chrono) {
576                 interval.setChronology(chrono);
577                 interval.setInterval(1234L, 5678L);
578             }
579             public Class<?> getSupportedType() {
580                 return ReadableInterval.class;
581             }
582         };
583         try {
584             ConverterManager.getInstance().addIntervalConverter(conv);
585             Interval base = new Interval(-1000L, 1000L);
586             MutableInterval test = new MutableInterval(base);
587             assertEquals(1234L, test.getStartMillis());
588             assertEquals(5678L, test.getEndMillis());
589         } finally {
590             ConverterManager.getInstance().addIntervalConverter(oldConv);
591         }
592     }
593 
594     class MockInterval implements ReadableInterval {
595         public Chronology getChronology() {
596             return ISOChronology.getInstance();
597         }
598         public long getStartMillis() {
599             return 1234L;
600         }
601         public DateTime getStart() {
602             return new DateTime(1234L);
603         }
604         public long getEndMillis() {
605             return 5678L;
606         }
607         public DateTime getEnd() {
608             return new DateTime(5678L);
609         }
610         public long toDurationMillis() {
611             return (5678L - 1234L);
612         }
613         public Duration toDuration() {
614             return new Duration(5678L - 1234L);
615         }
616         public boolean contains(long millisInstant) {
617             return false;
618         }
619         public boolean containsNow() {
620             return false;
621         }
622         public boolean contains(ReadableInstant instant) {
623             return false;
624         }
625         public boolean contains(ReadableInterval interval) {
626             return false;
627         }
628         public boolean overlaps(ReadableInterval interval) {
629             return false;
630         }
631         public boolean isBefore(ReadableInstant instant) {
632             return false;
633         }
634         public boolean isBefore(ReadableInterval interval) {
635             return false;
636         }
637         public boolean isAfter(ReadableInstant instant) {
638             return false;
639         }
640         public boolean isAfter(ReadableInterval interval) {
641             return false;
642         }
643         public Interval toInterval() {
644             return null;
645         }
646         public MutableInterval toMutableInterval() {
647             return null;
648         }
649         public Period toPeriod() {
650             return null;
651         }
652         public Period toPeriod(PeriodType type) {
653             return null;
654         }
655     }
656 
657     //-----------------------------------------------------------------------
658     public void testConstructor_Object_Chronology1() throws Throwable {
659         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
660         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
661         Interval base = new Interval(dt1, dt2);
662         
663         MutableInterval test = new MutableInterval(base, BuddhistChronology.getInstance());
664         assertEquals(dt1.getMillis(), test.getStartMillis());
665         assertEquals(dt2.getMillis(), test.getEndMillis());
666         assertEquals(BuddhistChronology.getInstance(), test.getChronology());
667     }
668 
669     public void testConstructor_Object_Chronology2() throws Throwable {
670         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
671         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
672         Interval base = new Interval(dt1, dt2);
673         
674         MutableInterval test = new MutableInterval(base, null);
675         assertEquals(dt1.getMillis(), test.getStartMillis());
676         assertEquals(dt2.getMillis(), test.getEndMillis());
677         assertEquals(ISOChronology.getInstance(), test.getChronology());
678     }
679 
680 }