Search in sources :

Example 16 with DateTimeField

use of org.joda.time.DateTimeField in project joda-time by JodaOrg.

the class TestUnsupportedDateTimeField method testMethodsThatShouldAlwaysReturnNull.

/**
     * According to the JavaDocs, there are two methods that should always
     * return null. * getRangeDurationField() * getLeapDurationField()
     * 
     * Ensure that these are in fact null.
     */
public void testMethodsThatShouldAlwaysReturnNull() {
    DateTimeField fieldOne = UnsupportedDateTimeField.getInstance(dateTimeFieldTypeOne, UnsupportedDurationField.getInstance(weeks));
    assertNull(fieldOne.getLeapDurationField());
    assertNull(fieldOne.getRangeDurationField());
}
Also used : DateTimeField(org.joda.time.DateTimeField)

Example 17 with DateTimeField

use of org.joda.time.DateTimeField in project joda-time by JodaOrg.

the class TestUnsupportedDateTimeField method testPublicGetNameMethod.

/**
     * The getName() method should return the same value as the getName() method
     * of the DateTimeFieldType that was used to create the instance.
     * 
     */
public void testPublicGetNameMethod() {
    DateTimeField fieldOne = UnsupportedDateTimeField.getInstance(dateTimeFieldTypeOne, UnsupportedDurationField.getInstance(weeks));
    assertSame(fieldOne.getName(), dateTimeFieldTypeOne.getName());
}
Also used : DateTimeField(org.joda.time.DateTimeField)

Example 18 with DateTimeField

use of org.joda.time.DateTimeField in project joda-time by JodaOrg.

the class TestUnsupportedDateTimeField method testDifferentDurationReturnDifferentObjects.

/**
     * 
     * This test exercises the logic in UnsupportedDateTimeField.getInstance. If
     * getInstance() is invoked twice with: - the same DateTimeFieldType -
     * different duration fields
     * 
     * Then the field returned in the first invocation should not be equal to
     * the field returned by the second invocation. In other words, the generated
     * instance should be the same for a unique pairing of
     * DateTimeFieldType/DurationField
     */
public void testDifferentDurationReturnDifferentObjects() {
    /**
         * The fields returned by getInstance should be the same when the
         * duration is the same for both method calls.
         */
    DateTimeField fieldOne = UnsupportedDateTimeField.getInstance(dateTimeFieldTypeOne, UnsupportedDurationField.getInstance(weeks));
    DateTimeField fieldTwo = UnsupportedDateTimeField.getInstance(dateTimeFieldTypeOne, UnsupportedDurationField.getInstance(weeks));
    assertSame(fieldOne, fieldTwo);
    /**
         * The fields returned by getInstance should NOT be the same when the
         * duration is the same for both method calls.
         */
    DateTimeField fieldThree = UnsupportedDateTimeField.getInstance(dateTimeFieldTypeOne, UnsupportedDurationField.getInstance(months));
    assertNotSame(fieldOne, fieldThree);
}
Also used : DateTimeField(org.joda.time.DateTimeField)

Example 19 with DateTimeField

use of org.joda.time.DateTimeField in project joda-time by JodaOrg.

the class TestUnsupportedDateTimeField method testUnsupportedMethods.

