View Javadoc

1   /*
2    *  Copyright 2001-2011 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.io.ByteArrayInputStream;
19  import java.io.ByteArrayOutputStream;
20  import java.io.ObjectInputStream;
21  import java.io.ObjectOutputStream;
22  import java.util.Locale;
23  import java.util.TimeZone;
24  
25  import junit.framework.TestCase;
26  import junit.framework.TestSuite;
27  
28  import org.joda.time.base.AbstractInterval;
29  import org.joda.time.chrono.BuddhistChronology;
30  import org.joda.time.chrono.CopticChronology;
31  import org.joda.time.chrono.GJChronology;
32  import org.joda.time.chrono.ISOChronology;
33  import org.joda.time.chrono.LenientChronology;
34  
35  /**
36   * This class is a Junit unit test for Instant.
37   *
38   * @author Stephen Colebourne
39   */
40  public class TestInterval_Basics extends TestCase {
41      // Test in 2002/03 as time zones are more well known
42      // (before the late 90's they were all over the place)
43  
44      private static final DateTimeZone MOSCOW = DateTimeZone.forID("Europe/Moscow");
45      private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
46      private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
47      private static final Chronology COPTIC_PARIS = CopticChronology.getInstance(PARIS);
48      private Interval interval37;
49      private Interval interval33;
50  
51      long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
52                       366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
53                       365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
54                       366 + 365;
55      long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
56                       366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
57                       365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
58                       366 + 365 + 365;
59      
60      // 2002-06-09
61      private long TEST_TIME_NOW =
62              (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
63              
64      // 2002-04-05
65      private long TEST_TIME1 =
66              (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY
67              + 12L * DateTimeConstants.MILLIS_PER_HOUR
68              + 24L * DateTimeConstants.MILLIS_PER_MINUTE;
69          
70      // 2003-05-06
71      private long TEST_TIME2 =
72              (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
73              + 14L * DateTimeConstants.MILLIS_PER_HOUR
74              + 28L * DateTimeConstants.MILLIS_PER_MINUTE;
75          
76      private DateTimeZone originalDateTimeZone = null;
77      private TimeZone originalTimeZone = null;
78      private Locale originalLocale = null;
79  
80      public static void main(String[] args) {
81          junit.textui.TestRunner.run(suite());
82      }
83  
84      public static TestSuite suite() {
85          return new TestSuite(TestInterval_Basics.class);
86      }
87  
88      public TestInterval_Basics(String name) {
89          super(name);
90      }
91  
92      protected void setUp() throws Exception {
93          DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
94          originalDateTimeZone = DateTimeZone.getDefault();
95          originalTimeZone = TimeZone.getDefault();
96          originalLocale = Locale.getDefault();
97          DateTimeZone.setDefault(PARIS);
98          TimeZone.setDefault(PARIS.toTimeZone());
99          Locale.setDefault(Locale.FRANCE);
100         interval37 = new Interval(3, 7);
101         interval33 = new Interval(3, 3);
102     }
103 
104     protected void tearDown() throws Exception {
105         DateTimeUtils.setCurrentMillisSystem();
106         DateTimeZone.setDefault(originalDateTimeZone);
107         TimeZone.setDefault(originalTimeZone);
108         Locale.setDefault(originalLocale);
109         originalDateTimeZone = null;
110         originalTimeZone = null;
111         originalLocale = null;
112     }
113 
114     //-----------------------------------------------------------------------
115     public void testTest() {
116         assertEquals("2002-06-09T00:00:00.000Z", new Instant(TEST_TIME_NOW).toString());
117         assertEquals("2002-04-05T12:24:00.000Z", new Instant(TEST_TIME1).toString());
118         assertEquals("2003-05-06T14:28:00.000Z", new Instant(TEST_TIME2).toString());
119     }
120 
121     //-----------------------------------------------------------------------
122     public void testGetMillis() {
123         Interval test = new Interval(TEST_TIME1, TEST_TIME2);
124         assertEquals(TEST_TIME1, test.getStartMillis());
125         assertEquals(TEST_TIME1, test.getStart().getMillis());
126         assertEquals(TEST_TIME2, test.getEndMillis());
127         assertEquals(TEST_TIME2, test.getEnd().getMillis());
128         assertEquals(TEST_TIME2 - TEST_TIME1, test.toDurationMillis());
129         assertEquals(TEST_TIME2 - TEST_TIME1, test.toDuration().getMillis());
130     }
131 
132     public void testGetDuration1() {
133         Interval test = new Interval(TEST_TIME1, TEST_TIME2);
134         assertEquals(TEST_TIME2 - TEST_TIME1, test.toDurationMillis());
135         assertEquals(TEST_TIME2 - TEST_TIME1, test.toDuration().getMillis());
136     }
137 
138     public void testGetDuration2() {
139         Interval test = new Interval(TEST_TIME1, TEST_TIME1);
140         assertSame(Duration.ZERO, test.toDuration());
141     }
142 
143     public void testEqualsHashCode() {
144         Interval test1 = new Interval(TEST_TIME1, TEST_TIME2);
145         Interval test2 = new Interval(TEST_TIME1, TEST_TIME2);
146         assertEquals(true, test1.equals(test2));
147         assertEquals(true, test2.equals(test1));
148         assertEquals(true, test1.equals(test1));
149         assertEquals(true, test2.equals(test2));
150         assertEquals(true, test1.hashCode() == test2.hashCode());
151         assertEquals(true, test1.hashCode() == test1.hashCode());
152         assertEquals(true, test2.hashCode() == test2.hashCode());
153         
154         Interval test3 = new Interval(TEST_TIME_NOW, TEST_TIME2);
155         assertEquals(false, test1.equals(test3));
156         assertEquals(false, test2.equals(test3));
157         assertEquals(false, test3.equals(test1));
158         assertEquals(false, test3.equals(test2));
159         assertEquals(false, test1.hashCode() == test3.hashCode());
160         assertEquals(false, test2.hashCode() == test3.hashCode());
161         
162         Interval test4 = new Interval(TEST_TIME1, TEST_TIME2, GJChronology.getInstance());
163         assertEquals(true, test4.equals(test4));
164         assertEquals(false, test1.equals(test4));
165         assertEquals(false, test2.equals(test4));
166         assertEquals(false, test4.equals(test1));
167         assertEquals(false, test4.equals(test2));
168         assertEquals(false, test1.hashCode() == test4.hashCode());
169         assertEquals(false, test2.hashCode() == test4.hashCode());
170         
171         MutableInterval test5 = new MutableInterval(TEST_TIME1, TEST_TIME2);
172         assertEquals(true, test1.equals(test5));
173         assertEquals(true, test2.equals(test5));
174         assertEquals(false, test3.equals(test5));
175         assertEquals(true, test5.equals(test1));
176         assertEquals(true, test5.equals(test2));
177         assertEquals(false, test5.equals(test3));
178         assertEquals(true, test1.hashCode() == test5.hashCode());
179         assertEquals(true, test2.hashCode() == test5.hashCode());
180         assertEquals(false, test3.hashCode() == test5.hashCode());
181         
182         assertEquals(false, test1.equals("Hello"));
183         assertEquals(true, test1.equals(new MockInterval()));
184         assertEquals(false, test1.equals(new DateTime(TEST_TIME1)));
185     }
186 
187     class MockInterval extends AbstractInterval {
188         public MockInterval() {
189             super();
190         }
191         public Chronology getChronology() {
192             return ISOChronology.getInstance();
193         }
194         public long getStartMillis() {
195             return TEST_TIME1;
196         }
197         public long getEndMillis() {
198             return TEST_TIME2;
199         }
200     }
201 
202     public void testEqualsHashCodeLenient() {
203         Interval test1 = new Interval(
204                 new DateTime(TEST_TIME1, LenientChronology.getInstance(COPTIC_PARIS)),
205                 new DateTime(TEST_TIME2, LenientChronology.getInstance(COPTIC_PARIS)));
206         Interval test2 = new Interval(
207                 new DateTime(TEST_TIME1, LenientChronology.getInstance(COPTIC_PARIS)),
208                 new DateTime(TEST_TIME2, LenientChronology.getInstance(COPTIC_PARIS)));
209         assertEquals(true, test1.equals(test2));
210         assertEquals(true, test2.equals(test1));
211         assertEquals(true, test1.equals(test1));
212         assertEquals(true, test2.equals(test2));
213         assertEquals(true, test1.hashCode() == test2.hashCode());
214         assertEquals(true, test1.hashCode() == test1.hashCode());
215         assertEquals(true, test2.hashCode() == test2.hashCode());
216     }
217 
218     public void testEqualsHashCodeStrict() {
219         Interval test1 = new Interval(
220                 new DateTime(TEST_TIME1, LenientChronology.getInstance(COPTIC_PARIS)),
221                 new DateTime(TEST_TIME2, LenientChronology.getInstance(COPTIC_PARIS)));
222         Interval test2 = new Interval(
223                 new DateTime(TEST_TIME1, LenientChronology.getInstance(COPTIC_PARIS)),
224                 new DateTime(TEST_TIME2, LenientChronology.getInstance(COPTIC_PARIS)));
225         assertEquals(true, test1.equals(test2));
226         assertEquals(true, test2.equals(test1));
227         assertEquals(true, test1.equals(test1));
228         assertEquals(true, test2.equals(test2));
229         assertEquals(true, test1.hashCode() == test2.hashCode());
230         assertEquals(true, test1.hashCode() == test1.hashCode());
231         assertEquals(true, test2.hashCode() == test2.hashCode());
232     }
233 
234     //-----------------------------------------------------------------------
235     public void test_useCase_ContainsOverlapAbutGap() {
236         // this is a simple test to ensure that the use case of these methods is OK
237         // when comparing any two intervals they can be in one and only one of these states
238         // (a) have a gap between them, (b) abut or (c) overlap
239         // contains is a subset of overlap
240         Interval test1020 = new Interval(10, 20);
241         
242         // [4,8) [10,20) - gap
243         Interval interval = new Interval(4, 8);
244         assertNotNull(test1020.gap(interval));
245         assertEquals(false, test1020.abuts(interval));
246         assertEquals(false, test1020.overlaps(interval));
247         assertEquals(false, test1020.contains(interval));
248         assertNotNull(interval.gap(test1020));
249         assertEquals(false, interval.abuts(test1020));
250         assertEquals(false, interval.overlaps(test1020));
251         assertEquals(false, interval.contains(test1020));
252         
253         // [6,10) [10,20) - abuts
254         interval = new Interval(6, 10);
255         assertNull(test1020.gap(interval));
256         assertEquals(true, test1020.abuts(interval));
257         assertEquals(false, test1020.overlaps(interval));
258         assertEquals(false, test1020.contains(interval));
259         assertNull(interval.gap(test1020));
260         assertEquals(true, interval.abuts(test1020));
261         assertEquals(false, interval.overlaps(test1020));
262         assertEquals(false, interval.contains(test1020));
263         
264         // [8,12) [10,20) - overlaps
265         interval = new Interval(8, 12);
266         assertNull(test1020.gap(interval));
267         assertEquals(false, test1020.abuts(interval));
268         assertEquals(true, test1020.overlaps(interval));
269         assertEquals(false, test1020.contains(interval));
270         assertNull(interval.gap(test1020));
271         assertEquals(false, interval.abuts(test1020));
272         assertEquals(true, interval.overlaps(test1020));
273         assertEquals(false, interval.contains(test1020));
274         
275         // [10,14) [10,20) - overlaps and contains-one-way
276         interval = new Interval(10, 14);
277         assertNull(test1020.gap(interval));
278         assertEquals(false, test1020.abuts(interval));
279         assertEquals(true, test1020.overlaps(interval));
280         assertEquals(true, test1020.contains(interval));
281         assertNull(interval.gap(test1020));
282         assertEquals(false, interval.abuts(test1020));
283         assertEquals(true, interval.overlaps(test1020));
284         assertEquals(false, interval.contains(test1020));
285         
286         // [10,20) [10,20) - overlaps and contains-both-ways
287         assertNull(test1020.gap(interval));
288         assertEquals(false, test1020.abuts(test1020));
289         assertEquals(true, test1020.overlaps(test1020));
290         assertEquals(true, test1020.contains(test1020));
291         
292         // [10,20) [16,20) - overlaps and contains-one-way
293         interval = new Interval(16, 20);
294         assertNull(test1020.gap(interval));
295         assertEquals(false, test1020.abuts(interval));
296         assertEquals(true, test1020.overlaps(interval));
297         assertEquals(true, test1020.contains(interval));
298         assertNull(interval.gap(test1020));
299         assertEquals(false, interval.abuts(test1020));
300         assertEquals(true, interval.overlaps(test1020));
301         assertEquals(false, interval.contains(test1020));
302         
303         // [10,20) [18,22) - overlaps
304         interval = new Interval(18, 22);
305         assertNull(test1020.gap(interval));
306         assertEquals(false, test1020.abuts(interval));
307         assertEquals(true, test1020.overlaps(interval));
308         assertEquals(false, test1020.contains(interval));
309         assertNull(interval.gap(test1020));
310         assertEquals(false, interval.abuts(test1020));
311         assertEquals(true, interval.overlaps(test1020));
312         assertEquals(false, interval.contains(test1020));
313         
314         // [10,20) [20,24) - abuts
315         interval = new Interval(20, 24);
316         assertNull(test1020.gap(interval));
317         assertEquals(true, test1020.abuts(interval));
318         assertEquals(false, test1020.overlaps(interval));
319         assertEquals(false, test1020.contains(interval));
320         assertNull(interval.gap(test1020));
321         assertEquals(true, interval.abuts(test1020));
322         assertEquals(false, interval.overlaps(test1020));
323         assertEquals(false, interval.contains(test1020));
324         
325         // [10,20) [22,26) - gap
326         interval = new Interval(22, 26);
327         assertNotNull(test1020.gap(interval));
328         assertEquals(false, test1020.abuts(interval));
329         assertEquals(false, test1020.overlaps(interval));
330         assertEquals(false, test1020.contains(interval));
331         assertNotNull(interval.gap(test1020));
332         assertEquals(false, interval.abuts(test1020));
333         assertEquals(false, interval.overlaps(test1020));
334         assertEquals(false, interval.contains(test1020));
335     }
336 
337     //-----------------------------------------------------------------------
338     public void test_useCase_ContainsOverlapAbutGap_zeroDuration() {
339         // this is a simple test to ensure that the use case of these methods
340         // is OK when considering a zero duration inerval
341         // when comparing any two intervals they can be in one and only one of these states
342         // (a) have a gap between them, (b) abut or (c) overlap
343         // contains is a subset of overlap
344         Interval test1020 = new Interval(10, 20);
345         
346         // [8,8) [10,20) - gap
347         Interval interval = new Interval(8, 8);
348         assertNotNull(test1020.gap(interval));
349         assertEquals(false, test1020.abuts(interval));
350         assertEquals(false, test1020.overlaps(interval));
351         assertEquals(false, test1020.contains(interval));
352         assertNotNull(interval.gap(test1020));
353         assertEquals(false, interval.abuts(test1020));
354         assertEquals(false, interval.overlaps(test1020));
355         assertEquals(false, interval.contains(test1020));
356         
357         // [10,10) [10,20) - abuts and contains-one-way
358         interval = new Interval(10, 10);
359         assertNull(test1020.gap(interval));
360         assertEquals(true,  test1020.abuts(interval));
361         assertEquals(false, test1020.overlaps(interval));  // abuts, so can't overlap
362         assertEquals(true,  test1020.contains(interval));  // normal contains zero-duration
363         assertNull(interval.gap(test1020));
364         assertEquals(true,  interval.abuts(test1020));
365         assertEquals(false, interval.overlaps(test1020));  // abuts, so can't overlap
366         assertEquals(false, interval.contains(test1020));  // zero-duration does not contain normal
367         
368         // [12,12) [10,20) - contains-one-way and overlaps
369         interval = new Interval(12, 12);
370         assertNull(test1020.gap(interval));
371         assertEquals(false, test1020.abuts(interval));
372         assertEquals(true,  test1020.overlaps(interval));
373         assertEquals(true,  test1020.contains(interval));  // normal contains zero-duration
374         assertNull(interval.gap(test1020));
375         assertEquals(false, interval.abuts(test1020));
376         assertEquals(true,  interval.overlaps(test1020));
377         assertEquals(false, interval.contains(test1020));  // zero-duration does not contain normal
378         
379         // [10,20) [20,20) - abuts
380         interval = new Interval(20, 20);
381         assertNull(test1020.gap(interval));
382         assertEquals(true,  test1020.abuts(interval));
383         assertEquals(false, test1020.overlaps(interval));
384         assertEquals(false, test1020.contains(interval));
385         assertNull(interval.gap(test1020));
386         assertEquals(true,  interval.abuts(test1020));
387         assertEquals(false, interval.overlaps(test1020));
388         assertEquals(false, interval.contains(test1020));
389         
390         // [10,20) [22,22) - gap
391         interval = new Interval(22, 22);
392         assertNotNull(test1020.gap(interval));
393         assertEquals(false, test1020.abuts(interval));
394         assertEquals(false, test1020.overlaps(interval));
395         assertEquals(false, test1020.contains(interval));
396         assertNotNull(interval.gap(test1020));
397         assertEquals(false, interval.abuts(test1020));
398         assertEquals(false, interval.overlaps(test1020));
399         assertEquals(false, interval.contains(test1020));
400     }
401 
402     //-----------------------------------------------------------------------
403     public void test_useCase_ContainsOverlapAbutGap_bothZeroDuration() {
404         // this is a simple test to ensure that the use case of these methods
405         // is OK when considering two zero duration inervals
406         // this is the simplest case, as the two intervals either have a gap or not
407         // if not, then they are equal and abut
408         Interval test0808 = new Interval(8, 8);
409         Interval test1010 = new Interval(10, 10);
410         
411         // [8,8) [10,10) - gap
412         assertNotNull(test1010.gap(test0808));
413         assertEquals(false, test1010.abuts(test0808));
414         assertEquals(false, test1010.overlaps(test0808));
415         assertEquals(false, test1010.contains(test0808));
416         assertNotNull(test0808.gap(test1010));
417         assertEquals(false, test0808.abuts(test1010));
418         assertEquals(false, test0808.overlaps(test1010));
419         assertEquals(false, test0808.contains(test1010));
420         
421         // [10,10) [10,10) - abuts
422         assertNull(test1010.gap(test1010));
423         assertEquals(true,  test1010.abuts(test1010));
424         assertEquals(false, test1010.overlaps(test1010));
425         assertEquals(false, test1010.contains(test1010));
426     }
427 
428     //-----------------------------------------------------------------------
429     public void testContains_long() {
430         assertEquals(false, interval37.contains(2));  // value before
431         assertEquals(true,  interval37.contains(3));
432         assertEquals(true,  interval37.contains(4));
433         assertEquals(true,  interval37.contains(5));
434         assertEquals(true,  interval37.contains(6));
435         assertEquals(false, interval37.contains(7));  // value after
436         assertEquals(false, interval37.contains(8));  // value after
437     }
438 
439     public void testContains_long_zeroDuration() {
440         assertEquals(false, interval33.contains(2));  // value before
441         assertEquals(false, interval33.contains(3));  // zero length duration contains nothing
442         assertEquals(false, interval33.contains(4));  // value after
443     }
444 
445     //-----------------------------------------------------------------------
446     public void testContainsNow() {
447         DateTimeUtils.setCurrentMillisFixed(2);
448         assertEquals(false, interval37.containsNow());  // value before
449         DateTimeUtils.setCurrentMillisFixed(3);
450         assertEquals(true,  interval37.containsNow());
451         DateTimeUtils.setCurrentMillisFixed(4);
452         assertEquals(true,  interval37.containsNow());
453         DateTimeUtils.setCurrentMillisFixed(6);
454         assertEquals(true,  interval37.containsNow());
455         DateTimeUtils.setCurrentMillisFixed(7);
456         assertEquals(false, interval37.containsNow());  // value after
457         DateTimeUtils.setCurrentMillisFixed(8);
458         assertEquals(false, interval37.containsNow());  // value after
459         
460         DateTimeUtils.setCurrentMillisFixed(2);
461         assertEquals(false, interval33.containsNow());  // value before
462         DateTimeUtils.setCurrentMillisFixed(3);
463         assertEquals(false, interval33.containsNow());  // zero length duration contains nothing
464         DateTimeUtils.setCurrentMillisFixed(4);
465         assertEquals(false, interval33.containsNow());  // value after
466     }
467 
468     //-----------------------------------------------------------------------
469     public void testContains_RI() {
470         assertEquals(false, interval37.contains(new Instant(2)));  // value before
471         assertEquals(true,  interval37.contains(new Instant(3)));
472         assertEquals(true,  interval37.contains(new Instant(4)));
473         assertEquals(true,  interval37.contains(new Instant(5)));
474         assertEquals(true,  interval37.contains(new Instant(6)));
475         assertEquals(false, interval37.contains(new Instant(7)));  // value after
476         assertEquals(false, interval37.contains(new Instant(8)));  // value after
477     }
478 
479     public void testContains_RI_null() {
480         DateTimeUtils.setCurrentMillisFixed(2);
481         assertEquals(false, interval37.contains((ReadableInstant) null));  // value before
482         DateTimeUtils.setCurrentMillisFixed(3);
483         assertEquals(true,  interval37.contains((ReadableInstant) null));
484         DateTimeUtils.setCurrentMillisFixed(4);
485         assertEquals(true,  interval37.contains((ReadableInstant) null));
486         DateTimeUtils.setCurrentMillisFixed(6);
487         assertEquals(true,  interval37.contains((ReadableInstant) null));
488         DateTimeUtils.setCurrentMillisFixed(7);
489         assertEquals(false, interval37.contains((ReadableInstant) null));  // value after
490         DateTimeUtils.setCurrentMillisFixed(8);
491         assertEquals(false, interval37.contains((ReadableInstant) null));  // value after
492     }
493 
494     public void testContains_RI_zeroDuration() {
495         assertEquals(false, interval33.contains(new Instant(2)));  // value before
496         assertEquals(false, interval33.contains(new Instant(3)));  // zero length duration contains nothing
497         assertEquals(false, interval33.contains(new Instant(4)));  // value after
498     }
499 
500     //-----------------------------------------------------------------------
501     public void testContains_RInterval() {
502         assertEquals(false, interval37.contains(new Interval(1, 2)));  // gap before
503         assertEquals(false, interval37.contains(new Interval(2, 2)));  // gap before
504         
505         assertEquals(false, interval37.contains(new Interval(2, 3)));  // abuts before
506         assertEquals(true,  interval37.contains(new Interval(3, 3)));
507         
508         assertEquals(false, interval37.contains(new Interval(2, 4)));  // starts before
509         assertEquals(true,  interval37.contains(new Interval(3, 4)));
510         assertEquals(true,  interval37.contains(new Interval(4, 4)));
511         
512         assertEquals(false, interval37.contains(new Interval(2, 6)));  // starts before
513         assertEquals(true,  interval37.contains(new Interval(3, 6)));
514         assertEquals(true,  interval37.contains(new Interval(4, 6)));
515         assertEquals(true,  interval37.contains(new Interval(5, 6)));
516         assertEquals(true,  interval37.contains(new Interval(6, 6)));
517         
518         assertEquals(false, interval37.contains(new Interval(2, 7)));  // starts before
519         assertEquals(true,  interval37.contains(new Interval(3, 7)));
520         assertEquals(true,  interval37.contains(new Interval(4, 7)));
521         assertEquals(true,  interval37.contains(new Interval(5, 7)));
522         assertEquals(true,  interval37.contains(new Interval(6, 7)));
523         assertEquals(false, interval37.contains(new Interval(7, 7)));  // abuts after
524         
525         assertEquals(false, interval37.contains(new Interval(2, 8)));  // ends after
526         assertEquals(false, interval37.contains(new Interval(3, 8)));  // ends after
527         assertEquals(false, interval37.contains(new Interval(4, 8)));  // ends after
528         assertEquals(false, interval37.contains(new Interval(5, 8)));  // ends after
529         assertEquals(false, interval37.contains(new Interval(6, 8)));  // ends after
530         assertEquals(false, interval37.contains(new Interval(7, 8)));  // abuts after
531         assertEquals(false, interval37.contains(new Interval(8, 8)));  // gap after
532         
533         assertEquals(false, interval37.contains(new Interval(8, 9)));  // gap after
534         assertEquals(false, interval37.contains(new Interval(9, 9)));  // gap after
535     }
536 
537     public void testContains_RInterval_null() {
538         DateTimeUtils.setCurrentMillisFixed(2);
539         assertEquals(false, interval37.contains((ReadableInterval) null));  // gap before
540         DateTimeUtils.setCurrentMillisFixed(3);
541         assertEquals(true,  interval37.contains((ReadableInterval) null));
542         DateTimeUtils.setCurrentMillisFixed(4);
543         assertEquals(true,  interval37.contains((ReadableInterval) null));
544         DateTimeUtils.setCurrentMillisFixed(6);
545         assertEquals(true,  interval37.contains((ReadableInterval) null));
546         DateTimeUtils.setCurrentMillisFixed(7);
547         assertEquals(false, interval37.contains((ReadableInterval) null));  // abuts after
548         DateTimeUtils.setCurrentMillisFixed(8);
549         assertEquals(false, interval37.contains((ReadableInterval) null));  // gap after
550     }
551 
552     public void testContains_RInterval_zeroDuration() {
553         assertEquals(false, interval33.contains(interval33));  // zero length duration contains nothing
554         assertEquals(false, interval33.contains(interval37));  // zero-duration cannot contain anything
555         assertEquals(true,  interval37.contains(interval33));
556         assertEquals(false, interval33.contains(new Interval(1, 2)));  // zero-duration cannot contain anything
557         assertEquals(false, interval33.contains(new Interval(8, 9)));  // zero-duration cannot contain anything
558         assertEquals(false, interval33.contains(new Interval(1, 9)));  // zero-duration cannot contain anything
559         
560         DateTimeUtils.setCurrentMillisFixed(2);
561         assertEquals(false, interval33.contains((ReadableInterval) null));  // gap before
562         DateTimeUtils.setCurrentMillisFixed(3);
563         assertEquals(false, interval33.contains((ReadableInterval) null));  // zero length duration contains nothing
564         DateTimeUtils.setCurrentMillisFixed(4);
565         assertEquals(false, interval33.contains((ReadableInterval) null));  // gap after
566     }
567 
568     //-----------------------------------------------------------------------
569     public void testOverlaps_RInterval() {
570         assertEquals(false, interval37.overlaps(new Interval(1, 2)));  // gap before
571         assertEquals(false, interval37.overlaps(new Interval(2, 2)));  // gap before
572         
573         assertEquals(false, interval37.overlaps(new Interval(2, 3)));  // abuts before
574         assertEquals(false, interval37.overlaps(new Interval(3, 3)));  // abuts before
575         
576         assertEquals(true,  interval37.overlaps(new Interval(2, 4)));
577         assertEquals(true,  interval37.overlaps(new Interval(3, 4)));
578         assertEquals(true,  interval37.overlaps(new Interval(4, 4)));
579         
580         assertEquals(true,  interval37.overlaps(new Interval(2, 6)));
581         assertEquals(true,  interval37.overlaps(new Interval(3, 6)));
582         assertEquals(true,  interval37.overlaps(new Interval(4, 6)));
583         assertEquals(true,  interval37.overlaps(new Interval(5, 6)));
584         assertEquals(true,  interval37.overlaps(new Interval(6, 6)));
585         
586         assertEquals(true,  interval37.overlaps(new Interval(2, 7)));
587         assertEquals(true,  interval37.overlaps(new Interval(3, 7)));
588         assertEquals(true,  interval37.overlaps(new Interval(4, 7)));
589         assertEquals(true,  interval37.overlaps(new Interval(5, 7)));
590         assertEquals(true,  interval37.overlaps(new Interval(6, 7)));
591         assertEquals(false, interval37.overlaps(new Interval(7, 7)));  // abuts after
592         
593         assertEquals(true,  interval37.overlaps(new Interval(2, 8)));
594         assertEquals(true,  interval37.overlaps(new Interval(3, 8)));
595         assertEquals(true,  interval37.overlaps(new Interval(4, 8)));
596         assertEquals(true,  interval37.overlaps(new Interval(5, 8)));
597         assertEquals(true,  interval37.overlaps(new Interval(6, 8)));
598         assertEquals(false, interval37.overlaps(new Interval(7, 8)));  // abuts after
599         assertEquals(false, interval37.overlaps(new Interval(8, 8)));  // gap after
600         
601         assertEquals(false, interval37.overlaps(new Interval(8, 9)));  // gap after
602         assertEquals(false, interval37.overlaps(new Interval(9, 9)));  // gap after
603     }
604 
605     public void testOverlaps_RInterval_null() {
606         DateTimeUtils.setCurrentMillisFixed(2);
607         assertEquals(false, interval37.overlaps((ReadableInterval) null));  // gap before
608         DateTimeUtils.setCurrentMillisFixed(3);
609         assertEquals(false, interval37.overlaps((ReadableInterval) null));  // abuts before
610         DateTimeUtils.setCurrentMillisFixed(4);
611         assertEquals(true,  interval37.overlaps((ReadableInterval) null));
612         DateTimeUtils.setCurrentMillisFixed(6);
613         assertEquals(true,  interval37.overlaps((ReadableInterval) null));
614         DateTimeUtils.setCurrentMillisFixed(7);
615         assertEquals(false, interval37.overlaps((ReadableInterval) null));  // abuts after
616         DateTimeUtils.setCurrentMillisFixed(8);
617         assertEquals(false, interval37.overlaps((ReadableInterval) null));  // gap after
618         
619         DateTimeUtils.setCurrentMillisFixed(3);
620         assertEquals(false, interval33.overlaps((ReadableInterval) null));  // abuts before and after
621     }
622 
623     public void testOverlaps_RInterval_zeroDuration() {
624         assertEquals(false, interval33.overlaps(interval33));  // abuts before and after
625         assertEquals(false, interval33.overlaps(interval37));  // abuts before
626         assertEquals(false, interval37.overlaps(interval33));  // abuts before
627         assertEquals(false, interval33.overlaps(new Interval(1, 2)));
628         assertEquals(false, interval33.overlaps(new Interval(8, 9)));
629         assertEquals(true,  interval33.overlaps(new Interval(1, 9)));
630     }
631 
632     //-----------------------------------------------------------------------
633     public void testOverlap_RInterval() {
634         assertEquals(null, interval37.overlap(new Interval(1, 2)));  // gap before
635         assertEquals(null, interval37.overlap(new Interval(2, 2)));  // gap before
636         
637         assertEquals(null, interval37.overlap(new Interval(2, 3)));  // abuts before
638         assertEquals(null, interval37.overlap(new Interval(3, 3)));  // abuts before
639         
640         assertEquals(new Interval(3, 4), interval37.overlap(new Interval(2, 4)));  // truncated start
641         assertEquals(new Interval(3, 4), interval37.overlap(new Interval(3, 4)));
642         assertEquals(new Interval(4, 4), interval37.overlap(new Interval(4, 4)));
643         
644         assertEquals(new Interval(3, 7), interval37.overlap(new Interval(2, 7)));  // truncated start
645         assertEquals(new Interval(3, 7), interval37.overlap(new Interval(3, 7)));
646         assertEquals(new Interval(4, 7), interval37.overlap(new Interval(4, 7)));
647         assertEquals(new Interval(5, 7), interval37.overlap(new Interval(5, 7)));
648         assertEquals(new Interval(6, 7), interval37.overlap(new Interval(6, 7)));
649         assertEquals(null, interval37.overlap(new Interval(7, 7)));  // abuts after
650         
651         assertEquals(new Interval(3, 7), interval37.overlap(new Interval(2, 8)));  // truncated start and end
652         assertEquals(new Interval(3, 7), interval37.overlap(new Interval(3, 8)));  // truncated end
653         assertEquals(new Interval(4, 7), interval37.overlap(new Interval(4, 8)));  // truncated end
654         assertEquals(new Interval(5, 7), interval37.overlap(new Interval(5, 8)));  // truncated end
655         assertEquals(new Interval(6, 7), interval37.overlap(new Interval(6, 8)));  // truncated end
656         assertEquals(null, interval37.overlap(new Interval(7, 8)));  // abuts after
657         assertEquals(null, interval37.overlap(new Interval(8, 8)));  // gap after
658     }
659 
660     public void testOverlap_RInterval_null() {
661         DateTimeUtils.setCurrentMillisFixed(2);
662         assertEquals(null, interval37.overlap((ReadableInterval) null));  // gap before
663         DateTimeUtils.setCurrentMillisFixed(3);
664         assertEquals(null, interval37.overlap((ReadableInterval) null));  // abuts before
665         DateTimeUtils.setCurrentMillisFixed(4);
666         assertEquals(new Interval(4, 4), interval37.overlap((ReadableInterval) null));
667         DateTimeUtils.setCurrentMillisFixed(6);
668         assertEquals(new Interval(6, 6), interval37.overlap((ReadableInterval) null));
669         DateTimeUtils.setCurrentMillisFixed(7);
670         assertEquals(null, interval37.overlap((ReadableInterval) null));  // abuts after
671         DateTimeUtils.setCurrentMillisFixed(8);
672         assertEquals(null, interval37.overlap((ReadableInterval) null));  // gap after
673         
674         DateTimeUtils.setCurrentMillisFixed(3);
675         assertEquals(null, interval33.overlap((ReadableInterval) null));  // abuts before and after
676     }
677 
678     public void testOverlap_RInterval_zone() {
679         Interval testA = new Interval(new DateTime(3, LONDON), new DateTime(7, LONDON));
680         assertEquals(ISOChronology.getInstance(LONDON), testA.getChronology());
681         
682         Interval testB = new Interval(new DateTime(4, MOSCOW), new DateTime(8, MOSCOW));
683         assertEquals(ISOChronology.getInstance(MOSCOW), testB.getChronology());
684         
685         Interval resultAB = testA.overlap(testB);
686         assertEquals(ISOChronology.getInstance(LONDON), resultAB.getChronology());
687         
688         Interval resultBA = testB.overlap(testA);
689         assertEquals(ISOChronology.getInstance(MOSCOW), resultBA.getChronology());
690     }
691 
692     public void testOverlap_RInterval_zoneUTC() {
693         Interval testA = new Interval(new Instant(3), new Instant(7));
694         assertEquals(ISOChronology.getInstanceUTC(), testA.getChronology());
695         
696         Interval testB = new Interval(new Instant(4), new Instant(8));
697         assertEquals(ISOChronology.getInstanceUTC(), testB.getChronology());
698         
699         Interval result = testA.overlap(testB);
700         assertEquals(ISOChronology.getInstanceUTC(), result.getChronology());
701     }
702 
703     //-----------------------------------------------------------------------
704     public void testGap_RInterval() {
705         assertEquals(new Interval(1, 3), interval37.gap(new Interval(0, 1)));
706         assertEquals(new Interval(1, 3), interval37.gap(new Interval(1, 1)));
707         
708         assertEquals(null, interval37.gap(new Interval(2, 3)));  // abuts before
709         assertEquals(null, interval37.gap(new Interval(3, 3)));  // abuts before
710         
711         assertEquals(null, interval37.gap(new Interval(4, 6)));  // overlaps
712         
713         assertEquals(null, interval37.gap(new Interval(3, 7)));  // overlaps
714         assertEquals(null, interval37.gap(new Interval(6, 7)));  // overlaps
715         assertEquals(null, interval37.gap(new Interval(7, 7)));  // abuts after
716         
717         assertEquals(null, interval37.gap(new Interval(6, 8)));  // overlaps
718         assertEquals(null, interval37.gap(new Interval(7, 8)));  // abuts after
719         assertEquals(new Interval(7, 8), interval37.gap(new Interval(8, 8)));
720         
721         assertEquals(null, interval37.gap(new Interval(6, 9)));  // overlaps
722         assertEquals(null, interval37.gap(new Interval(7, 9)));  // abuts after
723         assertEquals(new Interval(7, 8), interval37.gap(new Interval(8, 9)));
724         assertEquals(new Interval(7, 9), interval37.gap(new Interval(9, 9)));
725     }
726 
727     public void testGap_RInterval_null() {
728         DateTimeUtils.setCurrentMillisFixed(2);
729         assertEquals(new Interval(2, 3),  interval37.gap((ReadableInterval) null));
730         DateTimeUtils.setCurrentMillisFixed(3);
731         assertEquals(null,  interval37.gap((ReadableInterval) null));  // abuts before
732         DateTimeUtils.setCurrentMillisFixed(4);
733         assertEquals(null,  interval37.gap((ReadableInterval) null));  // overlaps
734         DateTimeUtils.setCurrentMillisFixed(6);
735         assertEquals(null,  interval37.gap((ReadableInterval) null));  // overlaps
736         DateTimeUtils.setCurrentMillisFixed(7);
737         assertEquals(null,  interval37.gap((ReadableInterval) null));  // abuts after
738         DateTimeUtils.setCurrentMillisFixed(8);
739         assertEquals(new Interval(7, 8),  interval37.gap((ReadableInterval) null));
740     }
741 
742     public void testGap_RInterval_zone() {
743         Interval testA = new Interval(new DateTime(3, LONDON), new DateTime(7, LONDON));
744         assertEquals(ISOChronology.getInstance(LONDON), testA.getChronology());
745         
746         Interval testB = new Interval(new DateTime(1, MOSCOW), new DateTime(2, MOSCOW));
747         assertEquals(ISOChronology.getInstance(MOSCOW), testB.getChronology());
748         
749         Interval resultAB = testA.gap(testB);
750         assertEquals(ISOChronology.getInstance(LONDON), resultAB.getChronology());
751         
752         Interval resultBA = testB.gap(testA);
753         assertEquals(ISOChronology.getInstance(MOSCOW), resultBA.getChronology());
754     }
755 
756     public void testGap_RInterval_zoneUTC() {
757         Interval testA = new Interval(new Instant(3), new Instant(7));
758         assertEquals(ISOChronology.getInstanceUTC(), testA.getChronology());
759         
760         Interval testB = new Interval(new Instant(1), new Instant(2));
761         assertEquals(ISOChronology.getInstanceUTC(), testB.getChronology());
762         
763         Interval result = testA.gap(testB);
764         assertEquals(ISOChronology.getInstanceUTC(), result.getChronology());
765     }
766 
767     //-----------------------------------------------------------------------
768     public void testAbuts_RInterval() {
769         assertEquals(false, interval37.abuts(new Interval(1, 2)));  // gap before
770         assertEquals(false, interval37.abuts(new Interval(2, 2)));  // gap before
771         
772         assertEquals(true,  interval37.abuts(new Interval(2, 3)));
773         assertEquals(true,  interval37.abuts(new Interval(3, 3)));
774         
775         assertEquals(false, interval37.abuts(new Interval(2, 4)));  // overlaps
776         assertEquals(false, interval37.abuts(new Interval(3, 4)));  // overlaps
777         assertEquals(false, interval37.abuts(new Interval(4, 4)));  // overlaps
778         
779         assertEquals(false, interval37.abuts(new Interval(2, 6)));  // overlaps
780         assertEquals(false, interval37.abuts(new Interval(3, 6)));  // overlaps
781         assertEquals(false, interval37.abuts(new Interval(4, 6)));  // overlaps
782         assertEquals(false, interval37.abuts(new Interval(5, 6)));  // overlaps
783         assertEquals(false, interval37.abuts(new Interval(6, 6)));  // overlaps
784         
785         assertEquals(false, interval37.abuts(new Interval(2, 7)));  // overlaps
786         assertEquals(false, interval37.abuts(new Interval(3, 7)));  // overlaps
787         assertEquals(false, interval37.abuts(new Interval(4, 7)));  // overlaps
788         assertEquals(false, interval37.abuts(new Interval(5, 7)));  // overlaps
789         assertEquals(false, interval37.abuts(new Interval(6, 7)));  // overlaps
790         assertEquals(true,  interval37.abuts(new Interval(7, 7)));
791         
792         assertEquals(false, interval37.abuts(new Interval(2, 8)));  // overlaps
793         assertEquals(false, interval37.abuts(new Interval(3, 8)));  // overlaps
794         assertEquals(false, interval37.abuts(new Interval(4, 8)));  // overlaps
795         assertEquals(false, interval37.abuts(new Interval(5, 8)));  // overlaps
796         assertEquals(false, interval37.abuts(new Interval(6, 8)));  // overlaps
797         assertEquals(true,  interval37.abuts(new Interval(7, 8)));
798         assertEquals(false, interval37.abuts(new Interval(8, 8)));  // gap after
799         
800         assertEquals(false, interval37.abuts(new Interval(8, 9)));  // gap after
801         assertEquals(false, interval37.abuts(new Interval(9, 9)));  // gap after
802     }
803 
804     public void testAbuts_RInterval_null() {
805         DateTimeUtils.setCurrentMillisFixed(2);
806         assertEquals(false,  interval37.abuts((ReadableInterval) null));  // gap before
807         DateTimeUtils.setCurrentMillisFixed(3);
808         assertEquals(true,  interval37.abuts((ReadableInterval) null));
809         DateTimeUtils.setCurrentMillisFixed(4);
810         assertEquals(false,  interval37.abuts((ReadableInterval) null));  // overlaps
811         DateTimeUtils.setCurrentMillisFixed(6);
812         assertEquals(false,  interval37.abuts((ReadableInterval) null));  // overlaps
813         DateTimeUtils.setCurrentMillisFixed(7);
814         assertEquals(true,  interval37.abuts((ReadableInterval) null));
815         DateTimeUtils.setCurrentMillisFixed(8);
816         assertEquals(false,  interval37.abuts((ReadableInterval) null));  // gap after
817     }
818 
819     // -----------------------------------------------------------------------
820     public void testIsBefore_long() {
821         assertEquals(false, interval37.isBefore(2));
822         assertEquals(false, interval37.isBefore(3));
823         assertEquals(false, interval37.isBefore(4));
824         assertEquals(false, interval37.isBefore(5));
825         assertEquals(false, interval37.isBefore(6));
826         assertEquals(true,  interval37.isBefore(7));
827         assertEquals(true,  interval37.isBefore(8));
828     }
829 
830     public void testIsBeforeNow() {
831         DateTimeUtils.setCurrentMillisFixed(2);
832         assertEquals(false, interval37.isBeforeNow());
833         DateTimeUtils.setCurrentMillisFixed(3);
834         assertEquals(false, interval37.isBeforeNow());
835         DateTimeUtils.setCurrentMillisFixed(4);
836         assertEquals(false, interval37.isBeforeNow());
837         DateTimeUtils.setCurrentMillisFixed(6);
838         assertEquals(false, interval37.isBeforeNow());
839         DateTimeUtils.setCurrentMillisFixed(7);
840         assertEquals(true, interval37.isBeforeNow());
841         DateTimeUtils.setCurrentMillisFixed(8);
842         assertEquals(true, interval37.isBeforeNow());
843     }
844 
845     public void testIsBefore_RI() {
846         assertEquals(false, interval37.isBefore(new Instant(2)));
847         assertEquals(false, interval37.isBefore(new Instant(3)));
848         assertEquals(false, interval37.isBefore(new Instant(4)));
849         assertEquals(false, interval37.isBefore(new Instant(5)));
850         assertEquals(false, interval37.isBefore(new Instant(6)));
851         assertEquals(true,  interval37.isBefore(new Instant(7)));
852         assertEquals(true,  interval37.isBefore(new Instant(8)));
853     }
854 
855     public void testIsBefore_RI_null() {
856         DateTimeUtils.setCurrentMillisFixed(2);
857         assertEquals(false, interval37.isBefore((ReadableInstant) null));
858         DateTimeUtils.setCurrentMillisFixed(3);
859         assertEquals(false, interval37.isBefore((ReadableInstant) null));
860         DateTimeUtils.setCurrentMillisFixed(4);
861         assertEquals(false, interval37.isBefore((ReadableInstant) null));
862         DateTimeUtils.setCurrentMillisFixed(6);
863         assertEquals(false, interval37.isBefore((ReadableInstant) null));
864         DateTimeUtils.setCurrentMillisFixed(7);
865         assertEquals(true, interval37.isBefore((ReadableInstant) null));
866         DateTimeUtils.setCurrentMillisFixed(8);
867         assertEquals(true, interval37.isBefore((ReadableInstant) null));
868     }
869 
870     public void testIsBefore_RInterval() {
871         assertEquals(false, interval37.isBefore(new Interval(Long.MIN_VALUE, 2)));
872         assertEquals(false, interval37.isBefore(new Interval(Long.MIN_VALUE, 3)));
873         assertEquals(false, interval37.isBefore(new Interval(Long.MIN_VALUE, 4)));
874         
875         assertEquals(false, interval37.isBefore(new Interval(6, Long.MAX_VALUE)));
876         assertEquals(true, interval37.isBefore(new Interval(7, Long.MAX_VALUE)));
877         assertEquals(true, interval37.isBefore(new Interval(8, Long.MAX_VALUE)));
878     }
879 
880     public void testIsBefore_RInterval_null() {
881         DateTimeUtils.setCurrentMillisFixed(2);
882         assertEquals(false, interval37.isBefore((ReadableInterval) null));
883         DateTimeUtils.setCurrentMillisFixed(3);
884         assertEquals(false, interval37.isBefore((ReadableInterval) null));
885         DateTimeUtils.setCurrentMillisFixed(4);
886         assertEquals(false, interval37.isBefore((ReadableInterval) null));
887         DateTimeUtils.setCurrentMillisFixed(6);
888         assertEquals(false, interval37.isBefore((ReadableInterval) null));
889         DateTimeUtils.setCurrentMillisFixed(7);
890         assertEquals(true, interval37.isBefore((ReadableInterval) null));
891         DateTimeUtils.setCurrentMillisFixed(8);
892         assertEquals(true, interval37.isBefore((ReadableInterval) null));
893     }
894 
895     //-----------------------------------------------------------------------
896     public void testIsAfter_long() {
897         assertEquals(true,  interval37.isAfter(2));
898         assertEquals(false, interval37.isAfter(3));
899         assertEquals(false, interval37.isAfter(4));
900         assertEquals(false, interval37.isAfter(5));
901         assertEquals(false, interval37.isAfter(6));
902         assertEquals(false, interval37.isAfter(7));
903         assertEquals(false, interval37.isAfter(8));
904     }
905 
906     public void testIsAfterNow() {
907         DateTimeUtils.setCurrentMillisFixed(2);
908         assertEquals(true, interval37.isAfterNow());
909         DateTimeUtils.setCurrentMillisFixed(3);
910         assertEquals(false, interval37.isAfterNow());
911         DateTimeUtils.setCurrentMillisFixed(4);
912         assertEquals(false, interval37.isAfterNow());
913         DateTimeUtils.setCurrentMillisFixed(6);
914         assertEquals(false, interval37.isAfterNow());
915         DateTimeUtils.setCurrentMillisFixed(7);
916         assertEquals(false, interval37.isAfterNow());
917         DateTimeUtils.setCurrentMillisFixed(8);
918         assertEquals(false, interval37.isAfterNow());
919     }
920 
921     public void testIsAfter_RI() {
922         assertEquals(true,  interval37.isAfter(new Instant(2)));
923         assertEquals(false, interval37.isAfter(new Instant(3)));
924         assertEquals(false, interval37.isAfter(new Instant(4)));
925         assertEquals(false, interval37.isAfter(new Instant(5)));
926         assertEquals(false, interval37.isAfter(new Instant(6)));
927         assertEquals(false, interval37.isAfter(new Instant(7)));
928         assertEquals(false, interval37.isAfter(new Instant(8)));
929     }
930 
931     public void testIsAfter_RI_null() {
932         DateTimeUtils.setCurrentMillisFixed(2);
933         assertEquals(true, interval37.isAfter((ReadableInstant) null));
934         DateTimeUtils.setCurrentMillisFixed(3);
935         assertEquals(false, interval37.isAfter((ReadableInstant) null));
936         DateTimeUtils.setCurrentMillisFixed(4);
937         assertEquals(false, interval37.isAfter((ReadableInstant) null));
938         DateTimeUtils.setCurrentMillisFixed(6);
939         assertEquals(false, interval37.isAfter((ReadableInstant) null));
940         DateTimeUtils.setCurrentMillisFixed(7);
941         assertEquals(false, interval37.isAfter((ReadableInstant) null));
942         DateTimeUtils.setCurrentMillisFixed(8);
943         assertEquals(false, interval37.isAfter((ReadableInstant) null));
944     }
945 
946     public void testIsAfter_RInterval() {
947         assertEquals(true, interval37.isAfter(new Interval(Long.MIN_VALUE, 2)));
948         assertEquals(true, interval37.isAfter(new Interval(Long.MIN_VALUE, 3)));
949         assertEquals(false, interval37.isAfter(new Interval(Long.MIN_VALUE, 4)));
950         
951         assertEquals(false, interval37.isAfter(new Interval(6, Long.MAX_VALUE)));
952         assertEquals(false, interval37.isAfter(new Interval(7, Long.MAX_VALUE)));
953         assertEquals(false, interval37.isAfter(new Interval(8, Long.MAX_VALUE)));
954     }
955 
956     public void testIsAfter_RInterval_null() {
957         DateTimeUtils.setCurrentMillisFixed(2);
958         assertEquals(true, interval37.isAfter((ReadableInterval) null));
959         DateTimeUtils.setCurrentMillisFixed(3);
960         assertEquals(true, interval37.isAfter((ReadableInterval) null));
961         DateTimeUtils.setCurrentMillisFixed(4);
962         assertEquals(false, interval37.isAfter((ReadableInterval) null));
963         DateTimeUtils.setCurrentMillisFixed(6);
964         assertEquals(false, interval37.isAfter((ReadableInterval) null));
965         DateTimeUtils.setCurrentMillisFixed(7);
966         assertEquals(false, interval37.isAfter((ReadableInterval) null));
967         DateTimeUtils.setCurrentMillisFixed(8);
968         assertEquals(false, interval37.isAfter((ReadableInterval) null));
969     }
970 
971     //-----------------------------------------------------------------------
972     public void testToInterval1() {
973         Interval test = new Interval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
974         Interval result = test.toInterval();
975         assertSame(test, result);
976     }
977 
978     //-----------------------------------------------------------------------
979     public void testToMutableInterval1() {
980         Interval test = new Interval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
981         MutableInterval result = test.toMutableInterval();
982         assertEquals(test, result);
983     }
984 
985     //-----------------------------------------------------------------------
986     public void testToPeriod() {
987         DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10, COPTIC_PARIS);
988         DateTime dt2 = new DateTime(2005, 8, 13, 12, 14, 16, 18, COPTIC_PARIS);
989         Interval base = new Interval(dt1, dt2);
990         
991         Period test = base.toPeriod();
992         Period expected = new Period(dt1, dt2, PeriodType.standard());
993         assertEquals(expected, test);
994     }
995 
996     //-----------------------------------------------------------------------
997     public void testToPeriod_PeriodType1() {
998         DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10, COPTIC_PARIS);
999         DateTime dt2 = new DateTime(2005, 8, 13, 12, 14, 16, 18, COPTIC_PARIS);
1000         Interval base = new Interval(dt1, dt2);
1001         
1002         Period test = base.toPeriod(null);
1003         Period expected = new Period(dt1, dt2, PeriodType.standard());
1004         assertEquals(expected, test);
1005     }
1006 
1007     public void testToPeriod_PeriodType2() {
1008         DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10);
1009         DateTime dt2 = new DateTime(2005, 8, 13, 12, 14, 16, 18);
1010         Interval base = new Interval(dt1, dt2);
1011         
1012         Period test = base.toPeriod(PeriodType.yearWeekDayTime());
1013         Period expected = new Period(dt1, dt2, PeriodType.yearWeekDayTime());
1014         assertEquals(expected, test);
1015     }
1016 
1017     //-----------------------------------------------------------------------
1018     public void testSerialization() throws Exception {
1019         Interval test = new Interval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
1020         
1021         ByteArrayOutputStream baos = new ByteArrayOutputStream();
1022         ObjectOutputStream oos = new ObjectOutputStream(baos);
1023         oos.writeObject(test);
1024         byte[] bytes = baos.toByteArray();
1025         oos.close();
1026         
1027         ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
1028         ObjectInputStream ois = new ObjectInputStream(bais);
1029         Interval result = (Interval) ois.readObject();
1030         ois.close();
1031         
1032         assertEquals(test, result);
1033     }
1034 
1035     //-----------------------------------------------------------------------
1036     public void testToString() {
1037         DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10, DateTimeZone.UTC);
1038         DateTime dt2 = new DateTime(2005, 8, 13, 12, 14, 16, 18, DateTimeZone.UTC);
1039         Interval test = new Interval(dt1, dt2);
1040         assertEquals("2004-06-09T07:08:09.010Z/2005-08-13T12:14:16.018Z", test.toString());
1041     }
1042 
1043     public void testToString_reparse() {
1044         DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10, DateTimeZone.getDefault());
1045         DateTime dt2 = new DateTime(2005, 8, 13, 12, 14, 16, 18, DateTimeZone.getDefault());
1046         Interval test = new Interval(dt1, dt2);
1047         assertEquals(test, new Interval(test.toString()));
1048     }
1049 
1050     //-----------------------------------------------------------------------
1051     public void testWithChronology1() {
1052         Interval base = new Interval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
1053         Interval test = base.withChronology(BuddhistChronology.getInstance());
1054         assertEquals(new Interval(TEST_TIME1, TEST_TIME2, BuddhistChronology.getInstance()), test);
1055     }
1056 
1057     public void testWithChronology2() {
1058         Interval base = new Interval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
1059         Interval test = base.withChronology(null);
1060         assertEquals(new Interval(TEST_TIME1, TEST_TIME2, ISOChronology.getInstance()), test);
1061     }
1062 
1063     public void testWithChronology3() {
1064         Interval base = new Interval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
1065         Interval test = base.withChronology(COPTIC_PARIS);
1066         assertSame(base, test);
1067     }
1068 
1069     //-----------------------------------------------------------------------
1070     public void testWithStartMillis_long1() {
1071         Interval base = new Interval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
1072         Interval test = base.withStartMillis(TEST_TIME1 - 1);
1073         assertEquals(new Interval(TEST_TIME1 - 1, TEST_TIME2, COPTIC_PARIS), test);
1074     }
1075 
1076     public void testWithStartMillis_long2() {
1077         Interval test = new Interval(TEST_TIME1, TEST_TIME2);
1078         try {
1079             test.withStartMillis(TEST_TIME2 + 1);
1080             fail();
1081         } catch (IllegalArgumentException ex) {}
1082     }
1083 
1084     public void testWithStartMillis_long3() {
1085         Interval base = new Interval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
1086         Interval test = base.withStartMillis(TEST_TIME1);
1087         assertSame(base, test);
1088     }
1089 
1090     //-----------------------------------------------------------------------
1091     public void testWithStartInstant_RI1() {
1092         Interval base = new Interval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
1093         Interval test = base.withStart(new Instant(TEST_TIME1 - 1));
1094         assertEquals(new Interval(TEST_TIME1 - 1, TEST_TIME2, COPTIC_PARIS), test);
1095     }
1096 
1097     public void testWithStartInstant_RI2() {
1098         Interval test = new Interval(TEST_TIME1, TEST_TIME2);
1099         try {
1100             test.withStart(new Instant(TEST_TIME2 + 1));
1101             fail();
1102         } catch (IllegalArgumentException ex) {}
1103     }
1104 
1105     public void testWithStartInstant_RI3() {
1106         Interval base = new Interval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
1107         Interval test = base.withStart(null);
1108         assertEquals(new Interval(TEST_TIME_NOW, TEST_TIME2, COPTIC_PARIS), test);
1109     }
1110 
1111     //-----------------------------------------------------------------------
1112     public void testWithEndMillis_long1() {
1113         Interval base = new Interval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
1114         Interval test = base.withEndMillis(TEST_TIME2 - 1);
1115         assertEquals(new Interval(TEST_TIME1, TEST_TIME2 - 1, COPTIC_PARIS), test);
1116     }
1117 
1118     public void testWithEndMillis_long2() {
1119         Interval test = new Interval(TEST_TIME1, TEST_TIME2);
1120         try {
1121             test.withEndMillis(TEST_TIME1 - 1);
1122             fail();
1123         } catch (IllegalArgumentException ex) {}
1124     }
1125 
1126     public void testWithEndMillis_long3() {
1127         Interval base = new Interval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
1128         Interval test = base.withEndMillis(TEST_TIME2);
1129         assertSame(base, test);
1130     }
1131 
1132     //-----------------------------------------------------------------------
1133     public void testWithEndInstant_RI1() {
1134         Interval base = new Interval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
1135         Interval test = base.withEnd(new Instant(TEST_TIME2 - 1));
1136         assertEquals(new Interval(TEST_TIME1, TEST_TIME2 - 1, COPTIC_PARIS), test);
1137     }
1138 
1139     public void testWithEndInstant_RI2() {
1140         Interval test = new Interval(TEST_TIME1, TEST_TIME2);
1141         try {
1142             test.withEnd(new Instant(TEST_TIME1 - 1));
1143             fail();
1144         } catch (IllegalArgumentException ex) {}
1145     }
1146 
1147     public void testWithEndInstant_RI3() {
1148         Interval base = new Interval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
1149         Interval test = base.withEnd(null);
1150         assertEquals(new Interval(TEST_TIME1, TEST_TIME_NOW, COPTIC_PARIS), test);
1151     }
1152 
1153     //-----------------------------------------------------------------------
1154     public void testWithDurationAfterStart1() throws Throwable {
1155         Duration dur = new Duration(TEST_TIME2 - TEST_TIME_NOW);
1156         Interval base = new Interval(TEST_TIME_NOW, TEST_TIME_NOW, COPTIC_PARIS);
1157         Interval test = base.withDurationAfterStart(dur);
1158         
1159         assertEquals(new Interval(TEST_TIME_NOW, TEST_TIME2, COPTIC_PARIS), test);
1160     }
1161 
1162     public void testWithDurationAfterStart2() throws Throwable {
1163         Interval base = new Interval(TEST_TIME_NOW, TEST_TIME2, COPTIC_PARIS);
1164         Interval test = base.withDurationAfterStart(null);
1165         
1166         assertEquals(new Interval(TEST_TIME_NOW, TEST_TIME_NOW, COPTIC_PARIS), test);
1167     }
1168 
1169     public void testWithDurationAfterStart3() throws Throwable {
1170         Duration dur = new Duration(-1);
1171         Interval base = new Interval(TEST_TIME_NOW, TEST_TIME_NOW);
1172         try {
1173             base.withDurationAfterStart(dur);
1174             fail();
1175         } catch (IllegalArgumentException ex) {}
1176     }
1177 
1178     public void testWithDurationAfterStart4() throws Throwable {
1179         Interval base = new Interval(TEST_TIME_NOW, TEST_TIME2, COPTIC_PARIS);
1180         Interval test = base.withDurationAfterStart(base.toDuration());
1181         
1182         assertSame(base, test);
1183     }
1184 
1185     //-----------------------------------------------------------------------
1186     public void testWithDurationBeforeEnd1() throws Throwable {
1187         Duration dur = new Duration(TEST_TIME_NOW - TEST_TIME1);
1188         Interval base = new Interval(TEST_TIME_NOW, TEST_TIME_NOW, COPTIC_PARIS);
1189         Interval test = base.withDurationBeforeEnd(dur);
1190         
1191         assertEquals(new Interval(TEST_TIME1, TEST_TIME_NOW, COPTIC_PARIS), test);
1192     }
1193 
1194     public void testWithDurationBeforeEnd2() throws Throwable {
1195         Interval base = new Interval(TEST_TIME_NOW, TEST_TIME2, COPTIC_PARIS);
1196         Interval test = base.withDurationBeforeEnd(null);
1197         
1198         assertEquals(new Interval(TEST_TIME2, TEST_TIME2, COPTIC_PARIS), test);
1199     }
1200 
1201     public void testWithDurationBeforeEnd3() throws Throwable {
1202         Duration dur = new Duration(-1);
1203         Interval base = new Interval(TEST_TIME_NOW, TEST_TIME_NOW);
1204         try {
1205             base.withDurationBeforeEnd(dur);
1206             fail();
1207         } catch (IllegalArgumentException ex) {}
1208     }
1209 
1210     public void testWithDurationBeforeEnd4() throws Throwable {
1211         Interval base = new Interval(TEST_TIME_NOW, TEST_TIME2, COPTIC_PARIS);
1212         Interval test = base.withDurationBeforeEnd(base.toDuration());
1213         
1214         assertSame(base, test);
1215     }
1216 
1217     //-----------------------------------------------------------------------
1218     public void testWithPeriodAfterStart1() throws Throwable {
1219         DateTime dt = new DateTime(TEST_TIME_NOW, COPTIC_PARIS);
1220         Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
1221         
1222         Interval base = new Interval(dt, dt);
1223         Interval test = base.withPeriodAfterStart(dur);
1224         assertEquals(new Interval(dt, dur), test);
1225     }
1226 
1227     public void testWithPeriodAfterStart2() throws Throwable {
1228         Interval base = new Interval(TEST_TIME_NOW, TEST_TIME2, COPTIC_PARIS);
1229         Interval test = base.withPeriodAfterStart(null);
1230         
1231         assertEquals(new Interval(TEST_TIME_NOW, TEST_TIME_NOW, COPTIC_PARIS), test);
1232     }
1233 
1234     public void testWithPeriodAfterStart3() throws Throwable {
1235         Period per = new Period(0, 0, 0, 0, 0, 0, 0, -1);
1236         Interval base = new Interval(TEST_TIME_NOW, TEST_TIME_NOW);
1237         try {
1238             base.withPeriodAfterStart(per);
1239             fail();
1240         } catch (IllegalArgumentException ex) {}
1241     }
1242 
1243     //-----------------------------------------------------------------------
1244     public void testWithPeriodBeforeEnd1() throws Throwable {
1245         DateTime dt = new DateTime(TEST_TIME_NOW, COPTIC_PARIS);
1246         Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
1247         
1248         Interval base = new Interval(dt, dt);
1249         Interval test = base.withPeriodBeforeEnd(dur);
1250         assertEquals(new Interval(dur, dt), test);
1251     }
1252 
1253     public void testWithPeriodBeforeEnd2() throws Throwable {
1254         Interval base = new Interval(TEST_TIME_NOW, TEST_TIME2, COPTIC_PARIS);
1255         Interval test = base.withPeriodBeforeEnd(null);
1256         
1257         assertEquals(new Interval(TEST_TIME2, TEST_TIME2, COPTIC_PARIS), test);
1258     }
1259 
1260     public void testWithPeriodBeforeEnd3() throws Throwable {
1261         Period per = new Period(0, 0, 0, 0, 0, 0, 0, -1);
1262         Interval base = new Interval(TEST_TIME_NOW, TEST_TIME_NOW);
1263         try {
1264             base.withPeriodBeforeEnd(per);
1265             fail();
1266         } catch (IllegalArgumentException ex) {}
1267     }
1268 
1269 }