001: /*
002: * Copyright 2001-2006 Stephen Colebourne
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.joda.time;
017:
018: import java.io.ByteArrayInputStream;
019: import java.io.ByteArrayOutputStream;
020: import java.io.ObjectInputStream;
021: import java.io.ObjectOutputStream;
022: import java.util.Locale;
023: import java.util.TimeZone;
024:
025: import junit.framework.TestCase;
026: import junit.framework.TestSuite;
027:
028: import org.joda.time.base.AbstractInterval;
029: import org.joda.time.chrono.CopticChronology;
030: import org.joda.time.chrono.GJChronology;
031: import org.joda.time.chrono.ISOChronology;
032:
033: /**
034: * This class is a Junit unit test for Instant.
035: *
036: * @author Stephen Colebourne
037: */
038: public class TestMutableInterval_Basics extends TestCase {
039: // Test in 2002/03 as time zones are more well known
040: // (before the late 90's they were all over the place)
041:
042: private static final DateTimeZone PARIS = DateTimeZone
043: .forID("Europe/Paris");
044: private static final DateTimeZone LONDON = DateTimeZone
045: .forID("Europe/London");
046: private static final Chronology COPTIC_PARIS = CopticChronology
047: .getInstance(PARIS);
048:
049: long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
050: + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365
051: + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
052: + 365 + 365 + 366 + 365;
053: long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
054: + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365
055: + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
056: + 365 + 365 + 366 + 365 + 365;
057:
058: // 2002-06-09
059: private long TEST_TIME_NOW = (y2002days + 31L + 28L + 31L + 30L
060: + 31L + 9L - 1L)
061: * DateTimeConstants.MILLIS_PER_DAY;
062:
063: // 2002-04-05
064: private long TEST_TIME1 = (y2002days + 31L + 28L + 31L + 5L - 1L)
065: * DateTimeConstants.MILLIS_PER_DAY + 12L
066: * DateTimeConstants.MILLIS_PER_HOUR + 24L
067: * DateTimeConstants.MILLIS_PER_MINUTE;
068:
069: // 2003-05-06
070: private long TEST_TIME2 = (y2003days + 31L + 28L + 31L + 30L + 6L - 1L)
071: * DateTimeConstants.MILLIS_PER_DAY
072: + 14L
073: * DateTimeConstants.MILLIS_PER_HOUR
074: + 28L
075: * DateTimeConstants.MILLIS_PER_MINUTE;
076:
077: private DateTimeZone originalDateTimeZone = null;
078: private TimeZone originalTimeZone = null;
079: private Locale originalLocale = null;
080:
081: public static void main(String[] args) {
082: junit.textui.TestRunner.run(suite());
083: }
084:
085: public static TestSuite suite() {
086: return new TestSuite(TestMutableInterval_Basics.class);
087: }
088:
089: public TestMutableInterval_Basics(String name) {
090: super (name);
091: }
092:
093: protected void setUp() throws Exception {
094: DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
095: originalDateTimeZone = DateTimeZone.getDefault();
096: originalTimeZone = TimeZone.getDefault();
097: originalLocale = Locale.getDefault();
098: DateTimeZone.setDefault(LONDON);
099: TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
100: Locale.setDefault(Locale.UK);
101: }
102:
103: protected void tearDown() throws Exception {
104: DateTimeUtils.setCurrentMillisSystem();
105: DateTimeZone.setDefault(originalDateTimeZone);
106: TimeZone.setDefault(originalTimeZone);
107: Locale.setDefault(originalLocale);
108: originalDateTimeZone = null;
109: originalTimeZone = null;
110: originalLocale = null;
111: }
112:
113: //-----------------------------------------------------------------------
114: public void testTest() {
115: assertEquals("2002-06-09T00:00:00.000Z", new Instant(
116: TEST_TIME_NOW).toString());
117: assertEquals("2002-04-05T12:24:00.000Z",
118: new Instant(TEST_TIME1).toString());
119: assertEquals("2003-05-06T14:28:00.000Z",
120: new Instant(TEST_TIME2).toString());
121: }
122:
123: //-----------------------------------------------------------------------
124: public void testGetMillis() {
125: MutableInterval test = new MutableInterval(TEST_TIME1,
126: TEST_TIME2);
127: assertEquals(TEST_TIME1, test.getStartMillis());
128: assertEquals(TEST_TIME1, test.getStart().getMillis());
129: assertEquals(TEST_TIME2, test.getEndMillis());
130: assertEquals(TEST_TIME2, test.getEnd().getMillis());
131: assertEquals(TEST_TIME2 - TEST_TIME1, test.toDurationMillis());
132: assertEquals(TEST_TIME2 - TEST_TIME1, test.toDuration()
133: .getMillis());
134: }
135:
136: public void testGetDuration1() {
137: MutableInterval test = new MutableInterval(TEST_TIME1,
138: TEST_TIME2);
139: assertEquals(TEST_TIME2 - TEST_TIME1, test.toDurationMillis());
140: assertEquals(TEST_TIME2 - TEST_TIME1, test.toDuration()
141: .getMillis());
142: }
143:
144: public void testGetDuration2() {
145: MutableInterval test = new MutableInterval(TEST_TIME1,
146: TEST_TIME1);
147: assertSame(Duration.ZERO, test.toDuration());
148: }
149:
150: public void testEqualsHashCode() {
151: MutableInterval test1 = new MutableInterval(TEST_TIME1,
152: TEST_TIME2);
153: MutableInterval test2 = new MutableInterval(TEST_TIME1,
154: TEST_TIME2);
155: assertEquals(true, test1.equals(test2));
156: assertEquals(true, test2.equals(test1));
157: assertEquals(true, test1.equals(test1));
158: assertEquals(true, test2.equals(test2));
159: assertEquals(true, test1.hashCode() == test2.hashCode());
160: assertEquals(true, test1.hashCode() == test1.hashCode());
161: assertEquals(true, test2.hashCode() == test2.hashCode());
162:
163: MutableInterval test3 = new MutableInterval(TEST_TIME_NOW,
164: TEST_TIME2);
165: assertEquals(false, test1.equals(test3));
166: assertEquals(false, test2.equals(test3));
167: assertEquals(false, test3.equals(test1));
168: assertEquals(false, test3.equals(test2));
169: assertEquals(false, test1.hashCode() == test3.hashCode());
170: assertEquals(false, test2.hashCode() == test3.hashCode());
171:
172: MutableInterval test4 = new MutableInterval(TEST_TIME1,
173: TEST_TIME2, GJChronology.getInstance());
174: assertEquals(true, test4.equals(test4));
175: assertEquals(false, test1.equals(test4));
176: assertEquals(false, test2.equals(test4));
177: assertEquals(false, test4.equals(test1));
178: assertEquals(false, test4.equals(test2));
179: assertEquals(false, test1.hashCode() == test4.hashCode());
180: assertEquals(false, test2.hashCode() == test4.hashCode());
181:
182: MutableInterval test5 = new MutableInterval(TEST_TIME1,
183: TEST_TIME2);
184: assertEquals(true, test1.equals(test5));
185: assertEquals(true, test2.equals(test5));
186: assertEquals(false, test3.equals(test5));
187: assertEquals(true, test5.equals(test1));
188: assertEquals(true, test5.equals(test2));
189: assertEquals(false, test5.equals(test3));
190: assertEquals(true, test1.hashCode() == test5.hashCode());
191: assertEquals(true, test2.hashCode() == test5.hashCode());
192: assertEquals(false, test3.hashCode() == test5.hashCode());
193:
194: assertEquals(false, test1.equals("Hello"));
195: assertEquals(true, test1.equals(new MockInterval()));
196: assertEquals(false, test1.equals(new DateTime(TEST_TIME1)));
197: }
198:
199: class MockInterval extends AbstractInterval {
200: public MockInterval() {
201: super ();
202: }
203:
204: public Chronology getChronology() {
205: return ISOChronology.getInstance();
206: }
207:
208: public long getStartMillis() {
209: return TEST_TIME1;
210: }
211:
212: public long getEndMillis() {
213: return TEST_TIME2;
214: }
215: }
216:
217: //-----------------------------------------------------------------------
218: public void testContains_long() {
219: MutableInterval test = new MutableInterval(TEST_TIME1,
220: TEST_TIME2);
221: assertEquals(true, test.contains(TEST_TIME1));
222: assertEquals(false, test.contains(TEST_TIME1 - 1));
223: assertEquals(true, test.contains(TEST_TIME1
224: + (TEST_TIME2 - TEST_TIME1) / 2));
225: assertEquals(false, test.contains(TEST_TIME2));
226: assertEquals(true, test.contains(TEST_TIME2 - 1));
227: }
228:
229: public void testContainsNow() {
230: MutableInterval test = new MutableInterval(TEST_TIME1,
231: TEST_TIME2);
232:
233: DateTimeUtils.setCurrentMillisFixed(TEST_TIME1);
234: assertEquals(true, test.containsNow());
235: DateTimeUtils.setCurrentMillisFixed(TEST_TIME1 - 1);
236: assertEquals(false, test.containsNow());
237: DateTimeUtils.setCurrentMillisFixed(TEST_TIME1
238: + (TEST_TIME2 - TEST_TIME1) / 2);
239: assertEquals(true, test.containsNow());
240: DateTimeUtils.setCurrentMillisFixed(TEST_TIME2);
241: assertEquals(false, test.containsNow());
242: DateTimeUtils.setCurrentMillisFixed(TEST_TIME2 - 1);
243: assertEquals(true, test.containsNow());
244: }
245:
246: public void testContains_RI() {
247: MutableInterval test = new MutableInterval(TEST_TIME1,
248: TEST_TIME2);
249: assertEquals(true, test.contains(new Instant(TEST_TIME1)));
250: assertEquals(false, test.contains(new Instant(TEST_TIME1 - 1)));
251: assertEquals(true, test.contains(new Instant(TEST_TIME1
252: + (TEST_TIME2 - TEST_TIME1) / 2)));
253: assertEquals(false, test.contains(new Instant(TEST_TIME2)));
254: assertEquals(true, test.contains(new Instant(TEST_TIME2 - 1)));
255: assertEquals(true, test.contains((ReadableInstant) null));
256: }
257:
258: //-----------------------------------------------------------------------
259: public void testContains_RInterval() {
260: MutableInterval test = new MutableInterval(TEST_TIME1,
261: TEST_TIME2);
262:
263: assertEquals(true, test.contains(new Interval(TEST_TIME1,
264: TEST_TIME1)));
265: assertEquals(false, test.contains(new Interval(TEST_TIME1 - 1,
266: TEST_TIME1)));
267:
268: assertEquals(true, test.contains(new Interval(TEST_TIME1,
269: TEST_TIME1 + 1)));
270: assertEquals(false, test.contains(new Interval(TEST_TIME1 - 1,
271: TEST_TIME1 + 1)));
272: assertEquals(true, test.contains(new Interval(TEST_TIME1 + 1,
273: TEST_TIME1 + 1)));
274:
275: assertEquals(true, test.contains(new Interval(TEST_TIME1,
276: TEST_TIME2)));
277: assertEquals(false, test.contains(new Interval(TEST_TIME1 - 1,
278: TEST_TIME2)));
279: assertEquals(true, test.contains(new Interval(TEST_TIME1
280: + (TEST_TIME2 - TEST_TIME1) / 2, TEST_TIME2)));
281: assertEquals(false, test.contains(new Interval(TEST_TIME2,
282: TEST_TIME2)));
283: assertEquals(true, test.contains(new Interval(TEST_TIME2 - 1,
284: TEST_TIME2)));
285:
286: assertEquals(true, test.contains(new Interval(TEST_TIME1,
287: TEST_TIME2 - 1)));
288: assertEquals(false, test.contains(new Interval(TEST_TIME1 - 1,
289: TEST_TIME2 - 1)));
290: assertEquals(true, test.contains(new Interval(TEST_TIME1
291: + (TEST_TIME2 - TEST_TIME1) / 2, TEST_TIME2 - 1)));
292: assertEquals(true, test.contains(new Interval(TEST_TIME2 - 1,
293: TEST_TIME2 - 1)));
294: assertEquals(true, test.contains(new Interval(TEST_TIME2 - 2,
295: TEST_TIME2 - 1)));
296:
297: assertEquals(false, test.contains(new Interval(TEST_TIME1,
298: TEST_TIME2 + 1)));
299: assertEquals(false, test.contains(new Interval(TEST_TIME1 - 1,
300: TEST_TIME2 + 1)));
301: assertEquals(false, test.contains(new Interval(TEST_TIME1
302: + (TEST_TIME2 - TEST_TIME1) / 2, TEST_TIME2 + 1)));
303: assertEquals(false, test.contains(new Interval(TEST_TIME2,
304: TEST_TIME2 + 1)));
305: assertEquals(false, test.contains(new Interval(TEST_TIME2 - 1,
306: TEST_TIME2 + 1)));
307: assertEquals(false, test.contains(new Interval(TEST_TIME1 - 2,
308: TEST_TIME1 - 1)));
309:
310: assertEquals(true, test.contains((ReadableInterval) null));
311: }
312:
313: public void testOverlaps_RInterval() {
314: MutableInterval test = new MutableInterval(TEST_TIME1,
315: TEST_TIME2);
316:
317: assertEquals(false, test.overlaps(new Interval(TEST_TIME1,
318: TEST_TIME1)));
319: assertEquals(false, test.overlaps(new Interval(TEST_TIME1 - 1,
320: TEST_TIME1)));
321:
322: assertEquals(true, test.overlaps(new Interval(TEST_TIME1,
323: TEST_TIME1 + 1)));
324: assertEquals(true, test.overlaps(new Interval(TEST_TIME1 - 1,
325: TEST_TIME1 + 1)));
326: assertEquals(true, test.overlaps(new Interval(TEST_TIME1 + 1,
327: TEST_TIME1 + 1)));
328:
329: assertEquals(true, test.overlaps(new Interval(TEST_TIME1,
330: TEST_TIME2)));
331: assertEquals(true, test.overlaps(new Interval(TEST_TIME1 - 1,
332: TEST_TIME2)));
333: assertEquals(true, test.overlaps(new Interval(TEST_TIME1
334: + (TEST_TIME2 - TEST_TIME1) / 2, TEST_TIME2)));
335: assertEquals(false, test.overlaps(new Interval(TEST_TIME2,
336: TEST_TIME2)));
337: assertEquals(true, test.overlaps(new Interval(TEST_TIME2 - 1,
338: TEST_TIME2)));
339:
340: assertEquals(true, test.overlaps(new Interval(TEST_TIME1,
341: TEST_TIME2 + 1)));
342: assertEquals(true, test.overlaps(new Interval(TEST_TIME1 - 1,
343: TEST_TIME2 + 1)));
344: assertEquals(true, test.overlaps(new Interval(TEST_TIME1
345: + (TEST_TIME2 - TEST_TIME1) / 2, TEST_TIME2 + 1)));
346: assertEquals(false, test.overlaps(new Interval(TEST_TIME2,
347: TEST_TIME2 + 1)));
348: assertEquals(true, test.overlaps(new Interval(TEST_TIME2 - 1,
349: TEST_TIME2 + 1)));
350:
351: assertEquals(false, test.overlaps(new Interval(TEST_TIME1 - 1,
352: TEST_TIME1 - 1)));
353: assertEquals(false, test.overlaps(new Interval(TEST_TIME1 - 1,
354: TEST_TIME1)));
355: assertEquals(true, test.overlaps(new Interval(TEST_TIME1 - 1,
356: TEST_TIME1 + 1)));
357:
358: assertEquals(true, test.overlaps((ReadableInterval) null));
359:
360: MutableInterval empty = new MutableInterval(TEST_TIME1,
361: TEST_TIME1);
362: assertEquals(false, empty.overlaps(empty));
363: assertEquals(false, empty.overlaps(test));
364: assertEquals(false, test.overlaps(empty));
365: }
366:
367: //-----------------------------------------------------------------------
368: public void testIsBefore_long() {
369: MutableInterval test = new MutableInterval(TEST_TIME1,
370: TEST_TIME2);
371:
372: assertEquals(false, test.isBefore(TEST_TIME1 - 1));
373: assertEquals(false, test.isBefore(TEST_TIME1));
374: assertEquals(false, test.isBefore(TEST_TIME1 + 1));
375:
376: assertEquals(false, test.isBefore(TEST_TIME2 - 1));
377: assertEquals(true, test.isBefore(TEST_TIME2));
378: assertEquals(true, test.isBefore(TEST_TIME2 + 1));
379: }
380:
381: public void testIsBeforeNow() {
382: MutableInterval test = new MutableInterval(TEST_TIME1,
383: TEST_TIME2);
384:
385: DateTimeUtils.setCurrentMillisFixed(TEST_TIME2 - 1);
386: assertEquals(false, test.isBeforeNow());
387: DateTimeUtils.setCurrentMillisFixed(TEST_TIME2);
388: assertEquals(true, test.isBeforeNow());
389: DateTimeUtils.setCurrentMillisFixed(TEST_TIME2 + 1);
390: assertEquals(true, test.isBeforeNow());
391: }
392:
393: public void testIsBefore_RI() {
394: MutableInterval test = new MutableInterval(TEST_TIME1,
395: TEST_TIME2);
396:
397: assertEquals(false, test.isBefore(new Instant(TEST_TIME1 - 1)));
398: assertEquals(false, test.isBefore(new Instant(TEST_TIME1)));
399: assertEquals(false, test.isBefore(new Instant(TEST_TIME1 + 1)));
400:
401: assertEquals(false, test.isBefore(new Instant(TEST_TIME2 - 1)));
402: assertEquals(true, test.isBefore(new Instant(TEST_TIME2)));
403: assertEquals(true, test.isBefore(new Instant(TEST_TIME2 + 1)));
404:
405: assertEquals(false, test.isBefore((ReadableInstant) null));
406: }
407:
408: public void testIsBefore_RInterval() {
409: MutableInterval test = new MutableInterval(TEST_TIME1,
410: TEST_TIME2);
411:
412: assertEquals(false, test.isBefore(new Interval(Long.MIN_VALUE,
413: TEST_TIME1 - 1)));
414: assertEquals(false, test.isBefore(new Interval(Long.MIN_VALUE,
415: TEST_TIME1)));
416: assertEquals(false, test.isBefore(new Interval(Long.MIN_VALUE,
417: TEST_TIME1 + 1)));
418:
419: assertEquals(false, test.isBefore(new Interval(TEST_TIME2 - 1,
420: Long.MAX_VALUE)));
421: assertEquals(true, test.isBefore(new Interval(TEST_TIME2,
422: Long.MAX_VALUE)));
423: assertEquals(true, test.isBefore(new Interval(TEST_TIME2 + 1,
424: Long.MAX_VALUE)));
425:
426: assertEquals(false, test.isBefore((ReadableInterval) null));
427: }
428:
429: //-----------------------------------------------------------------------
430: public void testIsAfter_long() {
431: MutableInterval test = new MutableInterval(TEST_TIME1,
432: TEST_TIME2);
433:
434: assertEquals(true, test.isAfter(TEST_TIME1 - 1));
435: assertEquals(false, test.isAfter(TEST_TIME1));
436: assertEquals(false, test.isAfter(TEST_TIME1 + 1));
437:
438: assertEquals(false, test.isAfter(TEST_TIME2 - 1));
439: assertEquals(false, test.isAfter(TEST_TIME2));
440: assertEquals(false, test.isAfter(TEST_TIME2 + 1));
441: }
442:
443: public void testIsAfterNow() {
444: MutableInterval test = new MutableInterval(TEST_TIME1,
445: TEST_TIME2);
446:
447: DateTimeUtils.setCurrentMillisFixed(TEST_TIME1 - 1);
448: assertEquals(true, test.isAfterNow());
449: DateTimeUtils.setCurrentMillisFixed(TEST_TIME1);
450: assertEquals(false, test.isAfterNow());
451: DateTimeUtils.setCurrentMillisFixed(TEST_TIME1 + 1);
452: assertEquals(false, test.isAfterNow());
453: }
454:
455: public void testIsAfter_RI() {
456: MutableInterval test = new MutableInterval(TEST_TIME1,
457: TEST_TIME2);
458:
459: assertEquals(true, test.isAfter(new Instant(TEST_TIME1 - 1)));
460: assertEquals(false, test.isAfter(new Instant(TEST_TIME1)));
461: assertEquals(false, test.isAfter(new Instant(TEST_TIME1 + 1)));
462:
463: assertEquals(false, test.isAfter(new Instant(TEST_TIME2 - 1)));
464: assertEquals(false, test.isAfter(new Instant(TEST_TIME2)));
465: assertEquals(false, test.isAfter(new Instant(TEST_TIME2 + 1)));
466:
467: assertEquals(false, test.isAfter((ReadableInstant) null));
468: }
469:
470: public void testIsAfter_RInterval() {
471: MutableInterval test = new MutableInterval(TEST_TIME1,
472: TEST_TIME2);
473:
474: assertEquals(true, test.isAfter(new Interval(Long.MIN_VALUE,
475: TEST_TIME1 - 1)));
476: assertEquals(true, test.isAfter(new Interval(Long.MIN_VALUE,
477: TEST_TIME1)));
478: assertEquals(false, test.isAfter(new Interval(Long.MIN_VALUE,
479: TEST_TIME1 + 1)));
480:
481: assertEquals(false, test.isAfter(new Interval(TEST_TIME2 - 1,
482: Long.MAX_VALUE)));
483: assertEquals(false, test.isAfter(new Interval(TEST_TIME2,
484: Long.MAX_VALUE)));
485: assertEquals(false, test.isAfter(new Interval(TEST_TIME2 + 1,
486: Long.MAX_VALUE)));
487:
488: assertEquals(false, test.isAfter((ReadableInterval) null));
489: }
490:
491: //-----------------------------------------------------------------------
492: public void testToInterval1() {
493: MutableInterval test = new MutableInterval(TEST_TIME1,
494: TEST_TIME2, COPTIC_PARIS);
495: Interval result = test.toInterval();
496: assertEquals(test, result);
497: }
498:
499: //-----------------------------------------------------------------------
500: public void testToMutableInterval1() {
501: MutableInterval test = new MutableInterval(TEST_TIME1,
502: TEST_TIME2, COPTIC_PARIS);
503: MutableInterval result = test.toMutableInterval();
504: assertEquals(test, result);
505: assertNotSame(test, result);
506: }
507:
508: //-----------------------------------------------------------------------
509: public void testToPeriod() {
510: DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10,
511: COPTIC_PARIS);
512: DateTime dt2 = new DateTime(2005, 8, 13, 12, 14, 16, 18,
513: COPTIC_PARIS);
514: MutableInterval base = new MutableInterval(dt1, dt2);
515:
516: Period test = base.toPeriod();
517: Period expected = new Period(dt1, dt2, PeriodType.standard());
518: assertEquals(expected, test);
519: }
520:
521: //-----------------------------------------------------------------------
522: public void testToPeriod_PeriodType1() {
523: DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10,
524: COPTIC_PARIS);
525: DateTime dt2 = new DateTime(2005, 8, 13, 12, 14, 16, 18,
526: COPTIC_PARIS);
527: MutableInterval base = new MutableInterval(dt1, dt2);
528:
529: Period test = base.toPeriod(null);
530: Period expected = new Period(dt1, dt2, PeriodType.standard());
531: assertEquals(expected, test);
532: }
533:
534: public void testToPeriod_PeriodType2() {
535: DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10);
536: DateTime dt2 = new DateTime(2005, 8, 13, 12, 14, 16, 18);
537: MutableInterval base = new MutableInterval(dt1, dt2);
538:
539: Period test = base.toPeriod(PeriodType.yearWeekDayTime());
540: Period expected = new Period(dt1, dt2, PeriodType
541: .yearWeekDayTime());
542: assertEquals(expected, test);
543: }
544:
545: //-----------------------------------------------------------------------
546: public void testSerialization() throws Exception {
547: MutableInterval test = new MutableInterval(TEST_TIME1,
548: TEST_TIME2);
549:
550: ByteArrayOutputStream baos = new ByteArrayOutputStream();
551: ObjectOutputStream oos = new ObjectOutputStream(baos);
552: oos.writeObject(test);
553: byte[] bytes = baos.toByteArray();
554: oos.close();
555:
556: ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
557: ObjectInputStream ois = new ObjectInputStream(bais);
558: MutableInterval result = (MutableInterval) ois.readObject();
559: ois.close();
560:
561: assertEquals(test, result);
562: }
563:
564: //-----------------------------------------------------------------------
565: public void testToString() {
566: DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10,
567: DateTimeZone.UTC);
568: DateTime dt2 = new DateTime(2005, 8, 13, 12, 14, 16, 18,
569: DateTimeZone.UTC);
570: MutableInterval test = new MutableInterval(dt1, dt2);
571: assertEquals("2004-06-09T07:08:09.010/2005-08-13T12:14:16.018",
572: test.toString());
573: }
574:
575: //-----------------------------------------------------------------------
576: public void testCopy() {
577: MutableInterval test = new MutableInterval(123L, 456L,
578: COPTIC_PARIS);
579: MutableInterval cloned = test.copy();
580: assertEquals(test, cloned);
581: assertNotSame(test, cloned);
582: }
583:
584: public void testClone() {
585: MutableInterval test = new MutableInterval(123L, 456L,
586: COPTIC_PARIS);
587: MutableInterval cloned = (MutableInterval) test.clone();
588: assertEquals(test, cloned);
589: assertNotSame(test, cloned);
590: }
591:
592: }
|