/**
     * As this is an unsupported date/time field, many normal methods are
     * unsupported and throw an UnsupportedOperationException. Verify that each
     * method correctly throws this exception. * add(ReadablePartial instant,
     * int fieldIndex, int[] values, int valueToAdd) * addWrapField(long
     * instant, int value) * addWrapField(ReadablePartial instant, int
     * fieldIndex, int[] values, int valueToAdd) *
     * addWrapPartial(ReadablePartial instant, int fieldIndex, int[] values, int
     * valueToAdd) * get(long instant) * getAsShortText(int fieldValue, Locale
     * locale) * getAsShortText(long instant) * getAsShortText(long instant,
     * Locale locale) * getAsShortText(ReadablePartial partial, int fieldValue,
     * Locale locale) * getAsShortText(ReadablePartial partial, Locale locale) *
     * getAsText(int fieldValue, Locale locale) * getAsText(long instant) *
     * getAsText(long instant, Locale locale) * getAsText(ReadablePartial
     * partial, int fieldValue, Locale locale) * getAsText(ReadablePartial
     * partial, Locale locale) * getLeapAmount(long instant) *
     * getMaximumShortTextLength(Locale locale) * getMaximumTextLength(Locale
     * locale) * getMaximumValue() * getMaximumValue(long instant) *
     * getMaximumValue(ReadablePartial instant) *
     * getMaximumValue(ReadablePartial instant, int[] values) *
     * getMinimumValue() * getMinimumValue(long instant) *
     * getMinimumValue(ReadablePartial instant) *
     * getMinimumValue(ReadablePartial instant, int[] values) * isLeap(long
     * instant) * remainder(long instant) * roundCeiling(long instant) *
     * roundFloor(long instant) * roundHalfCeiling(long instant) *
     * roundHalfEven(long instant) * roundHalfFloor(long instant) * set(long
     * instant, int value) * set(long instant, String text) * set(long instant,
     * String text, Locale locale) * set(ReadablePartial instant, int
     * fieldIndex, int[] values, int newValue) * set(ReadablePartial instant,
     * int fieldIndex, int[] values, String text, Locale locale)
     */
