Example #1
0
  // -----------------------------------------------------------------------
  public void testProperty() {
    DateTime test = new DateTime();
    assertEquals(test.year(), test.property(DateTimeFieldType.year()));
    assertEquals(test.dayOfWeek(), test.property(DateTimeFieldType.dayOfWeek()));
    assertEquals(test.secondOfMinute(), test.property(DateTimeFieldType.secondOfMinute()));
    assertEquals(test.millisOfSecond(), test.property(DateTimeFieldType.millisOfSecond()));
    DateTimeFieldType bad =
        new DateTimeFieldType("bad") {
          /** */
          private static final long serialVersionUID = -7639693014651231134L;

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

          public DurationFieldType getRangeDurationType() {
            return null;
          }

          public DateTimeField getField(Chronology chronology) {
            return UnsupportedDateTimeField.getInstance(
                this, UnsupportedDurationField.getInstance(getDurationType()));
          }
        };
    try {
      test.property(bad);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      test.property(null);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }