KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joda > time > TestMutableInterval_Constructors


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