Ejemplo n.º 1
0
 public void testSetInto_Object_Chronology2() throws Exception {
   MutableInterval m = new MutableInterval(1000L, 2000L, GJChronology.getInstance());
   NullConverter.INSTANCE.setInto(m, null, CopticChronology.getInstance());
   assertEquals(TEST_TIME_NOW, m.getStartMillis());
   assertEquals(TEST_TIME_NOW, m.getEndMillis());
   assertEquals(CopticChronology.getInstance(), m.getChronology());
 }
Ejemplo n.º 2
0
/**
 * This class is a Junit unit test for LocalTime.
 *
 * @author Stephen Colebourne
 */
public class TestLocalTime_Basics extends TestCase {

  private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
  private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
  private static final DateTimeZone TOKYO = DateTimeZone.forID("Asia/Tokyo");
  private static final Chronology COPTIC_PARIS = CopticChronology.getInstance(PARIS);
  private static final Chronology COPTIC_LONDON = CopticChronology.getInstance(LONDON);
  private static final Chronology COPTIC_TOKYO = CopticChronology.getInstance(TOKYO);
  private static final Chronology COPTIC_UTC = CopticChronology.getInstanceUTC();
  private static final Chronology BUDDHIST_LONDON = BuddhistChronology.getInstance(LONDON);

  private long TEST_TIME_NOW =
      10L * DateTimeConstants.MILLIS_PER_HOUR
          + 20L * DateTimeConstants.MILLIS_PER_MINUTE
          + 30L * DateTimeConstants.MILLIS_PER_SECOND
          + 40L;

  //    private long TEST_TIME1 =
  //        1L * DateTimeConstants.MILLIS_PER_HOUR
  //        + 2L * DateTimeConstants.MILLIS_PER_MINUTE
  //        + 3L * DateTimeConstants.MILLIS_PER_SECOND
  //        + 4L;

  private long TEST_TIME2 =
      1L * DateTimeConstants.MILLIS_PER_DAY
          + 5L * DateTimeConstants.MILLIS_PER_HOUR
          + 6L * DateTimeConstants.MILLIS_PER_MINUTE
          + 7L * DateTimeConstants.MILLIS_PER_SECOND
          + 8L;

  private DateTimeZone zone = null;

  public static void main(String[] args) {
    junit.textui.TestRunner.run(suite());
  }

  public static TestSuite suite() {
    return new TestSuite(TestLocalTime_Basics.class);
  }

  public TestLocalTime_Basics(String name) {
    super(name);
  }

  protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    zone = DateTimeZone.getDefault();
    DateTimeZone.setDefault(LONDON);
  }

  protected void tearDown() throws Exception {
    DateTimeUtils.setCurrentMillisSystem();
    DateTimeZone.setDefault(zone);
    zone = null;
  }

  // -----------------------------------------------------------------------
  public void testGet_DateTimeFieldType() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    assertEquals(10, test.get(DateTimeFieldType.hourOfDay()));
    assertEquals(20, test.get(DateTimeFieldType.minuteOfHour()));
    assertEquals(30, test.get(DateTimeFieldType.secondOfMinute()));
    assertEquals(40, test.get(DateTimeFieldType.millisOfSecond()));
    assertEquals(TEST_TIME_NOW / 60000, test.get(DateTimeFieldType.minuteOfDay()));
    assertEquals(TEST_TIME_NOW / 1000, test.get(DateTimeFieldType.secondOfDay()));
    assertEquals(TEST_TIME_NOW, test.get(DateTimeFieldType.millisOfDay()));
    assertEquals(10, test.get(DateTimeFieldType.hourOfHalfday()));
    assertEquals(DateTimeConstants.AM, test.get(DateTimeFieldType.halfdayOfDay()));
    test = new LocalTime(12, 30);
    assertEquals(0, test.get(DateTimeFieldType.hourOfHalfday()));
    assertEquals(12, test.get(DateTimeFieldType.clockhourOfHalfday()));
    assertEquals(12, test.get(DateTimeFieldType.clockhourOfDay()));
    assertEquals(DateTimeConstants.PM, test.get(DateTimeFieldType.halfdayOfDay()));
    test = new LocalTime(14, 30);
    assertEquals(2, test.get(DateTimeFieldType.hourOfHalfday()));
    assertEquals(2, test.get(DateTimeFieldType.clockhourOfHalfday()));
    assertEquals(14, test.get(DateTimeFieldType.clockhourOfDay()));
    assertEquals(DateTimeConstants.PM, test.get(DateTimeFieldType.halfdayOfDay()));
    test = new LocalTime(0, 30);
    assertEquals(0, test.get(DateTimeFieldType.hourOfHalfday()));
    assertEquals(12, test.get(DateTimeFieldType.clockhourOfHalfday()));
    assertEquals(24, test.get(DateTimeFieldType.clockhourOfDay()));
    assertEquals(DateTimeConstants.AM, test.get(DateTimeFieldType.halfdayOfDay()));
    try {
      test.get(null);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      test.get(DateTimeFieldType.dayOfMonth());
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testSize() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    assertEquals(4, test.size());
  }

  public void testGetFieldType_int() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    assertSame(DateTimeFieldType.hourOfDay(), test.getFieldType(0));
    assertSame(DateTimeFieldType.minuteOfHour(), test.getFieldType(1));
    assertSame(DateTimeFieldType.secondOfMinute(), test.getFieldType(2));
    assertSame(DateTimeFieldType.millisOfSecond(), test.getFieldType(3));
    try {
      test.getFieldType(-1);
    } catch (IndexOutOfBoundsException ex) {
    }
    try {
      test.getFieldType(5);
    } catch (IndexOutOfBoundsException ex) {
    }
  }

  public void testGetFieldTypes() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    DateTimeFieldType[] fields = test.getFieldTypes();
    assertSame(DateTimeFieldType.hourOfDay(), fields[0]);
    assertSame(DateTimeFieldType.minuteOfHour(), fields[1]);
    assertSame(DateTimeFieldType.secondOfMinute(), fields[2]);
    assertSame(DateTimeFieldType.millisOfSecond(), fields[3]);
    assertNotSame(test.getFieldTypes(), test.getFieldTypes());
  }

  public void testGetField_int() {
    LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_UTC);
    assertSame(COPTIC_UTC.hourOfDay(), test.getField(0));
    assertSame(COPTIC_UTC.minuteOfHour(), test.getField(1));
    assertSame(COPTIC_UTC.secondOfMinute(), test.getField(2));
    assertSame(COPTIC_UTC.millisOfSecond(), test.getField(3));
    try {
      test.getField(-1);
    } catch (IndexOutOfBoundsException ex) {
    }
    try {
      test.getField(5);
    } catch (IndexOutOfBoundsException ex) {
    }
  }

  public void testGetFields() {
    LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_UTC);
    DateTimeField[] fields = test.getFields();
    assertSame(COPTIC_UTC.hourOfDay(), fields[0]);
    assertSame(COPTIC_UTC.minuteOfHour(), fields[1]);
    assertSame(COPTIC_UTC.secondOfMinute(), fields[2]);
    assertSame(COPTIC_UTC.millisOfSecond(), fields[3]);
    assertNotSame(test.getFields(), test.getFields());
  }

  public void testGetValue_int() {
    LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_PARIS);
    assertEquals(10, test.getValue(0));
    assertEquals(20, test.getValue(1));
    assertEquals(30, test.getValue(2));
    assertEquals(40, test.getValue(3));
    try {
      test.getValue(-1);
    } catch (IndexOutOfBoundsException ex) {
    }
    try {
      test.getValue(5);
    } catch (IndexOutOfBoundsException ex) {
    }
  }

  public void testGetValues() {
    LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_UTC);
    int[] values = test.getValues();
    assertEquals(10, values[0]);
    assertEquals(20, values[1]);
    assertEquals(30, values[2]);
    assertEquals(40, values[3]);
    assertNotSame(test.getValues(), test.getValues());
  }

  public void testIsSupported_DateTimeFieldType() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    assertEquals(true, test.isSupported(DateTimeFieldType.hourOfDay()));
    assertEquals(true, test.isSupported(DateTimeFieldType.minuteOfHour()));
    assertEquals(true, test.isSupported(DateTimeFieldType.secondOfMinute()));
    assertEquals(true, test.isSupported(DateTimeFieldType.millisOfSecond()));
    assertEquals(true, test.isSupported(DateTimeFieldType.minuteOfDay()));
    assertEquals(true, test.isSupported(DateTimeFieldType.secondOfDay()));
    assertEquals(true, test.isSupported(DateTimeFieldType.millisOfDay()));

    assertEquals(true, test.isSupported(DateTimeFieldType.hourOfHalfday()));
    assertEquals(true, test.isSupported(DateTimeFieldType.halfdayOfDay()));
    assertEquals(true, test.isSupported(DateTimeFieldType.clockhourOfHalfday()));
    assertEquals(true, test.isSupported(DateTimeFieldType.clockhourOfDay()));

    assertEquals(false, test.isSupported(DateTimeFieldType.dayOfMonth()));
    assertEquals(false, test.isSupported((DateTimeFieldType) null));

    DateTimeFieldType d =
        new DateTimeFieldType("hours") {
          private static final long serialVersionUID = 1L;

          public DurationFieldType getDurationType() {
            return DurationFieldType.hours();
          }

          public DurationFieldType getRangeDurationType() {
            return null;
          }

          public DateTimeField getField(Chronology chronology) {
            return chronology.hourOfDay();
          }
        };
    assertEquals(false, test.isSupported(d));

    d =
        new DateTimeFieldType("hourOfYear") {
          private static final long serialVersionUID = 1L;

          public DurationFieldType getDurationType() {
            return DurationFieldType.hours();
          }

          public DurationFieldType getRangeDurationType() {
            return DurationFieldType.years();
          }

          public DateTimeField getField(Chronology chronology) {
            return chronology.hourOfDay();
          }
        };
    assertEquals(false, test.isSupported(d));
  }

  public void testIsSupported_DurationFieldType() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    assertEquals(true, test.isSupported(DurationFieldType.hours()));
    assertEquals(true, test.isSupported(DurationFieldType.minutes()));
    assertEquals(true, test.isSupported(DurationFieldType.seconds()));
    assertEquals(true, test.isSupported(DurationFieldType.millis()));
    assertEquals(true, test.isSupported(DurationFieldType.halfdays()));

    assertEquals(false, test.isSupported(DurationFieldType.days()));
    assertEquals(false, test.isSupported((DurationFieldType) null));
  }

  @SuppressWarnings("deprecation")
  public void testEqualsHashCode() {
    LocalTime test1 = new LocalTime(10, 20, 30, 40, COPTIC_PARIS);
    LocalTime test2 = new LocalTime(10, 20, 30, 40, COPTIC_PARIS);
    assertEquals(true, test1.equals(test2));
    assertEquals(true, test2.equals(test1));
    assertEquals(true, test1.equals(test1));
    assertEquals(true, test2.equals(test2));
    assertEquals(true, test1.hashCode() == test2.hashCode());
    assertEquals(true, test1.hashCode() == test1.hashCode());
    assertEquals(true, test2.hashCode() == test2.hashCode());

    LocalTime test3 = new LocalTime(15, 20, 30, 40);
    assertEquals(false, test1.equals(test3));
    assertEquals(false, test2.equals(test3));
    assertEquals(false, test3.equals(test1));
    assertEquals(false, test3.equals(test2));
    assertEquals(false, test1.hashCode() == test3.hashCode());
    assertEquals(false, test2.hashCode() == test3.hashCode());

    assertEquals(false, test1.equals("Hello"));
    assertEquals(true, test1.equals(new TimeOfDay(10, 20, 30, 40, COPTIC_UTC)));
    assertEquals(true, test1.hashCode() == new TimeOfDay(10, 20, 30, 40, COPTIC_UTC).hashCode());
    assertEquals(true, test1.equals(new MockInstant()));
    assertEquals(false, test1.equals(MockPartial.EMPTY_INSTANCE));
  }

  class MockInstant extends MockPartial {
    public Chronology getChronology() {
      return COPTIC_UTC;
    }

    public DateTimeField[] getFields() {
      return new DateTimeField[] {
        COPTIC_UTC.hourOfDay(),
        COPTIC_UTC.minuteOfHour(),
        COPTIC_UTC.secondOfMinute(),
        COPTIC_UTC.millisOfSecond(),
      };
    }

    public int[] getValues() {
      return new int[] {10, 20, 30, 40};
    }
  }

  // -----------------------------------------------------------------------
  @SuppressWarnings("deprecation")
  public void testCompareTo() {
    LocalTime test1 = new LocalTime(10, 20, 30, 40);
    LocalTime test1a = new LocalTime(10, 20, 30, 40);
    assertEquals(0, test1.compareTo(test1a));
    assertEquals(0, test1a.compareTo(test1));
    assertEquals(0, test1.compareTo(test1));
    assertEquals(0, test1a.compareTo(test1a));

    LocalTime test2 = new LocalTime(10, 20, 35, 40);
    assertEquals(-1, test1.compareTo(test2));
    assertEquals(+1, test2.compareTo(test1));

    LocalTime test3 = new LocalTime(10, 20, 35, 40, GregorianChronology.getInstanceUTC());
    assertEquals(-1, test1.compareTo(test3));
    assertEquals(+1, test3.compareTo(test1));
    assertEquals(0, test3.compareTo(test2));

    DateTimeFieldType[] types =
        new DateTimeFieldType[] {
          DateTimeFieldType.hourOfDay(),
          DateTimeFieldType.minuteOfHour(),
          DateTimeFieldType.secondOfMinute(),
          DateTimeFieldType.millisOfSecond(),
        };
    int[] values = new int[] {10, 20, 30, 40};
    Partial p = new Partial(types, values);
    assertEquals(0, test1.compareTo(p));
    assertEquals(0, test1.compareTo(new TimeOfDay(10, 20, 30, 40)));
    try {
      test1.compareTo(null);
      fail();
    } catch (NullPointerException ex) {
    }
    //        try {
    //            test1.compareTo(new Date());
    //            fail();
    //        } catch (ClassCastException ex) {}
  }

  // -----------------------------------------------------------------------
  public void testIsEqual_LocalTime() {
    LocalTime test1 = new LocalTime(10, 20, 30, 40);
    LocalTime test1a = new LocalTime(10, 20, 30, 40);
    assertEquals(true, test1.isEqual(test1a));
    assertEquals(true, test1a.isEqual(test1));
    assertEquals(true, test1.isEqual(test1));
    assertEquals(true, test1a.isEqual(test1a));

    LocalTime test2 = new LocalTime(10, 20, 35, 40);
    assertEquals(false, test1.isEqual(test2));
    assertEquals(false, test2.isEqual(test1));

    LocalTime test3 = new LocalTime(10, 20, 35, 40, GregorianChronology.getInstanceUTC());
    assertEquals(false, test1.isEqual(test3));
    assertEquals(false, test3.isEqual(test1));
    assertEquals(true, test3.isEqual(test2));

    try {
      new LocalTime(10, 20, 35, 40).isEqual(null);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  // -----------------------------------------------------------------------
  public void testIsBefore_LocalTime() {
    LocalTime test1 = new LocalTime(10, 20, 30, 40);
    LocalTime test1a = new LocalTime(10, 20, 30, 40);
    assertEquals(false, test1.isBefore(test1a));
    assertEquals(false, test1a.isBefore(test1));
    assertEquals(false, test1.isBefore(test1));
    assertEquals(false, test1a.isBefore(test1a));

    LocalTime test2 = new LocalTime(10, 20, 35, 40);
    assertEquals(true, test1.isBefore(test2));
    assertEquals(false, test2.isBefore(test1));

    LocalTime test3 = new LocalTime(10, 20, 35, 40, GregorianChronology.getInstanceUTC());
    assertEquals(true, test1.isBefore(test3));
    assertEquals(false, test3.isBefore(test1));
    assertEquals(false, test3.isBefore(test2));

    try {
      new LocalTime(10, 20, 35, 40).isBefore(null);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  // -----------------------------------------------------------------------
  public void testIsAfter_LocalTime() {
    LocalTime test1 = new LocalTime(10, 20, 30, 40);
    LocalTime test1a = new LocalTime(10, 20, 30, 40);
    assertEquals(false, test1.isAfter(test1a));
    assertEquals(false, test1a.isAfter(test1));
    assertEquals(false, test1.isAfter(test1));
    assertEquals(false, test1a.isAfter(test1a));

    LocalTime test2 = new LocalTime(10, 20, 35, 40);
    assertEquals(false, test1.isAfter(test2));
    assertEquals(true, test2.isAfter(test1));

    LocalTime test3 = new LocalTime(10, 20, 35, 40, GregorianChronology.getInstanceUTC());
    assertEquals(false, test1.isAfter(test3));
    assertEquals(true, test3.isAfter(test1));
    assertEquals(false, test3.isAfter(test2));

    try {
      new LocalTime(10, 20, 35, 40).isAfter(null);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  // -----------------------------------------------------------------------
  public void testWithField_DateTimeFieldType_int_1() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    LocalTime result = test.withField(DateTimeFieldType.hourOfDay(), 15);

    assertEquals(new LocalTime(10, 20, 30, 40), test);
    assertEquals(new LocalTime(15, 20, 30, 40), result);
  }

  public void testWithField_DateTimeFieldType_int_2() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    try {
      test.withField(null, 6);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testWithField_DateTimeFieldType_int_3() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    try {
      test.withField(DateTimeFieldType.dayOfMonth(), 6);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testWithField_DateTimeFieldType_int_4() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    LocalTime result = test.withField(DateTimeFieldType.hourOfDay(), 10);
    assertSame(test, result);
  }

  // -----------------------------------------------------------------------
  public void testWithFieldAdded_DurationFieldType_int_1() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    LocalTime result = test.withFieldAdded(DurationFieldType.hours(), 6);

    assertEquals(new LocalTime(10, 20, 30, 40), test);
    assertEquals(new LocalTime(16, 20, 30, 40), result);
  }

  public void testWithFieldAdded_DurationFieldType_int_2() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    try {
      test.withFieldAdded(null, 0);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testWithFieldAdded_DurationFieldType_int_3() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    try {
      test.withFieldAdded(null, 6);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testWithFieldAdded_DurationFieldType_int_4() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    LocalTime result = test.withFieldAdded(DurationFieldType.hours(), 0);
    assertSame(test, result);
  }

  public void testWithFieldAdded_DurationFieldType_int_5() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    try {
      test.withFieldAdded(DurationFieldType.days(), 6);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testWithFieldAdded_DurationFieldType_int_6() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    LocalTime result = test.withFieldAdded(DurationFieldType.hours(), 16);

    assertEquals(new LocalTime(10, 20, 30, 40), test);
    assertEquals(new LocalTime(2, 20, 30, 40), result);
  }

  public void testWithFieldAdded_DurationFieldType_int_7() {
    LocalTime test = new LocalTime(23, 59, 59, 999);
    LocalTime result = test.withFieldAdded(DurationFieldType.millis(), 1);
    assertEquals(new LocalTime(0, 0, 0, 0), result);

    test = new LocalTime(23, 59, 59, 999);
    result = test.withFieldAdded(DurationFieldType.seconds(), 1);
    assertEquals(new LocalTime(0, 0, 0, 999), result);

    test = new LocalTime(23, 59, 59, 999);
    result = test.withFieldAdded(DurationFieldType.minutes(), 1);
    assertEquals(new LocalTime(0, 0, 59, 999), result);

    test = new LocalTime(23, 59, 59, 999);
    result = test.withFieldAdded(DurationFieldType.hours(), 1);
    assertEquals(new LocalTime(0, 59, 59, 999), result);
  }

  public void testWithFieldAdded_DurationFieldType_int_8() {
    LocalTime test = new LocalTime(0, 0, 0, 0);
    LocalTime result = test.withFieldAdded(DurationFieldType.millis(), -1);
    assertEquals(new LocalTime(23, 59, 59, 999), result);

    test = new LocalTime(0, 0, 0, 0);
    result = test.withFieldAdded(DurationFieldType.seconds(), -1);
    assertEquals(new LocalTime(23, 59, 59, 0), result);

    test = new LocalTime(0, 0, 0, 0);
    result = test.withFieldAdded(DurationFieldType.minutes(), -1);
    assertEquals(new LocalTime(23, 59, 0, 0), result);

    test = new LocalTime(0, 0, 0, 0);
    result = test.withFieldAdded(DurationFieldType.hours(), -1);
    assertEquals(new LocalTime(23, 0, 0, 0), result);
  }

  // -----------------------------------------------------------------------
  public void testPlus_RP() {
    LocalTime test = new LocalTime(10, 20, 30, 40, BUDDHIST_LONDON);
    LocalTime result = test.plus(new Period(1, 2, 3, 4, 5, 6, 7, 8));
    LocalTime expected = new LocalTime(15, 26, 37, 48, BUDDHIST_LONDON);
    assertEquals(expected, result);

    result = test.plus((ReadablePeriod) null);
    assertSame(test, result);
  }

  public void testPlusHours_int() {
    LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON);
    LocalTime result = test.plusHours(1);
    LocalTime expected = new LocalTime(2, 2, 3, 4, BUDDHIST_LONDON);
    assertEquals(expected, result);

    result = test.plusHours(0);
    assertSame(test, result);
  }

  public void testPlusMinutes_int() {
    LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON);
    LocalTime result = test.plusMinutes(1);
    LocalTime expected = new LocalTime(1, 3, 3, 4, BUDDHIST_LONDON);
    assertEquals(expected, result);

    result = test.plusMinutes(0);
    assertSame(test, result);
  }

  public void testPlusSeconds_int() {
    LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON);
    LocalTime result = test.plusSeconds(1);
    LocalTime expected = new LocalTime(1, 2, 4, 4, BUDDHIST_LONDON);
    assertEquals(expected, result);

    result = test.plusSeconds(0);
    assertSame(test, result);
  }

  public void testPlusMillis_int() {
    LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON);
    LocalTime result = test.plusMillis(1);
    LocalTime expected = new LocalTime(1, 2, 3, 5, BUDDHIST_LONDON);
    assertEquals(expected, result);

    result = test.plusMillis(0);
    assertSame(test, result);
  }

  // -----------------------------------------------------------------------
  public void testMinus_RP() {
    LocalTime test = new LocalTime(10, 20, 30, 40, BUDDHIST_LONDON);
    LocalTime result = test.minus(new Period(1, 1, 1, 1, 1, 1, 1, 1));
    LocalTime expected = new LocalTime(9, 19, 29, 39, BUDDHIST_LONDON);
    assertEquals(expected, result);

    result = test.minus((ReadablePeriod) null);
    assertSame(test, result);
  }

  public void testMinusHours_int() {
    LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON);
    LocalTime result = test.minusHours(1);
    LocalTime expected = new LocalTime(0, 2, 3, 4, BUDDHIST_LONDON);
    assertEquals(expected, result);

    result = test.minusHours(0);
    assertSame(test, result);
  }

  public void testMinusMinutes_int() {
    LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON);
    LocalTime result = test.minusMinutes(1);
    LocalTime expected = new LocalTime(1, 1, 3, 4, BUDDHIST_LONDON);
    assertEquals(expected, result);

    result = test.minusMinutes(0);
    assertSame(test, result);
  }

  public void testMinusSeconds_int() {
    LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON);
    LocalTime result = test.minusSeconds(1);
    LocalTime expected = new LocalTime(1, 2, 2, 4, BUDDHIST_LONDON);
    assertEquals(expected, result);

    result = test.minusSeconds(0);
    assertSame(test, result);
  }

  public void testMinusMillis_int() {
    LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON);
    LocalTime result = test.minusMillis(1);
    LocalTime expected = new LocalTime(1, 2, 3, 3, BUDDHIST_LONDON);
    assertEquals(expected, result);

    result = test.minusMillis(0);
    assertSame(test, result);
  }

  // -----------------------------------------------------------------------
  public void testGetters() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    assertEquals(10, test.getHourOfDay());
    assertEquals(20, test.getMinuteOfHour());
    assertEquals(30, test.getSecondOfMinute());
    assertEquals(40, test.getMillisOfSecond());
    assertEquals(TEST_TIME_NOW, test.getMillisOfDay());
  }

  // -----------------------------------------------------------------------
  public void testWithers() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    check(test.withHourOfDay(6), 6, 20, 30, 40);
    check(test.withMinuteOfHour(6), 10, 6, 30, 40);
    check(test.withSecondOfMinute(6), 10, 20, 6, 40);
    check(test.withMillisOfSecond(6), 10, 20, 30, 6);
    check(test.withMillisOfDay(61234), 0, 1, 1, 234);
    try {
      test.withHourOfDay(-1);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      test.withHourOfDay(24);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  // -----------------------------------------------------------------------
  public void testToDateTimeTodayDefaultZone() {
    LocalTime base = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); // PARIS irrelevant
    DateTime dt = new DateTime(2004, 6, 9, 6, 7, 8, 9);
    DateTimeUtils.setCurrentMillisFixed(dt.getMillis());

    DateTime test = base.toDateTimeToday();
    check(base, 10, 20, 30, 40);
    DateTime expected = new DateTime(dt.getMillis(), COPTIC_LONDON);
    expected = expected.hourOfDay().setCopy(10);
    expected = expected.minuteOfHour().setCopy(20);
    expected = expected.secondOfMinute().setCopy(30);
    expected = expected.millisOfSecond().setCopy(40);
    assertEquals(expected, test);
  }

  // -----------------------------------------------------------------------
  public void testToDateTimeToday_Zone() {
    LocalTime base = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); // PARIS irrelevant
    DateTime dt = new DateTime(2004, 6, 9, 6, 7, 8, 9);
    DateTimeUtils.setCurrentMillisFixed(dt.getMillis());

    DateTime test = base.toDateTimeToday(TOKYO);
    check(base, 10, 20, 30, 40);
    DateTime expected = new DateTime(dt.getMillis(), COPTIC_TOKYO);
    expected = expected.hourOfDay().setCopy(10);
    expected = expected.minuteOfHour().setCopy(20);
    expected = expected.secondOfMinute().setCopy(30);
    expected = expected.millisOfSecond().setCopy(40);
    assertEquals(expected, test);
  }

  public void testToDateTimeToday_nullZone() {
    LocalTime base = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); // PARIS irrelevant
    DateTime dt = new DateTime(2004, 6, 9, 6, 7, 8, 9);
    DateTimeUtils.setCurrentMillisFixed(dt.getMillis());

    DateTime test = base.toDateTimeToday((DateTimeZone) null);
    check(base, 10, 20, 30, 40);
    DateTime expected = new DateTime(dt.getMillis(), COPTIC_LONDON);
    expected = expected.hourOfDay().setCopy(10);
    expected = expected.minuteOfHour().setCopy(20);
    expected = expected.secondOfMinute().setCopy(30);
    expected = expected.millisOfSecond().setCopy(40);
    assertEquals(expected, test);
  }

  // -----------------------------------------------------------------------
  public void testToDateTime_RI() {
    LocalTime base = new LocalTime(10, 20, 30, 40, COPTIC_PARIS);
    DateTime dt = new DateTime(0L); // LONDON zone
    assertEquals("1970-01-01T01:00:00.000+01:00", dt.toString());

    DateTime test = base.toDateTime(dt);
    check(base, 10, 20, 30, 40);
    assertEquals("1970-01-01T01:00:00.000+01:00", dt.toString());
    assertEquals("1970-01-01T10:20:30.040+01:00", test.toString());
  }

  public void testToDateTime_nullRI() {
    LocalTime base = new LocalTime(1, 2, 3, 4);
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME2);

    DateTime test = base.toDateTime((ReadableInstant) null);
    check(base, 1, 2, 3, 4);
    assertEquals("1970-01-02T01:02:03.004+01:00", test.toString());
  }

  // -----------------------------------------------------------------------
  public void testProperty() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    assertEquals(test.hourOfDay(), test.property(DateTimeFieldType.hourOfDay()));
    assertEquals(test.minuteOfHour(), test.property(DateTimeFieldType.minuteOfHour()));
    assertEquals(test.secondOfMinute(), test.property(DateTimeFieldType.secondOfMinute()));
    assertEquals(test.millisOfSecond(), test.property(DateTimeFieldType.millisOfSecond()));
    assertEquals(test.millisOfDay(), test.property(DateTimeFieldType.millisOfDay()));

    assertEquals(test, test.property(DateTimeFieldType.minuteOfDay()).getLocalTime());
    assertEquals(test, test.property(DateTimeFieldType.secondOfDay()).getLocalTime());
    assertEquals(test, test.property(DateTimeFieldType.millisOfDay()).getLocalTime());
    assertEquals(test, test.property(DateTimeFieldType.hourOfHalfday()).getLocalTime());
    assertEquals(test, test.property(DateTimeFieldType.halfdayOfDay()).getLocalTime());
    assertEquals(test, test.property(DateTimeFieldType.clockhourOfHalfday()).getLocalTime());
    assertEquals(test, test.property(DateTimeFieldType.clockhourOfDay()).getLocalTime());

    try {
      test.property(DateTimeFieldType.dayOfWeek());
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      test.property(null);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  // -----------------------------------------------------------------------
  public void testSerialization() throws Exception {
    LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_PARIS);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(test);
    oos.close();
    byte[] bytes = baos.toByteArray();

    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ObjectInputStream ois = new ObjectInputStream(bais);
    LocalTime result = (LocalTime) ois.readObject();
    ois.close();

    assertEquals(test, result);
    assertTrue(Arrays.equals(test.getValues(), result.getValues()));
    assertTrue(Arrays.equals(test.getFields(), result.getFields()));
    assertEquals(test.getChronology(), result.getChronology());
  }

  // -----------------------------------------------------------------------
  public void testToString() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    assertEquals("10:20:30.040", test.toString());
  }

  // -----------------------------------------------------------------------
  public void testToString_String() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    assertEquals("\ufffd\ufffd\ufffd\ufffd 10", test.toString("yyyy HH"));
    assertEquals("10:20:30.040", test.toString((String) null));
  }

  // -----------------------------------------------------------------------
  public void testToString_String_Locale() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    assertEquals("10 20", test.toString("H m", Locale.ENGLISH));
    assertEquals("10:20:30.040", test.toString(null, Locale.ENGLISH));
    assertEquals("10 20", test.toString("H m", null));
    assertEquals("10:20:30.040", test.toString(null, null));
  }

  // -----------------------------------------------------------------------
  public void testToString_DTFormatter() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    assertEquals(
        "\ufffd\ufffd\ufffd\ufffd 10", test.toString(DateTimeFormat.forPattern("yyyy HH")));
    assertEquals("10:20:30.040", test.toString((DateTimeFormatter) null));
  }

  // -----------------------------------------------------------------------
  private void check(LocalTime test, int hour, int min, int sec, int milli) {
    assertEquals(hour, test.getHourOfDay());
    assertEquals(min, test.getMinuteOfHour());
    assertEquals(sec, test.getSecondOfMinute());
    assertEquals(milli, test.getMillisOfSecond());
  }
}
/**
 * This class is a Junit unit test for Instant.
 *
 * @author Stephen Colebourne
 */