public void testUnsupportedMethods() {
    DateTimeField fieldOne = UnsupportedDateTimeField.getInstance(dateTimeFieldTypeOne, UnsupportedDurationField.getInstance(weeks));
    // valueToAdd)
    try {
        fieldOne.add(localTime, 0, new int[] { 0, 100 }, 100);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // addWrapField(long instant, int value)
    try {
        fieldOne.addWrapField(100000L, 250);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // int valueToAdd)
    try {
        fieldOne.addWrapField(localTime, 0, new int[] { 0, 100 }, 100);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // int valueToAdd)
    try {
        fieldOne.addWrapPartial(localTime, 0, new int[] { 0, 100 }, 100);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // UnsupportedDateTimeField.get(long instant)
    try {
        fieldOne.get(1000L);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // Locale locale)
    try {
        fieldOne.getAsShortText(0, Locale.getDefault());
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // UnsupportedDateTimeField.getAsShortText(long instant)
    try {
        fieldOne.getAsShortText(100000L);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // UnsupportedDateTimeField.getAsShortText(long instant, Locale locale)
    try {
        fieldOne.getAsShortText(100000L, Locale.getDefault());
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // Locale locale)
    try {
        fieldOne.getAsShortText(localTime, 0, Locale.getDefault());
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // Locale locale)
    try {
        fieldOne.getAsShortText(localTime, Locale.getDefault());
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // Locale locale)
    try {
        fieldOne.getAsText(0, Locale.getDefault());
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // UnsupportedDateTimeField.getAsText(long instant)
    try {
        fieldOne.getAsText(1000L);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // UnsupportedDateTimeField.getAsText(long instant, Locale locale)
    try {
        fieldOne.getAsText(1000L, Locale.getDefault());
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // Locale locale)
    try {
        fieldOne.getAsText(localTime, 0, Locale.getDefault());
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // Locale locale)
    try {
        fieldOne.getAsText(localTime, Locale.getDefault());
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // and should always thrown an UnsupportedOperationException
    try {
        fieldOne.getLeapAmount(System.currentTimeMillis());
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // UnsupportedOperationException
    try {
        fieldOne.getMaximumShortTextLength(Locale.getDefault());
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // UnsupportedOperationException
    try {
        fieldOne.getMaximumTextLength(Locale.getDefault());
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // and should always thrown an UnsupportedOperationException
    try {
        fieldOne.getMaximumValue();
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // UnsupportedOperationException
    try {
        fieldOne.getMaximumValue(1000000L);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // UnsupportedOperationException
    try {
        fieldOne.getMaximumValue(localTime);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // UnsupportedOperationException
    try {
        fieldOne.getMaximumValue(localTime, new int[] { 0 });
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // and should always thrown an UnsupportedOperationException
    try {
        fieldOne.getMinimumValue();
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // and should always thrown an UnsupportedOperationException
    try {
        fieldOne.getMinimumValue(10000000L);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // UnsupportedOperationException
    try {
        fieldOne.getMinimumValue(localTime);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // and should always thrown an UnsupportedOperationException
    try {
        fieldOne.getMinimumValue(localTime, new int[] { 0 });
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // should always thrown an UnsupportedOperationException
    try {
        fieldOne.isLeap(System.currentTimeMillis());
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // should always thrown an UnsupportedOperationException
    try {
        fieldOne.remainder(1000000L);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // should always thrown an UnsupportedOperationException
    try {
        fieldOne.roundCeiling(1000000L);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // should always thrown an UnsupportedOperationException
    try {
        fieldOne.roundFloor(1000000L);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // should always thrown an UnsupportedOperationException
    try {
        fieldOne.roundHalfCeiling(1000000L);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // should always thrown an UnsupportedOperationException
    try {
        fieldOne.roundHalfEven(1000000L);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // should always thrown an UnsupportedOperationException
    try {
        fieldOne.roundHalfFloor(1000000L);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // should always thrown an UnsupportedOperationException
    try {
        fieldOne.set(1000000L, 1000);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // should always thrown an UnsupportedOperationException
    try {
        fieldOne.set(1000000L, "Unsupported Operation");
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // UnsupportedOperationException
    try {
        fieldOne.set(1000000L, "Unsupported Operation", Locale.getDefault());
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // should always thrown an UnsupportedOperationException
    try {
        fieldOne.set(localTime, 0, new int[] { 0 }, 10000);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    // should always thrown an UnsupportedOperationException
    try {
        fieldOne.set(localTime, 0, new int[] { 0 }, "Unsupported Operation", Locale.getDefault());
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
}
Also used : DateTimeField(org.joda.time.DateTimeField)

Example 20 with DateTimeField

use of org.joda.time.DateTimeField in project joda-time by JodaOrg.

the class TestUnsupportedDateTimeField method testToString.

/**
    * The toString method should return a suitable debug message (not null).
    * Ensure that the toString method returns a string with length greater than
    * 0 (and not null)
    * 
    */
public void testToString() {
    DateTimeField fieldOne = UnsupportedDateTimeField.getInstance(dateTimeFieldTypeOne, UnsupportedDurationField.getInstance(weeks));
    String debugMessage = fieldOne.toString();
    assertNotNull(debugMessage);
    assertTrue(debugMessage.length() > 0);
}
Also used : DateTimeField(org.joda.time.DateTimeField)

Aggregations

DateTimeField (org.joda.time.DateTimeField)20 DateTime (org.joda.time.DateTime)5 DividedDateTimeField (org.joda.time.field.DividedDateTimeField)2 OffsetDateTimeField (org.joda.time.field.OffsetDateTimeField)2 RemainderDateTimeField (org.joda.time.field.RemainderDateTimeField)2 DateTimeFieldType (org.joda.time.DateTimeFieldType)1 IllegalFieldValueException (org.joda.time.IllegalFieldValueException)1 Interval (org.joda.time.Interval)1 Period (org.joda.time.Period)1 DelegatedDateTimeField (org.joda.time.field.DelegatedDateTimeField)1 PreciseDateTimeField (org.joda.time.field.PreciseDateTimeField)1 SkipUndoDateTimeField (org.joda.time.field.SkipUndoDateTimeField)1 UnsupportedDateTimeField (org.joda.time.field.UnsupportedDateTimeField)1 ZeroIsMaxDateTimeField (org.joda.time.field.ZeroIsMaxDateTimeField)1