001    /*
002     *  Copyright 2001-2006 Stephen Colebourne
003     *
004     *  Licensed under the Apache License, Version 2.0 (the "License");
005     *  you may not use this file except in compliance with the License.
006     *  You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     *  Unless required by applicable law or agreed to in writing, software
011     *  distributed under the License is distributed on an "AS IS" BASIS,
012     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     *  See the License for the specific language governing permissions and
014     *  limitations under the License.
015     */
016    package org.joda.time;
017    
018    import java.util.Locale;
019    import java.util.TimeZone;
020    
021    import junit.framework.TestCase;
022    import junit.framework.TestSuite;
023    
024    import org.joda.time.chrono.BuddhistChronology;
025    import org.joda.time.chrono.CopticChronology;
026    import org.joda.time.chrono.GJChronology;
027    import org.joda.time.chrono.ISOChronology;
028    import org.joda.time.convert.ConverterManager;
029    import org.joda.time.convert.IntervalConverter;
030    
031    /**
032     * This class is a JUnit test for Interval.
033     *
034     * @author Stephen Colebourne
035     */
036    public class TestInterval_Constructors extends TestCase {
037        // Test in 2002/03 as time zones are more well known
038        // (before the late 90's they were all over the place)
039    
040        private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
041        private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
042        
043        long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
044                         366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
045                         365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
046                         366 + 365;
047        long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
048                         366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
049                         365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
050                         366 + 365 + 365;
051        
052        // 2002-06-09
053        private long TEST_TIME_NOW =
054                (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
055                
056    //    // 2002-04-05
057    //    private long TEST_TIME1 =
058    //            (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY
059    //            + 12L * DateTimeConstants.MILLIS_PER_HOUR
060    //            + 24L * DateTimeConstants.MILLIS_PER_MINUTE;
061    //        
062    //    // 2003-05-06
063    //    private long TEST_TIME2 =
064    //            (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
065    //            + 14L * DateTimeConstants.MILLIS_PER_HOUR
066    //            + 28L * DateTimeConstants.MILLIS_PER_MINUTE;
067        
068        private DateTimeZone originalDateTimeZone = null;
069        private TimeZone originalTimeZone = null;
070        private Locale originalLocale = null;
071    
072        public static void main(String[] args) {
073            junit.textui.TestRunner.run(suite());
074        }
075    
076        public static TestSuite suite() {
077            return new TestSuite(TestInterval_Constructors.class);
078        }
079    
080        public TestInterval_Constructors(String name) {
081            super(name);
082        }
083    
084        protected void setUp() throws Exception {
085            DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
086            originalDateTimeZone = DateTimeZone.getDefault();
087            originalTimeZone = TimeZone.getDefault();
088            originalLocale = Locale.getDefault();
089            DateTimeZone.setDefault(PARIS);
090            TimeZone.setDefault(PARIS.toTimeZone());
091            Locale.setDefault(Locale.FRANCE);
092        }
093    
094        protected void tearDown() throws Exception {
095            DateTimeUtils.setCurrentMillisSystem();
096            DateTimeZone.setDefault(originalDateTimeZone);
097            TimeZone.setDefault(originalTimeZone);
098            Locale.setDefault(originalLocale);
099            originalDateTimeZone = null;
100            originalTimeZone = null;
101            originalLocale = null;
102        }
103    
104        //-----------------------------------------------------------------------
105        public void testParse_noFormatter() throws Throwable {
106            DateTime start = new DateTime(2010, 6, 30, 12, 30, ISOChronology.getInstance(PARIS));
107            DateTime end = new DateTime(2010, 7, 1, 14, 30, ISOChronology.getInstance(PARIS));
108            assertEquals(new Interval(start, end), Interval.parse("2010-06-30T12:30/2010-07-01T14:30"));
109            assertEquals(new Interval(start, end), Interval.parse("2010-06-30T12:30/P1DT2H"));
110            assertEquals(new Interval(start, end), Interval.parse("P1DT2H/2010-07-01T14:30"));
111        }
112    
113        //-----------------------------------------------------------------------
114        public void testConstructor_long_long1() throws Throwable {
115            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
116            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
117            Interval test = new Interval(dt1.getMillis(), dt2.getMillis());
118            assertEquals(dt1.getMillis(), test.getStartMillis());
119            assertEquals(dt2.getMillis(), test.getEndMillis());
120            assertEquals(ISOChronology.getInstance(), test.getChronology());
121        }
122    
123        public void testConstructor_long_long2() throws Throwable {
124            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
125            Interval test = new Interval(dt1.getMillis(), dt1.getMillis());
126            assertEquals(dt1.getMillis(), test.getStartMillis());
127            assertEquals(dt1.getMillis(), test.getEndMillis());
128            assertEquals(ISOChronology.getInstance(), test.getChronology());
129        }
130    
131        public void testConstructor_long_long3() throws Throwable {
132            DateTime dt1 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
133            DateTime dt2 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
134            try {
135                new Interval(dt1.getMillis(), dt2.getMillis());
136                fail();
137            } catch (IllegalArgumentException ex) {}
138        }
139    
140        //-----------------------------------------------------------------------
141        public void testConstructor_long_long_Zone() throws Throwable {
142            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
143            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
144            Interval test = new Interval(dt1.getMillis(), dt2.getMillis(), LONDON);
145            assertEquals(dt1.getMillis(), test.getStartMillis());
146            assertEquals(dt2.getMillis(), test.getEndMillis());
147            assertEquals(ISOChronology.getInstance(LONDON), test.getChronology());
148        }
149    
150        public void testConstructor_long_long_nullZone() throws Throwable {
151            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
152            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
153            Interval test = new Interval(dt1.getMillis(), dt2.getMillis(), (DateTimeZone) null);
154            assertEquals(dt1.getMillis(), test.getStartMillis());
155            assertEquals(dt2.getMillis(), test.getEndMillis());
156            assertEquals(ISOChronology.getInstance(), test.getChronology());
157        }
158    
159        //-----------------------------------------------------------------------
160        public void testConstructor_long_long_Chronology() throws Throwable {
161            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
162            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
163            Interval test = new Interval(dt1.getMillis(), dt2.getMillis(), GJChronology.getInstance());
164            assertEquals(dt1.getMillis(), test.getStartMillis());
165            assertEquals(dt2.getMillis(), test.getEndMillis());
166            assertEquals(GJChronology.getInstance(), test.getChronology());
167        }
168    
169        public void testConstructor_long_long_nullChronology() throws Throwable {
170            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
171            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
172            Interval test = new Interval(dt1.getMillis(), dt2.getMillis(), (Chronology) null);
173            assertEquals(dt1.getMillis(), test.getStartMillis());
174            assertEquals(dt2.getMillis(), test.getEndMillis());
175            assertEquals(ISOChronology.getInstance(), test.getChronology());
176        }
177    
178        //-----------------------------------------------------------------------
179        public void testConstructor_RI_RI1() throws Throwable {
180            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
181            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
182            Interval test = new Interval(dt1, dt2);
183            assertEquals(dt1.getMillis(), test.getStartMillis());
184            assertEquals(dt2.getMillis(), test.getEndMillis());
185        }
186    
187        public void testConstructor_RI_RI2() throws Throwable {
188            Instant dt1 = new Instant(new DateTime(2004, 6, 9, 0, 0, 0, 0));
189            Instant dt2 = new Instant(new DateTime(2005, 7, 10, 1, 1, 1, 1));
190            Interval test = new Interval(dt1, dt2);
191            assertEquals(dt1.getMillis(), test.getStartMillis());
192            assertEquals(dt2.getMillis(), test.getEndMillis());
193        }
194    
195        public void testConstructor_RI_RI3() throws Throwable {
196            Interval test = new Interval((ReadableInstant) null, (ReadableInstant) null);
197            assertEquals(TEST_TIME_NOW, test.getStartMillis());
198            assertEquals(TEST_TIME_NOW, test.getEndMillis());
199        }
200    
201        public void testConstructor_RI_RI4() throws Throwable {
202            DateTime dt1 = new DateTime(2000, 6, 9, 0, 0, 0, 0);
203            Interval test = new Interval(dt1, (ReadableInstant) null);
204            assertEquals(dt1.getMillis(), test.getStartMillis());
205            assertEquals(TEST_TIME_NOW, test.getEndMillis());
206        }
207    
208        public void testConstructor_RI_RI5() throws Throwable {
209            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
210            Interval test = new Interval((ReadableInstant) null, dt2);
211            assertEquals(TEST_TIME_NOW, test.getStartMillis());
212            assertEquals(dt2.getMillis(), test.getEndMillis());
213        }
214    
215        public void testConstructor_RI_RI6() throws Throwable {
216            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
217            Interval test = new Interval(dt1, dt1);
218            assertEquals(dt1.getMillis(), test.getStartMillis());
219            assertEquals(dt1.getMillis(), test.getEndMillis());
220        }
221    
222        public void testConstructor_RI_RI7() throws Throwable {
223            DateTime dt1 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
224            DateTime dt2 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
225            try {
226                new Interval(dt1, dt2);
227                fail();
228            } catch (IllegalArgumentException ex) {}
229        }
230    
231        public void testConstructor_RI_RI_chronoStart() throws Throwable {
232            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0, GJChronology.getInstance());
233            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
234            Interval test = new Interval(dt1, dt2);
235            assertEquals(dt1.getMillis(), test.getStartMillis());
236            assertEquals(dt2.getMillis(), test.getEndMillis());
237            assertEquals(GJChronology.getInstance(), test.getChronology());
238        }
239    
240        public void testConstructor_RI_RI_chronoEnd() throws Throwable {
241            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
242            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1, GJChronology.getInstance());
243            Interval test = new Interval(dt1, dt2);
244            assertEquals(dt1.getMillis(), test.getStartMillis());
245            assertEquals(dt2.getMillis(), test.getEndMillis());
246            assertEquals(ISOChronology.getInstance(), test.getChronology());
247        }
248    
249        public void testConstructor_RI_RI_zones() throws Throwable {
250            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0, LONDON);
251            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1, PARIS);
252            Interval test = new Interval(dt1, dt2);
253            assertEquals(dt1.getMillis(), test.getStartMillis());
254            assertEquals(dt2.getMillis(), test.getEndMillis());
255            assertEquals(ISOChronology.getInstance(LONDON), test.getChronology());
256        }
257    
258        public void testConstructor_RI_RI_instant() throws Throwable {
259            Instant dt1 = new Instant(12345678L);
260            Instant dt2 = new Instant(22345678L);
261            Interval test = new Interval(dt1, dt2);
262            assertEquals(12345678L, test.getStartMillis());
263            assertEquals(22345678L, test.getEndMillis());
264            assertEquals(ISOChronology.getInstanceUTC(), test.getChronology());
265        }
266    
267        //-----------------------------------------------------------------------
268        public void testConstructor_RI_RP1() throws Throwable {
269            DateTime dt = new DateTime(TEST_TIME_NOW);
270            Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
271            long result = TEST_TIME_NOW;
272            result = ISOChronology.getInstance().months().add(result, 6);
273            result = ISOChronology.getInstance().hours().add(result, 1);
274            
275            Interval test = new Interval(dt, dur);
276            assertEquals(dt.getMillis(), test.getStartMillis());
277            assertEquals(result, test.getEndMillis());
278        }
279    
280        public void testConstructor_RI_RP2() throws Throwable {
281            Instant dt = new Instant(new DateTime(TEST_TIME_NOW));
282            Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0);
283            long result = TEST_TIME_NOW;
284            result = ISOChronology.getInstanceUTC().months().add(result, 6);
285            result = ISOChronology.getInstanceUTC().days().add(result, 3);
286            result = ISOChronology.getInstanceUTC().hours().add(result, 1);
287            
288            Interval test = new Interval(dt, dur);
289            assertEquals(dt.getMillis(), test.getStartMillis());
290            assertEquals(result, test.getEndMillis());
291        }
292    
293        public void testConstructor_RI_RP3() throws Throwable {
294            DateTime dt = new DateTime(TEST_TIME_NOW, CopticChronology.getInstanceUTC());
295            Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0, PeriodType.standard());
296            long result = TEST_TIME_NOW;
297            result = CopticChronology.getInstanceUTC().months().add(result, 6);
298            result = CopticChronology.getInstanceUTC().days().add(result, 3);
299            result = CopticChronology.getInstanceUTC().hours().add(result, 1);
300            
301            Interval test = new Interval(dt, dur);
302            assertEquals(dt.getMillis(), test.getStartMillis());
303            assertEquals(result, test.getEndMillis());
304        }
305    
306        public void testConstructor_RI_RP4() throws Throwable {
307            DateTime dt = new DateTime(TEST_TIME_NOW);
308            Period dur = new Period(1 * DateTimeConstants.MILLIS_PER_HOUR + 23L);
309            long result = TEST_TIME_NOW;
310            result = ISOChronology.getInstance().hours().add(result, 1);
311            result = ISOChronology.getInstance().millis().add(result, 23);
312            
313            Interval test = new Interval(dt, dur);
314            assertEquals(dt.getMillis(), test.getStartMillis());
315            assertEquals(result, test.getEndMillis());
316        }
317    
318        public void testConstructor_RI_RP5() throws Throwable {
319            Interval test = new Interval((ReadableInstant) null, (ReadablePeriod) null);
320            assertEquals(TEST_TIME_NOW, test.getStartMillis());
321            assertEquals(TEST_TIME_NOW, test.getEndMillis());
322        }
323    
324        public void testConstructor_RI_RP6() throws Throwable {
325            DateTime dt = new DateTime(TEST_TIME_NOW);
326            Interval test = new Interval(dt, (ReadablePeriod) null);
327            assertEquals(dt.getMillis(), test.getStartMillis());
328            assertEquals(dt.getMillis(), test.getEndMillis());
329        }
330    
331        public void testConstructor_RI_RP7() throws Throwable {
332            Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
333            long result = TEST_TIME_NOW;
334            result = ISOChronology.getInstance().monthOfYear().add(result, 6);
335            result = ISOChronology.getInstance().hourOfDay().add(result, 1);
336            
337            Interval test = new Interval((ReadableInstant) null, dur);
338            assertEquals(TEST_TIME_NOW, test.getStartMillis());
339            assertEquals(result, test.getEndMillis());
340        }
341    
342        public void testConstructor_RI_RP8() throws Throwable {
343            DateTime dt = new DateTime(TEST_TIME_NOW);
344            Period dur = new Period(0, 0, 0, 0, 0, 0, 0, -1);
345            try {
346                new Interval(dt, dur);
347                fail();
348            } catch (IllegalArgumentException ex) {}
349        }
350    
351        //-----------------------------------------------------------------------
352        public void testConstructor_RP_RI1() throws Throwable {
353            DateTime dt = new DateTime(TEST_TIME_NOW);
354            Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
355            long result = TEST_TIME_NOW;
356            result = ISOChronology.getInstance().months().add(result, -6);
357            result = ISOChronology.getInstance().hours().add(result, -1);
358            
359            Interval test = new Interval(dur, dt);
360            assertEquals(result, test.getStartMillis());
361            assertEquals(dt.getMillis(), test.getEndMillis());
362        }
363    
364        public void testConstructor_RP_RI2() throws Throwable {
365            Instant dt = new Instant(new DateTime(TEST_TIME_NOW));
366            Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0);
367            long result = TEST_TIME_NOW;
368            result = ISOChronology.getInstanceUTC().months().add(result, -6);
369            result = ISOChronology.getInstanceUTC().days().add(result, -3);
370            result = ISOChronology.getInstanceUTC().hours().add(result, -1);
371            
372            Interval test = new Interval(dur, dt);
373            assertEquals(result, test.getStartMillis());
374            assertEquals(dt.getMillis(), test.getEndMillis());
375        }
376    
377        public void testConstructor_RP_RI3() throws Throwable {
378            DateTime dt = new DateTime(TEST_TIME_NOW, CopticChronology.getInstanceUTC());
379            Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0, PeriodType.standard());
380            long result = TEST_TIME_NOW;
381            result = CopticChronology.getInstanceUTC().months().add(result, -6);
382            result = CopticChronology.getInstanceUTC().days().add(result, -3);
383            result = CopticChronology.getInstanceUTC().hours().add(result, -1);
384            
385            Interval test = new Interval(dur, dt);
386            assertEquals(result, test.getStartMillis());
387            assertEquals(dt.getMillis(), test.getEndMillis());
388        }
389    
390        public void testConstructor_RP_RI4() throws Throwable {
391            DateTime dt = new DateTime(TEST_TIME_NOW);
392            Period dur = new Period(1 * DateTimeConstants.MILLIS_PER_HOUR + 23L);
393            long result = TEST_TIME_NOW;
394            result = ISOChronology.getInstance().hours().add(result, -1);
395            result = ISOChronology.getInstance().millis().add(result, -23);
396            
397            Interval test = new Interval(dur, dt);
398            assertEquals(result, test.getStartMillis());
399            assertEquals(dt.getMillis(), test.getEndMillis());
400        }
401    
402        public void testConstructor_RP_RI5() throws Throwable {
403            Interval test = new Interval((ReadablePeriod) null, (ReadableInstant) null);
404            assertEquals(TEST_TIME_NOW, test.getStartMillis());
405            assertEquals(TEST_TIME_NOW, test.getEndMillis());
406        }
407    
408        public void testConstructor_RP_RI6() throws Throwable {
409            DateTime dt = new DateTime(TEST_TIME_NOW);
410            Interval test = new Interval((ReadablePeriod) null, dt);
411            assertEquals(dt.getMillis(), test.getStartMillis());
412            assertEquals(dt.getMillis(), test.getEndMillis());
413        }
414    
415        public void testConstructor_RP_RI7() throws Throwable {
416            Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
417            long result = TEST_TIME_NOW;
418            result = ISOChronology.getInstance().monthOfYear().add(result, -6);
419            result = ISOChronology.getInstance().hourOfDay().add(result, -1);
420            
421            Interval test = new Interval(dur, (ReadableInstant) null);
422            assertEquals(result, test.getStartMillis());
423            assertEquals(TEST_TIME_NOW, test.getEndMillis());
424        }
425    
426        public void testConstructor_RP_RI8() throws Throwable {
427            DateTime dt = new DateTime(TEST_TIME_NOW);
428            Period dur = new Period(0, 0, 0, 0, 0, 0, 0, -1);
429            try {
430                new Interval(dur, dt);
431                fail();
432            } catch (IllegalArgumentException ex) {}
433        }
434    
435        //-----------------------------------------------------------------------
436        public void testConstructor_RI_RD1() throws Throwable {
437            long result = TEST_TIME_NOW;
438            result = ISOChronology.getInstance().months().add(result, 6);
439            result = ISOChronology.getInstance().hours().add(result, 1);
440            
441            DateTime dt = new DateTime(TEST_TIME_NOW);
442            Duration dur = new Duration(result - TEST_TIME_NOW);
443            
444            Interval test = new Interval(dt, dur);
445            assertEquals(dt.getMillis(), test.getStartMillis());
446            assertEquals(result, test.getEndMillis());
447        }
448    
449        public void testConstructor_RI_RD2() throws Throwable {
450            Interval test = new Interval((ReadableInstant) null, (ReadableDuration) null);
451            assertEquals(TEST_TIME_NOW, test.getStartMillis());
452            assertEquals(TEST_TIME_NOW, test.getEndMillis());
453        }
454    
455        public void testConstructor_RI_RD3() throws Throwable {
456            DateTime dt = new DateTime(TEST_TIME_NOW);
457            Interval test = new Interval(dt, (ReadableDuration) null);
458            assertEquals(dt.getMillis(), test.getStartMillis());
459            assertEquals(dt.getMillis(), test.getEndMillis());
460        }
461    
462        public void testConstructor_RI_RD4() throws Throwable {
463            long result = TEST_TIME_NOW;
464            result = ISOChronology.getInstance().monthOfYear().add(result, 6);
465            result = ISOChronology.getInstance().hourOfDay().add(result, 1);
466            
467            Duration dur = new Duration(result - TEST_TIME_NOW);
468            
469            Interval test = new Interval((ReadableInstant) null, dur);
470            assertEquals(TEST_TIME_NOW, test.getStartMillis());
471            assertEquals(result, test.getEndMillis());
472        }
473    
474        public void testConstructor_RI_RD5() throws Throwable {
475            DateTime dt = new DateTime(TEST_TIME_NOW);
476            Duration dur = new Duration(-1);
477            try {
478                new Interval(dt, dur);
479                fail();
480            } catch (IllegalArgumentException ex) {}
481        }
482    
483        //-----------------------------------------------------------------------
484        public void testConstructor_RD_RI1() throws Throwable {
485            long result = TEST_TIME_NOW;
486            result = ISOChronology.getInstance().months().add(result, -6);
487            result = ISOChronology.getInstance().hours().add(result, -1);
488            
489            DateTime dt = new DateTime(TEST_TIME_NOW);
490            Duration dur = new Duration(TEST_TIME_NOW - result);
491            
492            Interval test = new Interval(dur, dt);
493            assertEquals(result, test.getStartMillis());
494            assertEquals(dt.getMillis(), test.getEndMillis());
495        }
496    
497        public void testConstructor_RD_RI2() throws Throwable {
498            Interval test = new Interval((ReadableDuration) null, (ReadableInstant) null);
499            assertEquals(TEST_TIME_NOW, test.getStartMillis());
500            assertEquals(TEST_TIME_NOW, test.getEndMillis());
501        }
502    
503        public void testConstructor_RD_RI3() throws Throwable {
504            DateTime dt = new DateTime(TEST_TIME_NOW);
505            Interval test = new Interval((ReadableDuration) null, dt);
506            assertEquals(dt.getMillis(), test.getStartMillis());
507            assertEquals(dt.getMillis(), test.getEndMillis());
508        }
509    
510        public void testConstructor_RD_RI4() throws Throwable {
511            long result = TEST_TIME_NOW;
512            result = ISOChronology.getInstance().monthOfYear().add(result, -6);
513            result = ISOChronology.getInstance().hourOfDay().add(result, -1);
514            
515            Duration dur = new Duration(TEST_TIME_NOW - result);
516            
517            Interval test = new Interval(dur, (ReadableInstant) null);
518            assertEquals(result, test.getStartMillis());
519            assertEquals(TEST_TIME_NOW, test.getEndMillis());
520        }
521    
522        public void testConstructor_RD_RI5() throws Throwable {
523            DateTime dt = new DateTime(TEST_TIME_NOW);
524            Duration dur = new Duration(-1);
525            try {
526                new Interval(dur, dt);
527                fail();
528            } catch (IllegalArgumentException ex) {}
529        }
530    
531        //-----------------------------------------------------------------------
532        public void testConstructor_Object1() throws Throwable {
533            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
534            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
535            Interval test = new Interval(dt1.toString() + '/' + dt2.toString());
536            assertEquals(dt1.getMillis(), test.getStartMillis());
537            assertEquals(dt2.getMillis(), test.getEndMillis());
538        }
539    
540        public void testConstructor_Object2() throws Throwable {
541            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
542            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
543            Interval base = new Interval(dt1, dt2);
544            
545            Interval test = new Interval(base);
546            assertEquals(dt1.getMillis(), test.getStartMillis());
547            assertEquals(dt2.getMillis(), test.getEndMillis());
548        }
549    
550        public void testConstructor_Object3() throws Throwable {
551            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
552            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
553            MutableInterval base = new MutableInterval(dt1, dt2);
554            
555            Interval test = new Interval(base);
556            assertEquals(dt1.getMillis(), test.getStartMillis());
557            assertEquals(dt2.getMillis(), test.getEndMillis());
558        }
559    
560        public void testConstructor_Object4() throws Throwable {
561            MockInterval base = new MockInterval();
562            Interval test = new Interval(base);
563            assertEquals(base.getStartMillis(), test.getStartMillis());
564            assertEquals(base.getEndMillis(), test.getEndMillis());
565        }
566    
567        public void testConstructor_Object5() throws Throwable {
568            IntervalConverter oldConv = ConverterManager.getInstance().getIntervalConverter("");
569            IntervalConverter conv = new IntervalConverter() {
570                public boolean isReadableInterval(Object object, Chronology chrono) {
571                    return false;
572                }
573                public void setInto(ReadWritableInterval interval, Object object, Chronology chrono) {
574                    interval.setChronology(chrono);
575                    interval.setInterval(1234L, 5678L);
576                }
577                public Class<?> getSupportedType() {
578                    return String.class;
579                }
580            };
581            try {
582                ConverterManager.getInstance().addIntervalConverter(conv);
583                DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
584                DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
585                Interval test = new Interval(dt1.toString() + '/' + dt2.toString());
586                assertEquals(1234L, test.getStartMillis());
587                assertEquals(5678L, test.getEndMillis());
588            } finally {
589                ConverterManager.getInstance().addIntervalConverter(oldConv);
590            }
591        }
592    
593        public void testConstructor_Object6() throws Throwable {
594            IntervalConverter oldConv = ConverterManager.getInstance().getIntervalConverter(new Interval(0L, 0L));
595            IntervalConverter conv = new IntervalConverter() {
596                public boolean isReadableInterval(Object object, Chronology chrono) {
597                    return false;
598                }
599                public void setInto(ReadWritableInterval interval, Object object, Chronology chrono) {
600                    interval.setChronology(chrono);
601                    interval.setInterval(1234L, 5678L);
602                }
603                public Class<?> getSupportedType() {
604                    return ReadableInterval.class;
605                }
606            };
607            try {
608                ConverterManager.getInstance().addIntervalConverter(conv);
609                Interval base = new Interval(-1000L, 1000L);
610                Interval test = new Interval(base);
611                assertEquals(1234L, test.getStartMillis());
612                assertEquals(5678L, test.getEndMillis());
613            } finally {
614                ConverterManager.getInstance().addIntervalConverter(oldConv);
615            }
616        }
617    
618        class MockInterval implements ReadableInterval {
619            public Chronology getChronology() {
620                return ISOChronology.getInstance();
621            }
622            public long getStartMillis() {
623                return 1234L;
624            }
625            public DateTime getStart() {
626                return new DateTime(1234L);
627            }
628            public long getEndMillis() {
629                return 5678L;
630            }
631            public DateTime getEnd() {
632                return new DateTime(5678L);
633            }
634            public long toDurationMillis() {
635                return (5678L - 1234L);
636            }
637            public Duration toDuration() {
638                return new Duration(5678L - 1234L);
639            }
640            public boolean contains(long millisInstant) {
641                return false;
642            }
643            public boolean containsNow() {
644                return false;
645            }
646            public boolean contains(ReadableInstant instant) {
647                return false;
648            }
649            public boolean contains(ReadableInterval interval) {
650                return false;
651            }
652            public boolean overlaps(ReadableInterval interval) {
653                return false;
654            }
655            public boolean isBefore(ReadableInstant instant) {
656                return false;
657            }
658            public boolean isBefore(ReadableInterval interval) {
659                return false;
660            }
661            public boolean isAfter(ReadableInstant instant) {
662                return false;
663            }
664            public boolean isAfter(ReadableInterval interval) {
665                return false;
666            }
667            public Interval toInterval() {
668                return null;
669            }
670            public MutableInterval toMutableInterval() {
671                return null;
672            }
673            public Period toPeriod() {
674                return null;
675            }
676            public Period toPeriod(PeriodType type) {
677                return null;
678            }
679        }
680    
681        //-----------------------------------------------------------------------
682        public void testConstructor_Object_Chronology1() throws Throwable {
683            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
684            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
685            Interval base = new Interval(dt1, dt2);
686            
687            Interval test = new Interval(base, BuddhistChronology.getInstance());
688            assertEquals(dt1.getMillis(), test.getStartMillis());
689            assertEquals(dt2.getMillis(), test.getEndMillis());
690            assertEquals(BuddhistChronology.getInstance(), test.getChronology());
691        }
692    
693        public void testConstructor_Object_Chronology2() throws Throwable {
694            DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
695            DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
696            Interval base = new Interval(dt1, dt2);
697            
698            Interval test = new Interval(base, null);
699            assertEquals(dt1.getMillis(), test.getStartMillis());
700            assertEquals(dt2.getMillis(), test.getEndMillis());
701            assertEquals(ISOChronology.getInstance(), test.getChronology());
702        }
703    
704    }