public class TestMutableInterval_Basics 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 Chronology COPTIC_PARIS = CopticChronology.getInstance(PARIS);

  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(TestMutableInterval_Basics.class);
  }

  public TestMutableInterval_Basics(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(LONDON);
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
  }

  protected void tearDown() throws Exception {
    DateTimeUtils.setCurrentMillisSystem();
    DateTimeZone.setDefault(originalDateTimeZone);
    TimeZone.setDefault(originalTimeZone);
    Locale.setDefault(originalLocale);
    originalDateTimeZone = null;
    originalTimeZone = null;
    originalLocale = null;
  }

  // -----------------------------------------------------------------------
  public void testTest() {
    assertEquals("2002-06-09T00:00:00.000Z", new Instant(TEST_TIME_NOW).toString());
    assertEquals("2002-04-05T12:24:00.000Z", new Instant(TEST_TIME1).toString());
    assertEquals("2003-05-06T14:28:00.000Z", new Instant(TEST_TIME2).toString());
  }

  // -----------------------------------------------------------------------
  public void testGetMillis() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);
    assertEquals(TEST_TIME1, test.getStartMillis());
    assertEquals(TEST_TIME1, test.getStart().getMillis());
    assertEquals(TEST_TIME2, test.getEndMillis());
    assertEquals(TEST_TIME2, test.getEnd().getMillis());
    assertEquals(TEST_TIME2 - TEST_TIME1, test.toDurationMillis());
    assertEquals(TEST_TIME2 - TEST_TIME1, test.toDuration().getMillis());
  }

  public void testGetDuration1() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);
    assertEquals(TEST_TIME2 - TEST_TIME1, test.toDurationMillis());
    assertEquals(TEST_TIME2 - TEST_TIME1, test.toDuration().getMillis());
  }

  public void testGetDuration2() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME1);
    assertSame(Duration.ZERO, test.toDuration());
  }

  public void testEqualsHashCode() {
    MutableInterval test1 = new MutableInterval(TEST_TIME1, TEST_TIME2);
    MutableInterval test2 = new MutableInterval(TEST_TIME1, TEST_TIME2);
    assertEquals(true, test1.equals(test2));
    assertEquals(true, test2.equals(test1));
    assertEquals(true, test1.equals(test1));
    assertEquals(true, test2.equals(test2));
    assertEquals(true, test1.hashCode() == test2.hashCode());
    assertEquals(true, test1.hashCode() == test1.hashCode());
    assertEquals(true, test2.hashCode() == test2.hashCode());

    MutableInterval test3 = new MutableInterval(TEST_TIME_NOW, TEST_TIME2);
    assertEquals(false, test1.equals(test3));
    assertEquals(false, test2.equals(test3));
    assertEquals(false, test3.equals(test1));
    assertEquals(false, test3.equals(test2));
    assertEquals(false, test1.hashCode() == test3.hashCode());
    assertEquals(false, test2.hashCode() == test3.hashCode());

    MutableInterval test4 = new MutableInterval(TEST_TIME1, TEST_TIME2, GJChronology.getInstance());
    assertEquals(true, test4.equals(test4));
    assertEquals(false, test1.equals(test4));
    assertEquals(false, test2.equals(test4));
    assertEquals(false, test4.equals(test1));
    assertEquals(false, test4.equals(test2));
    assertEquals(false, test1.hashCode() == test4.hashCode());
    assertEquals(false, test2.hashCode() == test4.hashCode());

    MutableInterval test5 = new MutableInterval(TEST_TIME1, TEST_TIME2);
    assertEquals(true, test1.equals(test5));
    assertEquals(true, test2.equals(test5));
    assertEquals(false, test3.equals(test5));
    assertEquals(true, test5.equals(test1));
    assertEquals(true, test5.equals(test2));
    assertEquals(false, test5.equals(test3));
    assertEquals(true, test1.hashCode() == test5.hashCode());
    assertEquals(true, test2.hashCode() == test5.hashCode());
    assertEquals(false, test3.hashCode() == test5.hashCode());

    assertEquals(false, test1.equals("Hello"));
    assertEquals(true, test1.equals(new MockInterval()));
    assertEquals(false, test1.equals(new DateTime(TEST_TIME1)));
  }

  class MockInterval extends AbstractInterval {
    public MockInterval() {
      super();
    }

    public Chronology getChronology() {
      return ISOChronology.getInstance();
    }

    public long getStartMillis() {
      return TEST_TIME1;
    }

    public long getEndMillis() {
      return TEST_TIME2;
    }
  }

  // -----------------------------------------------------------------------
  public void testContains_long() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);
    assertEquals(true, test.contains(TEST_TIME1));
    assertEquals(false, test.contains(TEST_TIME1 - 1));
    assertEquals(true, test.contains(TEST_TIME1 + (TEST_TIME2 - TEST_TIME1) / 2));
    assertEquals(false, test.contains(TEST_TIME2));
    assertEquals(true, test.contains(TEST_TIME2 - 1));
  }

  public void testContainsNow() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);

    DateTimeUtils.setCurrentMillisFixed(TEST_TIME1);
    assertEquals(true, test.containsNow());
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME1 - 1);
    assertEquals(false, test.containsNow());
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME1 + (TEST_TIME2 - TEST_TIME1) / 2);
    assertEquals(true, test.containsNow());
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME2);
    assertEquals(false, test.containsNow());
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME2 - 1);
    assertEquals(true, test.containsNow());
  }

  public void testContains_RI() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);
    assertEquals(true, test.contains(new Instant(TEST_TIME1)));
    assertEquals(false, test.contains(new Instant(TEST_TIME1 - 1)));
    assertEquals(true, test.contains(new Instant(TEST_TIME1 + (TEST_TIME2 - TEST_TIME1) / 2)));
    assertEquals(false, test.contains(new Instant(TEST_TIME2)));
    assertEquals(true, test.contains(new Instant(TEST_TIME2 - 1)));
    assertEquals(true, test.contains((ReadableInstant) null));
  }

  // -----------------------------------------------------------------------
  public void testContains_RInterval() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);

    assertEquals(true, test.contains(new Interval(TEST_TIME1, TEST_TIME1)));
    assertEquals(false, test.contains(new Interval(TEST_TIME1 - 1, TEST_TIME1)));

    assertEquals(true, test.contains(new Interval(TEST_TIME1, TEST_TIME1 + 1)));
    assertEquals(false, test.contains(new Interval(TEST_TIME1 - 1, TEST_TIME1 + 1)));
    assertEquals(true, test.contains(new Interval(TEST_TIME1 + 1, TEST_TIME1 + 1)));

    assertEquals(true, test.contains(new Interval(TEST_TIME1, TEST_TIME2)));
    assertEquals(false, test.contains(new Interval(TEST_TIME1 - 1, TEST_TIME2)));
    assertEquals(
        true, test.contains(new Interval(TEST_TIME1 + (TEST_TIME2 - TEST_TIME1) / 2, TEST_TIME2)));
    assertEquals(false, test.contains(new Interval(TEST_TIME2, TEST_TIME2)));
    assertEquals(true, test.contains(new Interval(TEST_TIME2 - 1, TEST_TIME2)));

    assertEquals(true, test.contains(new Interval(TEST_TIME1, TEST_TIME2 - 1)));
    assertEquals(false, test.contains(new Interval(TEST_TIME1 - 1, TEST_TIME2 - 1)));
    assertEquals(
        true,
        test.contains(new Interval(TEST_TIME1 + (TEST_TIME2 - TEST_TIME1) / 2, TEST_TIME2 - 1)));
    assertEquals(true, test.contains(new Interval(TEST_TIME2 - 1, TEST_TIME2 - 1)));
    assertEquals(true, test.contains(new Interval(TEST_TIME2 - 2, TEST_TIME2 - 1)));

    assertEquals(false, test.contains(new Interval(TEST_TIME1, TEST_TIME2 + 1)));
    assertEquals(false, test.contains(new Interval(TEST_TIME1 - 1, TEST_TIME2 + 1)));
    assertEquals(
        false,
        test.contains(new Interval(TEST_TIME1 + (TEST_TIME2 - TEST_TIME1) / 2, TEST_TIME2 + 1)));
    assertEquals(false, test.contains(new Interval(TEST_TIME2, TEST_TIME2 + 1)));
    assertEquals(false, test.contains(new Interval(TEST_TIME2 - 1, TEST_TIME2 + 1)));
    assertEquals(false, test.contains(new Interval(TEST_TIME1 - 2, TEST_TIME1 - 1)));

    assertEquals(true, test.contains((ReadableInterval) null));
  }

  public void testOverlaps_RInterval() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);

    assertEquals(false, test.overlaps(new Interval(TEST_TIME1, TEST_TIME1)));
    assertEquals(false, test.overlaps(new Interval(TEST_TIME1 - 1, TEST_TIME1)));

    assertEquals(true, test.overlaps(new Interval(TEST_TIME1, TEST_TIME1 + 1)));
    assertEquals(true, test.overlaps(new Interval(TEST_TIME1 - 1, TEST_TIME1 + 1)));
    assertEquals(true, test.overlaps(new Interval(TEST_TIME1 + 1, TEST_TIME1 + 1)));

    assertEquals(true, test.overlaps(new Interval(TEST_TIME1, TEST_TIME2)));
    assertEquals(true, test.overlaps(new Interval(TEST_TIME1 - 1, TEST_TIME2)));
    assertEquals(
        true, test.overlaps(new Interval(TEST_TIME1 + (TEST_TIME2 - TEST_TIME1) / 2, TEST_TIME2)));
    assertEquals(false, test.overlaps(new Interval(TEST_TIME2, TEST_TIME2)));
    assertEquals(true, test.overlaps(new Interval(TEST_TIME2 - 1, TEST_TIME2)));

    assertEquals(true, test.overlaps(new Interval(TEST_TIME1, TEST_TIME2 + 1)));
    assertEquals(true, test.overlaps(new Interval(TEST_TIME1 - 1, TEST_TIME2 + 1)));
    assertEquals(
        true,
        test.overlaps(new Interval(TEST_TIME1 + (TEST_TIME2 - TEST_TIME1) / 2, TEST_TIME2 + 1)));
    assertEquals(false, test.overlaps(new Interval(TEST_TIME2, TEST_TIME2 + 1)));
    assertEquals(true, test.overlaps(new Interval(TEST_TIME2 - 1, TEST_TIME2 + 1)));

    assertEquals(false, test.overlaps(new Interval(TEST_TIME1 - 1, TEST_TIME1 - 1)));
    assertEquals(false, test.overlaps(new Interval(TEST_TIME1 - 1, TEST_TIME1)));
    assertEquals(true, test.overlaps(new Interval(TEST_TIME1 - 1, TEST_TIME1 + 1)));

    assertEquals(true, test.overlaps((ReadableInterval) null));

    MutableInterval empty = new MutableInterval(TEST_TIME1, TEST_TIME1);
    assertEquals(false, empty.overlaps(empty));
    assertEquals(false, empty.overlaps(test));
    assertEquals(false, test.overlaps(empty));
  }

  // -----------------------------------------------------------------------
  public void testIsBefore_long() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);

    assertEquals(false, test.isBefore(TEST_TIME1 - 1));
    assertEquals(false, test.isBefore(TEST_TIME1));
    assertEquals(false, test.isBefore(TEST_TIME1 + 1));

    assertEquals(false, test.isBefore(TEST_TIME2 - 1));
    assertEquals(true, test.isBefore(TEST_TIME2));
    assertEquals(true, test.isBefore(TEST_TIME2 + 1));
  }

  public void testIsBeforeNow() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);

    DateTimeUtils.setCurrentMillisFixed(TEST_TIME2 - 1);
    assertEquals(false, test.isBeforeNow());
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME2);
    assertEquals(true, test.isBeforeNow());
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME2 + 1);
    assertEquals(true, test.isBeforeNow());
  }

  public void testIsBefore_RI() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);

    assertEquals(false, test.isBefore(new Instant(TEST_TIME1 - 1)));
    assertEquals(false, test.isBefore(new Instant(TEST_TIME1)));
    assertEquals(false, test.isBefore(new Instant(TEST_TIME1 + 1)));

    assertEquals(false, test.isBefore(new Instant(TEST_TIME2 - 1)));
    assertEquals(true, test.isBefore(new Instant(TEST_TIME2)));
    assertEquals(true, test.isBefore(new Instant(TEST_TIME2 + 1)));

    assertEquals(false, test.isBefore((ReadableInstant) null));
  }

  public void testIsBefore_RInterval() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);

    assertEquals(false, test.isBefore(new Interval(Long.MIN_VALUE, TEST_TIME1 - 1)));
    assertEquals(false, test.isBefore(new Interval(Long.MIN_VALUE, TEST_TIME1)));
    assertEquals(false, test.isBefore(new Interval(Long.MIN_VALUE, TEST_TIME1 + 1)));

    assertEquals(false, test.isBefore(new Interval(TEST_TIME2 - 1, Long.MAX_VALUE)));
    assertEquals(true, test.isBefore(new Interval(TEST_TIME2, Long.MAX_VALUE)));
    assertEquals(true, test.isBefore(new Interval(TEST_TIME2 + 1, Long.MAX_VALUE)));

    assertEquals(false, test.isBefore((ReadableInterval) null));
  }

  // -----------------------------------------------------------------------
  public void testIsAfter_long() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);

    assertEquals(true, test.isAfter(TEST_TIME1 - 1));
    assertEquals(false, test.isAfter(TEST_TIME1));
    assertEquals(false, test.isAfter(TEST_TIME1 + 1));

    assertEquals(false, test.isAfter(TEST_TIME2 - 1));
    assertEquals(false, test.isAfter(TEST_TIME2));
    assertEquals(false, test.isAfter(TEST_TIME2 + 1));
  }

  public void testIsAfterNow() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);

    DateTimeUtils.setCurrentMillisFixed(TEST_TIME1 - 1);
    assertEquals(true, test.isAfterNow());
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME1);
    assertEquals(false, test.isAfterNow());
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME1 + 1);
    assertEquals(false, test.isAfterNow());
  }

  public void testIsAfter_RI() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);

    assertEquals(true, test.isAfter(new Instant(TEST_TIME1 - 1)));
    assertEquals(false, test.isAfter(new Instant(TEST_TIME1)));
    assertEquals(false, test.isAfter(new Instant(TEST_TIME1 + 1)));

    assertEquals(false, test.isAfter(new Instant(TEST_TIME2 - 1)));
    assertEquals(false, test.isAfter(new Instant(TEST_TIME2)));
    assertEquals(false, test.isAfter(new Instant(TEST_TIME2 + 1)));

    assertEquals(false, test.isAfter((ReadableInstant) null));
  }

  public void testIsAfter_RInterval() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);

    assertEquals(true, test.isAfter(new Interval(Long.MIN_VALUE, TEST_TIME1 - 1)));
    assertEquals(true, test.isAfter(new Interval(Long.MIN_VALUE, TEST_TIME1)));
    assertEquals(false, test.isAfter(new Interval(Long.MIN_VALUE, TEST_TIME1 + 1)));

    assertEquals(false, test.isAfter(new Interval(TEST_TIME2 - 1, Long.MAX_VALUE)));
    assertEquals(false, test.isAfter(new Interval(TEST_TIME2, Long.MAX_VALUE)));
    assertEquals(false, test.isAfter(new Interval(TEST_TIME2 + 1, Long.MAX_VALUE)));

    assertEquals(false, test.isAfter((ReadableInterval) null));
  }

  // -----------------------------------------------------------------------
  public void testToInterval1() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
    Interval result = test.toInterval();
    assertEquals(test, result);
  }

  // -----------------------------------------------------------------------
  public void testToMutableInterval1() {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2, COPTIC_PARIS);
    MutableInterval result = test.toMutableInterval();
    assertEquals(test, result);
    assertNotSame(test, result);
  }

  // -----------------------------------------------------------------------
  public void testToPeriod() {
    DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10, COPTIC_PARIS);
    DateTime dt2 = new DateTime(2005, 8, 13, 12, 14, 16, 18, COPTIC_PARIS);
    MutableInterval base = new MutableInterval(dt1, dt2);

    Period test = base.toPeriod();
    Period expected = new Period(dt1, dt2, PeriodType.standard());
    assertEquals(expected, test);
  }

  // -----------------------------------------------------------------------
  public void testToPeriod_PeriodType1() {
    DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10, COPTIC_PARIS);
    DateTime dt2 = new DateTime(2005, 8, 13, 12, 14, 16, 18, COPTIC_PARIS);
    MutableInterval base = new MutableInterval(dt1, dt2);

    Period test = base.toPeriod(null);
    Period expected = new Period(dt1, dt2, PeriodType.standard());
    assertEquals(expected, test);
  }

  public void testToPeriod_PeriodType2() {
    DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10);
    DateTime dt2 = new DateTime(2005, 8, 13, 12, 14, 16, 18);
    MutableInterval base = new MutableInterval(dt1, dt2);

    Period test = base.toPeriod(PeriodType.yearWeekDayTime());
    Period expected = new Period(dt1, dt2, PeriodType.yearWeekDayTime());
    assertEquals(expected, test);
  }

  // -----------------------------------------------------------------------
  public void testSerialization() throws Exception {
    MutableInterval test = new MutableInterval(TEST_TIME1, TEST_TIME2);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(test);
    byte[] bytes = baos.toByteArray();
    oos.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ObjectInputStream ois = new ObjectInputStream(bais);
    MutableInterval result = (MutableInterval) ois.readObject();
    ois.close();

    assertEquals(test, result);
  }

  // -----------------------------------------------------------------------
  public void testToString() {
    DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10, DateTimeZone.UTC);
    DateTime dt2 = new DateTime(2005, 8, 13, 12, 14, 16, 18, DateTimeZone.UTC);
    MutableInterval test = new MutableInterval(dt1, dt2);
    assertEquals("2004-06-09T07:08:09.010Z/2005-08-13T12:14:16.018Z", test.toString());
  }

  // -----------------------------------------------------------------------
  public void testCopy() {
    MutableInterval test = new MutableInterval(123L, 456L, COPTIC_PARIS);
    MutableInterval cloned = test.copy();
    assertEquals(test, cloned);
    assertNotSame(test, cloned);
  }

  public void testClone() {
    MutableInterval test = new MutableInterval(123L, 456L, COPTIC_PARIS);
    MutableInterval cloned = (MutableInterval) test.clone();
    assertEquals(test, cloned);
    assertNotSame(test, cloned);
  }
}