/*
* Copyright 2001-2015 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time;
import java.util.Locale;
import java.util.TimeZone;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.joda.time.chrono.BuddhistChronology;
import org.joda.time.chrono.CopticChronology;
import org.joda.time.chrono.GJChronology;
import org.joda.time.chrono.ISOChronology;
import org.joda.time.convert.ConverterManager;
import org.joda.time.convert.IntervalConverter;
/**
* This class is a JUnit test for Interval.
*
* @author Stephen Colebourne
*/
public class TestInterval_Constructors extends TestCase {
// Test in 2002/03 as time zones are more well known
// (before the late 90's they were all over the place)
private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
private static final DateTimeZone OFFSET_04_00 = DateTimeZone.forOffsetHours(4);
long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 +
365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
366 + 365;
long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 +
365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
366 + 365 + 365;
// 2002-06-09
private long TEST_TIME_NOW =
(y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
// // 2002-04-05
// private long TEST_TIME1 =
// (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY
// + 12L * DateTimeConstants.MILLIS_PER_HOUR
// + 24L * DateTimeConstants.MILLIS_PER_MINUTE;
//
// // 2003-05-06
// private long TEST_TIME2 =
// (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
// + 14L * DateTimeConstants.MILLIS_PER_HOUR
// + 28L * DateTimeConstants.MILLIS_PER_MINUTE;
private DateTimeZone originalDateTimeZone = null;
private TimeZone originalTimeZone = null;
private Locale originalLocale = null;
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
public static TestSuite suite() {
return new TestSuite(TestInterval_Constructors.class);
}
public TestInterval_Constructors(String name) {
super(name);
}
protected void setUp() throws Exception {
DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
originalDateTimeZone = DateTimeZone.getDefault();
originalTimeZone = TimeZone.getDefault();
originalLocale = Locale.getDefault();
DateTimeZone.setDefault(PARIS);
TimeZone.setDefault(PARIS.toTimeZone());
Locale.setDefault(Locale.FRANCE);
}
protected void tearDown() throws Exception {
DateTimeUtils.setCurrentMillisSystem();
DateTimeZone.setDefault(originalDateTimeZone);
TimeZone.setDefault(originalTimeZone);
Locale.setDefault(originalLocale);
originalDateTimeZone = null;
originalTimeZone = null;
originalLocale = null;
}
//-----------------------------------------------------------------------
public void testParse_noOffsetInString() throws Throwable {
DateTime start = new DateTime(2010, 6, 30, 12, 30, ISOChronology.getInstance(PARIS));
DateTime end = new DateTime(2010, 7, 1, 14, 30, ISOChronology.getInstance(PARIS));
assertEquals(new Interval(start, end), Interval.parse("2010-06-30T12:30/2010-07-01T14:30"));
assertEquals(new Interval(start, end), Interval.parse("2010-06-30T12:30/P1DT2H"));
assertEquals(new Interval(start, end), Interval.parse("P1DT2H/2010-07-01T14:30"));
}
public void testParse_offsetInString() throws Throwable {
DateTime start = new DateTime(2010, 6, 30, 10, 30, ISOChronology.getInstance(PARIS));
DateTime end = new DateTime(2010, 7, 1, 12, 30, ISOChronology.getInstance(PARIS));
assertEquals(new Interval(start, end), Interval.parse("2010-06-30T12:30+04:00/2010-07-01T14:30+04:00"));
assertEquals(new Interval(start, end), Interval.parse("2010-06-30T12:30+04:00/P1DT2H"));
assertEquals(new Interval(start, end), Interval.parse("P1DT2H/2010-07-01T14:30+04:00"));
}
public void testParseWithOffset_noOffsetInString() throws Throwable {
DateTime start = new DateTime(2010, 6, 30, 12, 30, ISOChronology.getInstance(PARIS));
DateTime end = new DateTime(2010, 7, 1, 14, 30, ISOChronology.getInstance(PARIS));
assertEquals(new Interval(start, end), Interval.parseWithOffset("2010-06-30T12:30/2010-07-01T14:30"));
assertEquals(new Interval(start, end), Interval.parseWithOffset("2010-06-30T12:30/P1DT2H"));
assertEquals(new Interval(start, end), Interval.parseWithOffset("P1DT2H/2010-07-01T14:30"));
}
public void testParseWithOffset_offsetInString() throws Throwable {
DateTime start = new DateTime(2010, 6, 30, 12, 30, ISOChronology.getInstance(OFFSET_04_00));
DateTime end = new DateTime(2010, 7, 1, 14, 30, ISOChronology.getInstance(OFFSET_04_00));
assertEquals(new Interval(start, end), Interval.parseWithOffset("2010-06-30T12:30+04:00/2010-07-01T14:30+04:00"));
assertEquals(new Interval(start, end), Interval.parseWithOffset("2010-06-30T12:30+04:00/p1DT2H"));
assertEquals(new Interval(start, end), Interval.parseWithOffset("p1DT2H/2010-07-01T14:30+04:00"));
}
public void testParseWithOffset_invalid() throws Throwable {
try {
Interval.parseWithOffset("2010-06-30T12:30");
fail();
} catch (IllegalArgumentException ex) {
// expected
}
try {
Interval.parseWithOffset("P1D/P1D");
fail();
} catch (IllegalArgumentException ex) {
// expected
}
}
//-----------------------------------------------------------------------
public void testConstructor_long_long1() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval test = new Interval(dt1.getMillis(), dt2.getMillis());
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(ISOChronology.getInstance(), test.getChronology());
}
public void testConstructor_long_long2() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
Interval test = new Interval(dt1.getMillis(), dt1.getMillis());
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt1.getMillis(), test.getEndMillis());
assertEquals(ISOChronology.getInstance(), test.getChronology());
}
public void testConstructor_long_long3() throws Throwable {
DateTime dt1 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
DateTime dt2 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
try {
new Interval(dt1.getMillis(), dt2.getMillis());
fail();
} catch (IllegalArgumentException ex) {}
}
public void testConstructor_long_long_minMax() throws Throwable {
Interval test = new Interval(Long.MIN_VALUE, Long.MAX_VALUE);
assertEquals(Long.MIN_VALUE, test.getStartMillis());
assertEquals(Long.MAX_VALUE, test.getEndMillis());
assertEquals(new DateTime(Long.MIN_VALUE), test.getStart());
assertEquals(new DateTime(Long.MAX_VALUE), test.getEnd());
assertEquals(ISOChronology.getInstance(), test.getChronology());
assertEquals(test, test.toInterval());
assertEquals("-292275055-05-16T16:56:25.192+00:09:21/292278994-08-17T07:12:55.807Z", test.toString());
try {
test.toDuration();
fail();
} catch (ArithmeticException ex) {}
try {
test.toDurationMillis();
fail();
} catch (ArithmeticException ex) {}
try {
test.toPeriod();
fail();
} catch (RuntimeException ex) {}
}
public void testConstructor_long_long_min() throws Throwable {
Interval test = new Interval(Long.MIN_VALUE, Long.MIN_VALUE + 9);
assertEquals(Long.MIN_VALUE, test.getStartMillis());
assertEquals(Long.MIN_VALUE + 9, test.getEndMillis());
assertEquals(new DateTime(Long.MIN_VALUE), test.getStart());
assertEquals(new DateTime(Long.MIN_VALUE + 9), test.getEnd());
assertEquals(ISOChronology.getInstance(), test.getChronology());
assertEquals(test, test.toInterval());
assertEquals("-292275055-05-16T16:56:25.192+00:09:21/-292275055-05-16T16:56:25.201+00:09:21", test.toString());
assertEquals(9, test.toDurationMillis());
assertEquals(new Duration(9), test.toDuration());
assertEquals(new Period(9), test.toPeriod());
}
public void testConstructor_long_long_max() throws Throwable {
Interval test = new Interval(Long.MAX_VALUE - 9, Long.MAX_VALUE);
assertEquals(Long.MAX_VALUE - 9, test.getStartMillis());
assertEquals(Long.MAX_VALUE, test.getEndMillis());
assertEquals(new DateTime(Long.MAX_VALUE - 9), test.getStart());
assertEquals(new DateTime(Long.MAX_VALUE), test.getEnd());
assertEquals(ISOChronology.getInstance(), test.getChronology());
assertEquals(test, test.toInterval());
assertEquals("292278994-08-17T07:12:55.798Z/292278994-08-17T07:12:55.807Z", test.toString());
assertEquals(9, test.toDurationMillis());
assertEquals(new Duration(9), test.toDuration());
}
//-----------------------------------------------------------------------
public void testConstructor_long_long_Zone() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval test = new Interval(dt1.getMillis(), dt2.getMillis(), LONDON);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(ISOChronology.getInstance(LONDON), test.getChronology());
}
public void testConstructor_long_long_nullZone() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval test = new Interval(dt1.getMillis(), dt2.getMillis(), (DateTimeZone) null);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(ISOChronology.getInstance(), test.getChronology());
}
//-----------------------------------------------------------------------
public void testConstructor_long_long_Chronology() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval test = new Interval(dt1.getMillis(), dt2.getMillis(), GJChronology.getInstance());
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(GJChronology.getInstance(), test.getChronology());
}
public void testConstructor_long_long_nullChronology() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval test = new Interval(dt1.getMillis(), dt2.getMillis(), (Chronology) null);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(ISOChronology.getInstance(), test.getChronology());
}
//-----------------------------------------------------------------------
public void testConstructor_RI_RI1() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval test = new Interval(dt1, dt2);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
}
public void testConstructor_RI_RI2() throws Throwable {
Instant dt1 = new Instant(new DateTime(2004, 6, 9, 0, 0, 0, 0));
Instant dt2 = new Instant(new DateTime(2005, 7, 10, 1, 1, 1, 1));
Interval test = new Interval(dt1, dt2);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
}
public void testConstructor_RI_RI3() throws Throwable {
Interval test = new Interval((ReadableInstant) null, (ReadableInstant) null);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RI_RI4() throws Throwable {
DateTime dt1 = new DateTime(2000, 6, 9, 0, 0, 0, 0);
Interval test = new Interval(dt1, (ReadableInstant) null);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RI_RI5() throws Throwable {
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval test = new Interval((ReadableInstant) null, dt2);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
}
public void testConstructor_RI_RI6() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
Interval test = new Interval(dt1, dt1);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt1.getMillis(), test.getEndMillis());
}
public void testConstructor_RI_RI7() throws Throwable {
DateTime dt1 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
DateTime dt2 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
try {
new Interval(dt1, dt2);
fail();
} catch (IllegalArgumentException ex) {}
}
public void testConstructor_RI_RI_chronoStart() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0, GJChronology.getInstance());
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval test = new Interval(dt1, dt2);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(GJChronology.getInstance(), test.getChronology());
}
public void testConstructor_RI_RI_chronoEnd() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1, GJChronology.getInstance());
Interval test = new Interval(dt1, dt2);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(ISOChronology.getInstance(), test.getChronology());
}
public void testConstructor_RI_RI_zones() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0, LONDON);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1, PARIS);
Interval test = new Interval(dt1, dt2);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(ISOChronology.getInstance(LONDON), test.getChronology());
}
public void testConstructor_RI_RI_instant() throws Throwable {
Instant dt1 = new Instant(12345678L);
Instant dt2 = new Instant(22345678L);
Interval test = new Interval(dt1, dt2);
assertEquals(12345678L, test.getStartMillis());
assertEquals(22345678L, test.getEndMillis());
assertEquals(ISOChronology.getInstanceUTC(), test.getChronology());
}
//-----------------------------------------------------------------------
public void testConstructor_RI_RP1() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().months().add(result, 6);
result = ISOChronology.getInstance().hours().add(result, 1);
Interval test = new Interval(dt, dur);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(result, test.getEndMillis());
}
public void testConstructor_RI_RP2() throws Throwable {
Instant dt = new Instant(new DateTime(TEST_TIME_NOW));
Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstanceUTC().months().add(result, 6);
result = ISOChronology.getInstanceUTC().days().add(result, 3);
result = ISOChronology.getInstanceUTC().hours().add(result, 1);
Interval test = new Interval(dt, dur);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(result, test.getEndMillis());
}
public void testConstructor_RI_RP3() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW, CopticChronology.getInstanceUTC());
Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0, PeriodType.standard());
long result = TEST_TIME_NOW;
result = CopticChronology.getInstanceUTC().months().add(result, 6);
result = CopticChronology.getInstanceUTC().days().add(result, 3);
result = CopticChronology.getInstanceUTC().hours().add(result, 1);
Interval test = new Interval(dt, dur);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(result, test.getEndMillis());
}
public void testConstructor_RI_RP4() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Period dur = new Period(1 * DateTimeConstants.MILLIS_PER_HOUR + 23L);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().hours().add(result, 1);
result = ISOChronology.getInstance().millis().add(result, 23);
Interval test = new Interval(dt, dur);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(result, test.getEndMillis());
}
public void testConstructor_RI_RP5() throws Throwable {
Interval test = new Interval((ReadableInstant) null, (ReadablePeriod) null);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RI_RP6() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Interval test = new Interval(dt, (ReadablePeriod) null);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RI_RP7() throws Throwable {
Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().monthOfYear().add(result, 6);
result = ISOChronology.getInstance().hourOfDay().add(result, 1);
Interval test = new Interval((ReadableInstant) null, dur);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(result, test.getEndMillis());
}
public void testConstructor_RI_RP8() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Period dur = new Period(0, 0, 0, 0, 0, 0, 0, -1);
try {
new Interval(dt, dur);
fail();
} catch (IllegalArgumentException ex) {}
}
//-----------------------------------------------------------------------
public void testConstructor_RP_RI1() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().months().add(result, -6);
result = ISOChronology.getInstance().hours().add(result, -1);
Interval test = new Interval(dur, dt);
assertEquals(result, test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RP_RI2() throws Throwable {
Instant dt = new Instant(new DateTime(TEST_TIME_NOW));
Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstanceUTC().months().add(result, -6);
result = ISOChronology.getInstanceUTC().days().add(result, -3);
result = ISOChronology.getInstanceUTC().hours().add(result, -1);
Interval test = new Interval(dur, dt);
assertEquals(result, test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RP_RI3() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW, CopticChronology.getInstanceUTC());
Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0, PeriodType.standard());
long result = TEST_TIME_NOW;
result = CopticChronology.getInstanceUTC().months().add(result, -6);
result = CopticChronology.getInstanceUTC().days().add(result, -3);
result = CopticChronology.getInstanceUTC().hours().add(result, -1);
Interval test = new Interval(dur, dt);
assertEquals(result, test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RP_RI4() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Period dur = new Period(1 * DateTimeConstants.MILLIS_PER_HOUR + 23L);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().hours().add(result, -1);
result = ISOChronology.getInstance().millis().add(result, -23);
Interval test = new Interval(dur, dt);
assertEquals(result, test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RP_RI5() throws Throwable {
Interval test = new Interval((ReadablePeriod) null, (ReadableInstant) null);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RP_RI6() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Interval test = new Interval((ReadablePeriod) null, dt);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RP_RI7() throws Throwable {
Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().monthOfYear().add(result, -6);
result = ISOChronology.getInstance().hourOfDay().add(result, -1);
Interval test = new Interval(dur, (ReadableInstant) null);
assertEquals(result, test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RP_RI8() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Period dur = new Period(0, 0, 0, 0, 0, 0, 0, -1);
try {
new Interval(dur, dt);
fail();
} catch (IllegalArgumentException ex) {}
}
//-----------------------------------------------------------------------
public void testConstructor_RI_RD1() throws Throwable {
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().months().add(result, 6);
result = ISOChronology.getInstance().hours().add(result, 1);
DateTime dt = new DateTime(TEST_TIME_NOW);
Duration dur = new Duration(result - TEST_TIME_NOW);
Interval test = new Interval(dt, dur);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(result, test.getEndMillis());
}
public void testConstructor_RI_RD2() throws Throwable {
Interval test = new Interval((ReadableInstant) null, (ReadableDuration) null);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RI_RD3() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Interval test = new Interval(dt, (ReadableDuration) null);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RI_RD4() throws Throwable {
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().monthOfYear().add(result, 6);
result = ISOChronology.getInstance().hourOfDay().add(result, 1);
Duration dur = new Duration(result - TEST_TIME_NOW);
Interval test = new Interval((ReadableInstant) null, dur);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(result, test.getEndMillis());
}
public void testConstructor_RI_RD5() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Duration dur = new Duration(-1);
try {
new Interval(dt, dur);
fail();
} catch (IllegalArgumentException ex) {}
}
//-----------------------------------------------------------------------
public void testConstructor_RD_RI1() throws Throwable {
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().months().add(result, -6);
result = ISOChronology.getInstance().hours().add(result, -1);
DateTime dt = new DateTime(TEST_TIME_NOW);
Duration dur = new Duration(TEST_TIME_NOW - result);
Interval test = new Interval(dur, dt);
assertEquals(result, test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RD_RI2() throws Throwable {
Interval test = new Interval((ReadableDuration) null, (ReadableInstant) null);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RD_RI3() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Interval test = new Interval((ReadableDuration) null, dt);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RD_RI4() throws Throwable {
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().monthOfYear().add(result, -6);
result = ISOChronology.getInstance().hourOfDay().add(result, -1);
Duration dur = new Duration(TEST_TIME_NOW - result);
Interval test = new Interval(dur, (ReadableInstant) null);
assertEquals(result, test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RD_RI5() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Duration dur = new Duration(-1);
try {
new Interval(dur, dt);
fail();
} catch (IllegalArgumentException ex) {}
}
//-----------------------------------------------------------------------
public void testConstructor_Object1() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval test = new Interval(dt1.toString() + '/' + dt2.toString());
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
}
public void testConstructor_Object2() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval base = new Interval(dt1, dt2);
Interval test = new Interval(base);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
}
public void testConstructor_Object3() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
MutableInterval base = new MutableInterval(dt1, dt2);
Interval test = new Interval(base);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
}
public void testConstructor_Object4() throws Throwable {
MockInterval base = new MockInterval();
Interval test = new Interval(base);
assertEquals(base.getStartMillis(), test.getStartMillis());
assertEquals(base.getEndMillis(), test.getEndMillis());
}
public void testConstructor_Object5() throws Throwable {
IntervalConverter oldConv = ConverterManager.getInstance().getIntervalConverter("");
IntervalConverter conv = new IntervalConverter() {
public boolean isReadableInterval(Object object, Chronology chrono) {
return false;
}
public void setInto(ReadWritableInterval interval, Object object, Chronology chrono) {
interval.setChronology(chrono);
interval.setInterval(1234L, 5678L);
}
public Class<?> getSupportedType() {
return String.class;
}
};
try {
ConverterManager.getInstance().addIntervalConverter(conv);
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval test = new Interval(dt1.toString() + '/' + dt2.toString());
assertEquals(1234L, test.getStartMillis());
assertEquals(5678L, test.getEndMillis());
} finally {
ConverterManager.getInstance().addIntervalConverter(oldConv);
}
}
public void testConstructor_Object6() throws Throwable {
IntervalConverter oldConv = ConverterManager.getInstance().getIntervalConverter(new Interval(0L, 0L));
IntervalConverter conv = new IntervalConverter() {
public boolean isReadableInterval(Object object, Chronology chrono) {
return false;
}
public void setInto(ReadWritableInterval interval, Object object, Chronology chrono) {
interval.setChronology(chrono);
interval.setInterval(1234L, 5678L);
}
public Class<?> getSupportedType() {
return ReadableInterval.class;
}
};
try {
ConverterManager.getInstance().addIntervalConverter(conv);
Interval base = new Interval(-1000L, 1000L);
Interval test = new Interval(base);
assertEquals(1234L, test.getStartMillis());
assertEquals(5678L, test.getEndMillis());
} finally {
ConverterManager.getInstance().addIntervalConverter(oldConv);
}
}
class MockInterval implements ReadableInterval {
public Chronology getChronology() {
return ISOChronology.getInstance();
}
public long getStartMillis() {
return 1234L;
}
public DateTime getStart() {
return new DateTime(1234L);
}
public long getEndMillis() {
return 5678L;
}
public DateTime getEnd() {
return new DateTime(5678L);
}
public long toDurationMillis() {
return (5678L - 1234L);
}
public Duration toDuration() {
return new Duration(5678L - 1234L);
}
public boolean contains(long millisInstant) {
return false;
}
public boolean containsNow() {
return false;
}
public boolean contains(ReadableInstant instant) {
return false;
}
public boolean contains(ReadableInterval interval) {
return false;
}
public boolean overlaps(ReadableInterval interval) {
return false;
}
public boolean isBefore(ReadableInstant instant) {
return false;
}
public boolean isBefore(ReadableInterval interval) {
return false;
}
public boolean isAfter(ReadableInstant instant) {
return false;
}
public boolean isAfter(ReadableInterval interval) {
return false;
}
public Interval toInterval() {
return null;
}
public MutableInterval toMutableInterval() {
return null;
}
public Period toPeriod() {
return null;
}
public Period toPeriod(PeriodType type) {
return null;
}
}
//-----------------------------------------------------------------------
public void testConstructor_Object_Chronology1() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval base = new Interval(dt1, dt2);
Interval test = new Interval(base, BuddhistChronology.getInstance());
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(BuddhistChronology.getInstance(), test.getChronology());
}
public void testConstructor_Object_Chronology2() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval base = new Interval(dt1, dt2);
Interval test = new Interval(base, null);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(ISOChronology.getInstance(), test.getChronology());
}
}