0001: /*
0002: * Copyright 2001-2006 Stephen Colebourne
0003: *
0004: * Licensed under the Apache License, Version 2.0 (the "License");
0005: * you may not use this file except in compliance with the License.
0006: * You may obtain a copy of the License at
0007: *
0008: * http://www.apache.org/licenses/LICENSE-2.0
0009: *
0010: * Unless required by applicable law or agreed to in writing, software
0011: * distributed under the License is distributed on an "AS IS" BASIS,
0012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013: * See the License for the specific language governing permissions and
0014: * limitations under the License.
0015: */
0016: package org.joda.time;
0017:
0018: import java.util.Locale;
0019:
0020: import junit.framework.TestCase;
0021: import junit.framework.TestSuite;
0022:
0023: import org.joda.time.chrono.CopticChronology;
0024:
0025: /**
0026: * This class is a Junit unit test for LocalDateTime.
0027: *
0028: * @author Stephen Colebourne
0029: */
0030: public class TestLocalDateTime_Properties extends TestCase {
0031:
0032: private static final CopticChronology COPTIC_UTC = CopticChronology
0033: .getInstanceUTC();
0034:
0035: private int MILLIS_OF_DAY = (int) (10L
0036: * DateTimeConstants.MILLIS_PER_HOUR + 20L
0037: * DateTimeConstants.MILLIS_PER_MINUTE + 30L
0038: * DateTimeConstants.MILLIS_PER_SECOND + 40L);
0039: private long TEST_TIME_NOW = (31L + 28L + 31L + 30L + 31L + 9L - 1L)
0040: * DateTimeConstants.MILLIS_PER_DAY + MILLIS_OF_DAY;
0041: private long TEST_TIME1 = (31L + 28L + 31L + 6L - 1L)
0042: * DateTimeConstants.MILLIS_PER_DAY + 1L
0043: * DateTimeConstants.MILLIS_PER_HOUR + 2L
0044: * DateTimeConstants.MILLIS_PER_MINUTE + 3L
0045: * DateTimeConstants.MILLIS_PER_SECOND + 4L;
0046: private long TEST_TIME2 = (365L + 31L + 28L + 31L + 30L + 7L - 1L)
0047: * DateTimeConstants.MILLIS_PER_DAY + 4L
0048: * DateTimeConstants.MILLIS_PER_HOUR + 5L
0049: * DateTimeConstants.MILLIS_PER_MINUTE + 6L
0050: * DateTimeConstants.MILLIS_PER_SECOND + 7L;
0051:
0052: private DateTimeZone zone = null;
0053:
0054: public static void main(String[] args) {
0055: junit.textui.TestRunner.run(suite());
0056: }
0057:
0058: public static TestSuite suite() {
0059: return new TestSuite(TestLocalDateTime_Properties.class);
0060: }
0061:
0062: public TestLocalDateTime_Properties(String name) {
0063: super (name);
0064: }
0065:
0066: protected void setUp() throws Exception {
0067: DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
0068: zone = DateTimeZone.getDefault();
0069: DateTimeZone.setDefault(DateTimeZone.UTC);
0070: }
0071:
0072: protected void tearDown() throws Exception {
0073: DateTimeUtils.setCurrentMillisSystem();
0074: DateTimeZone.setDefault(zone);
0075: zone = null;
0076: }
0077:
0078: //-----------------------------------------------------------------------
0079: public void testPropertyGetYear() {
0080: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0081: 40);
0082: assertSame(test.getChronology().year(), test.year().getField());
0083: assertEquals("year", test.year().getName());
0084: assertEquals("Property[year]", test.year().toString());
0085: assertSame(test, test.year().getLocalDateTime());
0086: assertEquals(1972, test.year().get());
0087: assertEquals("1972", test.year().getAsString());
0088: assertEquals("1972", test.year().getAsText());
0089: assertEquals("1972", test.year().getAsText(Locale.FRENCH));
0090: assertEquals("1972", test.year().getAsShortText());
0091: assertEquals("1972", test.year().getAsShortText(Locale.FRENCH));
0092: assertEquals(test.getChronology().years(), test.year()
0093: .getDurationField());
0094: assertEquals(null, test.year().getRangeDurationField());
0095: assertEquals(9, test.year().getMaximumTextLength(null));
0096: assertEquals(9, test.year().getMaximumShortTextLength(null));
0097: }
0098:
0099: public void testPropertyGetMaxMinValuesYear() {
0100: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0101: 40);
0102: assertEquals(-292275054, test.year().getMinimumValue());
0103: assertEquals(-292275054, test.year().getMinimumValueOverall());
0104: assertEquals(292278993, test.year().getMaximumValue());
0105: assertEquals(292278993, test.year().getMaximumValueOverall());
0106: }
0107:
0108: public void testPropertyAddToCopyYear() {
0109: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0110: 40);
0111: LocalDateTime copy = test.year().addToCopy(9);
0112: check(test, 1972, 6, 9, 10, 20, 30, 40);
0113: check(copy, 1981, 6, 9, 10, 20, 30, 40);
0114:
0115: copy = test.year().addToCopy(0);
0116: check(copy, 1972, 6, 9, 10, 20, 30, 40);
0117:
0118: copy = test.year().addToCopy(292278993 - 1972);
0119: check(copy, 292278993, 6, 9, 10, 20, 30, 40);
0120:
0121: try {
0122: test.year().addToCopy(292278993 - 1972 + 1);
0123: fail();
0124: } catch (IllegalArgumentException ex) {
0125: }
0126: check(test, 1972, 6, 9, 10, 20, 30, 40);
0127:
0128: copy = test.year().addToCopy(-1972);
0129: check(copy, 0, 6, 9, 10, 20, 30, 40);
0130:
0131: copy = test.year().addToCopy(-1973);
0132: check(copy, -1, 6, 9, 10, 20, 30, 40);
0133:
0134: try {
0135: test.year().addToCopy(-292275054 - 1972 - 1);
0136: fail();
0137: } catch (IllegalArgumentException ex) {
0138: }
0139: check(test, 1972, 6, 9, 10, 20, 30, 40);
0140: }
0141:
0142: public void testPropertyAddWrapFieldToCopyYear() {
0143: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0144: 40);
0145: LocalDateTime copy = test.year().addWrapFieldToCopy(9);
0146: check(test, 1972, 6, 9, 10, 20, 30, 40);
0147: check(copy, 1981, 6, 9, 10, 20, 30, 40);
0148:
0149: copy = test.year().addWrapFieldToCopy(0);
0150: check(copy, 1972, 6, 9, 10, 20, 30, 40);
0151:
0152: copy = test.year().addWrapFieldToCopy(292278993 - 1972 + 1);
0153: check(copy, -292275054, 6, 9, 10, 20, 30, 40);
0154:
0155: copy = test.year().addWrapFieldToCopy(-292275054 - 1972 - 1);
0156: check(copy, 292278993, 6, 9, 10, 20, 30, 40);
0157: }
0158:
0159: public void testPropertySetCopyYear() {
0160: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0161: 40);
0162: LocalDateTime copy = test.year().setCopy(12);
0163: check(test, 1972, 6, 9, 10, 20, 30, 40);
0164: check(copy, 12, 6, 9, 10, 20, 30, 40);
0165: }
0166:
0167: public void testPropertySetCopyTextYear() {
0168: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0169: 40);
0170: LocalDateTime copy = test.year().setCopy("12");
0171: check(test, 1972, 6, 9, 10, 20, 30, 40);
0172: check(copy, 12, 6, 9, 10, 20, 30, 40);
0173: }
0174:
0175: public void testPropertyCompareToYear() {
0176: LocalDateTime test1 = new LocalDateTime(TEST_TIME1);
0177: LocalDateTime test2 = new LocalDateTime(TEST_TIME2);
0178: assertEquals(true, test1.year().compareTo(test2) < 0);
0179: assertEquals(true, test2.year().compareTo(test1) > 0);
0180: assertEquals(true, test1.year().compareTo(test1) == 0);
0181: try {
0182: test1.year().compareTo((ReadablePartial) null);
0183: fail();
0184: } catch (IllegalArgumentException ex) {
0185: }
0186:
0187: DateTime dt1 = new DateTime(TEST_TIME1);
0188: DateTime dt2 = new DateTime(TEST_TIME2);
0189: assertEquals(true, test1.year().compareTo(dt2) < 0);
0190: assertEquals(true, test2.year().compareTo(dt1) > 0);
0191: assertEquals(true, test1.year().compareTo(dt1) == 0);
0192: try {
0193: test1.year().compareTo((ReadableInstant) null);
0194: fail();
0195: } catch (IllegalArgumentException ex) {
0196: }
0197: }
0198:
0199: //-----------------------------------------------------------------------
0200: public void testPropertyGetMonth() {
0201: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0202: 40);
0203: assertSame(test.getChronology().monthOfYear(), test
0204: .monthOfYear().getField());
0205: assertEquals("monthOfYear", test.monthOfYear().getName());
0206: assertEquals("Property[monthOfYear]", test.monthOfYear()
0207: .toString());
0208: assertSame(test, test.monthOfYear().getLocalDateTime());
0209: assertEquals(6, test.monthOfYear().get());
0210: assertEquals("6", test.monthOfYear().getAsString());
0211: assertEquals("June", test.monthOfYear().getAsText());
0212: assertEquals("juin", test.monthOfYear()
0213: .getAsText(Locale.FRENCH));
0214: assertEquals("Jun", test.monthOfYear().getAsShortText());
0215: assertEquals("juin", test.monthOfYear().getAsShortText(
0216: Locale.FRENCH));
0217: assertEquals(test.getChronology().months(), test.monthOfYear()
0218: .getDurationField());
0219: assertEquals(test.getChronology().years(), test.monthOfYear()
0220: .getRangeDurationField());
0221: assertEquals(9, test.monthOfYear().getMaximumTextLength(null));
0222: assertEquals(3, test.monthOfYear().getMaximumShortTextLength(
0223: null));
0224: test = new LocalDateTime(1972, 7, 9, 10, 20, 30, 40);
0225: assertEquals("juillet", test.monthOfYear().getAsText(
0226: Locale.FRENCH));
0227: assertEquals("juil.", test.monthOfYear().getAsShortText(
0228: Locale.FRENCH));
0229: }
0230:
0231: public void testPropertyGetMaxMinValuesMonth() {
0232: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0233: 40);
0234: assertEquals(1, test.monthOfYear().getMinimumValue());
0235: assertEquals(1, test.monthOfYear().getMinimumValueOverall());
0236: assertEquals(12, test.monthOfYear().getMaximumValue());
0237: assertEquals(12, test.monthOfYear().getMaximumValueOverall());
0238: }
0239:
0240: public void testPropertyAddToCopyMonth() {
0241: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0242: 40);
0243: LocalDateTime copy = test.monthOfYear().addToCopy(6);
0244: check(test, 1972, 6, 9, 10, 20, 30, 40);
0245: check(copy, 1972, 12, 9, 10, 20, 30, 40);
0246:
0247: copy = test.monthOfYear().addToCopy(7);
0248: check(copy, 1973, 1, 9, 10, 20, 30, 40);
0249:
0250: copy = test.monthOfYear().addToCopy(-5);
0251: check(copy, 1972, 1, 9, 10, 20, 30, 40);
0252:
0253: copy = test.monthOfYear().addToCopy(-6);
0254: check(copy, 1971, 12, 9, 10, 20, 30, 40);
0255:
0256: test = new LocalDateTime(1972, 1, 31, 10, 20, 30, 40);
0257: copy = test.monthOfYear().addToCopy(1);
0258: check(copy, 1972, 2, 29, 10, 20, 30, 40);
0259:
0260: copy = test.monthOfYear().addToCopy(2);
0261: check(copy, 1972, 3, 31, 10, 20, 30, 40);
0262:
0263: copy = test.monthOfYear().addToCopy(3);
0264: check(copy, 1972, 4, 30, 10, 20, 30, 40);
0265:
0266: test = new LocalDateTime(1971, 1, 31, 10, 20, 30, 40);
0267: copy = test.monthOfYear().addToCopy(1);
0268: check(copy, 1971, 2, 28, 10, 20, 30, 40);
0269: }
0270:
0271: public void testPropertyAddWrapFieldToCopyMonth() {
0272: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0273: 40);
0274: LocalDateTime copy = test.monthOfYear().addWrapFieldToCopy(4);
0275: check(test, 1972, 6, 9, 10, 20, 30, 40);
0276: check(copy, 1972, 10, 9, 10, 20, 30, 40);
0277:
0278: copy = test.monthOfYear().addWrapFieldToCopy(8);
0279: check(copy, 1972, 2, 9, 10, 20, 30, 40);
0280:
0281: copy = test.monthOfYear().addWrapFieldToCopy(-8);
0282: check(copy, 1972, 10, 9, 10, 20, 30, 40);
0283:
0284: test = new LocalDateTime(1972, 1, 31, 10, 20, 30, 40);
0285: copy = test.monthOfYear().addWrapFieldToCopy(1);
0286: check(copy, 1972, 2, 29, 10, 20, 30, 40);
0287:
0288: copy = test.monthOfYear().addWrapFieldToCopy(2);
0289: check(copy, 1972, 3, 31, 10, 20, 30, 40);
0290:
0291: copy = test.monthOfYear().addWrapFieldToCopy(3);
0292: check(copy, 1972, 4, 30, 10, 20, 30, 40);
0293:
0294: test = new LocalDateTime(1971, 1, 31, 10, 20, 30, 40);
0295: copy = test.monthOfYear().addWrapFieldToCopy(1);
0296: check(copy, 1971, 2, 28, 10, 20, 30, 40);
0297: }
0298:
0299: public void testPropertySetCopyMonth() {
0300: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0301: 40);
0302: LocalDateTime copy = test.monthOfYear().setCopy(12);
0303: check(test, 1972, 6, 9, 10, 20, 30, 40);
0304: check(copy, 1972, 12, 9, 10, 20, 30, 40);
0305:
0306: test = new LocalDateTime(1972, 1, 31, 10, 20, 30, 40);
0307: copy = test.monthOfYear().setCopy(2);
0308: check(copy, 1972, 2, 29, 10, 20, 30, 40);
0309:
0310: try {
0311: test.monthOfYear().setCopy(13);
0312: fail();
0313: } catch (IllegalArgumentException ex) {
0314: }
0315: try {
0316: test.monthOfYear().setCopy(0);
0317: fail();
0318: } catch (IllegalArgumentException ex) {
0319: }
0320: }
0321:
0322: public void testPropertySetCopyTextMonth() {
0323: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0324: 40);
0325: LocalDateTime copy = test.monthOfYear().setCopy("12");
0326: check(test, 1972, 6, 9, 10, 20, 30, 40);
0327: check(copy, 1972, 12, 9, 10, 20, 30, 40);
0328:
0329: copy = test.monthOfYear().setCopy("December");
0330: check(test, 1972, 6, 9, 10, 20, 30, 40);
0331: check(copy, 1972, 12, 9, 10, 20, 30, 40);
0332:
0333: copy = test.monthOfYear().setCopy("Dec");
0334: check(test, 1972, 6, 9, 10, 20, 30, 40);
0335: check(copy, 1972, 12, 9, 10, 20, 30, 40);
0336: }
0337:
0338: public void testPropertyCompareToMonth() {
0339: LocalDateTime test1 = new LocalDateTime(TEST_TIME1);
0340: LocalDateTime test2 = new LocalDateTime(TEST_TIME2);
0341: assertEquals(true, test1.monthOfYear().compareTo(test2) < 0);
0342: assertEquals(true, test2.monthOfYear().compareTo(test1) > 0);
0343: assertEquals(true, test1.monthOfYear().compareTo(test1) == 0);
0344: try {
0345: test1.monthOfYear().compareTo((ReadablePartial) null);
0346: fail();
0347: } catch (IllegalArgumentException ex) {
0348: }
0349:
0350: DateTime dt1 = new DateTime(TEST_TIME1);
0351: DateTime dt2 = new DateTime(TEST_TIME2);
0352: assertEquals(true, test1.monthOfYear().compareTo(dt2) < 0);
0353: assertEquals(true, test2.monthOfYear().compareTo(dt1) > 0);
0354: assertEquals(true, test1.monthOfYear().compareTo(dt1) == 0);
0355: try {
0356: test1.monthOfYear().compareTo((ReadableInstant) null);
0357: fail();
0358: } catch (IllegalArgumentException ex) {
0359: }
0360: }
0361:
0362: //-----------------------------------------------------------------------
0363: public void testPropertyGetDay() {
0364: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0365: 40);
0366: assertSame(test.getChronology().dayOfMonth(), test.dayOfMonth()
0367: .getField());
0368: assertEquals("dayOfMonth", test.dayOfMonth().getName());
0369: assertEquals("Property[dayOfMonth]", test.dayOfMonth()
0370: .toString());
0371: assertSame(test, test.dayOfMonth().getLocalDateTime());
0372: assertEquals(9, test.dayOfMonth().get());
0373: assertEquals("9", test.dayOfMonth().getAsString());
0374: assertEquals("9", test.dayOfMonth().getAsText());
0375: assertEquals("9", test.dayOfMonth().getAsText(Locale.FRENCH));
0376: assertEquals("9", test.dayOfMonth().getAsShortText());
0377: assertEquals("9", test.dayOfMonth().getAsShortText(
0378: Locale.FRENCH));
0379: assertEquals(test.getChronology().days(), test.dayOfMonth()
0380: .getDurationField());
0381: assertEquals(test.getChronology().months(), test.dayOfMonth()
0382: .getRangeDurationField());
0383: assertEquals(2, test.dayOfMonth().getMaximumTextLength(null));
0384: assertEquals(2, test.dayOfMonth().getMaximumShortTextLength(
0385: null));
0386: }
0387:
0388: public void testPropertyGetMaxMinValuesDay() {
0389: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0390: 40);
0391: assertEquals(1, test.dayOfMonth().getMinimumValue());
0392: assertEquals(1, test.dayOfMonth().getMinimumValueOverall());
0393: assertEquals(30, test.dayOfMonth().getMaximumValue());
0394: assertEquals(31, test.dayOfMonth().getMaximumValueOverall());
0395: test = new LocalDateTime(1972, 7, 9, 10, 20, 30, 40);
0396: assertEquals(31, test.dayOfMonth().getMaximumValue());
0397: test = new LocalDateTime(1972, 2, 9, 10, 20, 30, 40);
0398: assertEquals(29, test.dayOfMonth().getMaximumValue());
0399: test = new LocalDateTime(1971, 2, 9, 10, 20, 30, 40);
0400: assertEquals(28, test.dayOfMonth().getMaximumValue());
0401: }
0402:
0403: public void testPropertyAddToCopyDay() {
0404: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0405: 40);
0406: LocalDateTime copy = test.dayOfMonth().addToCopy(9);
0407: check(test, 1972, 6, 9, 10, 20, 30, 40);
0408: check(copy, 1972, 6, 18, 10, 20, 30, 40);
0409:
0410: copy = test.dayOfMonth().addToCopy(21);
0411: check(copy, 1972, 6, 30, 10, 20, 30, 40);
0412:
0413: copy = test.dayOfMonth().addToCopy(22);
0414: check(copy, 1972, 7, 1, 10, 20, 30, 40);
0415:
0416: copy = test.dayOfMonth().addToCopy(22 + 30);
0417: check(copy, 1972, 7, 31, 10, 20, 30, 40);
0418:
0419: copy = test.dayOfMonth().addToCopy(22 + 31);
0420: check(copy, 1972, 8, 1, 10, 20, 30, 40);
0421:
0422: copy = test.dayOfMonth().addToCopy(
0423: 21 + 31 + 31 + 30 + 31 + 30 + 31);
0424: check(copy, 1972, 12, 31, 10, 20, 30, 40);
0425:
0426: copy = test.dayOfMonth().addToCopy(
0427: 22 + 31 + 31 + 30 + 31 + 30 + 31);
0428: check(copy, 1973, 1, 1, 10, 20, 30, 40);
0429:
0430: copy = test.dayOfMonth().addToCopy(-8);
0431: check(copy, 1972, 6, 1, 10, 20, 30, 40);
0432:
0433: copy = test.dayOfMonth().addToCopy(-9);
0434: check(copy, 1972, 5, 31, 10, 20, 30, 40);
0435:
0436: copy = test.dayOfMonth().addToCopy(-8 - 31 - 30 - 31 - 29 - 31);
0437: check(copy, 1972, 1, 1, 10, 20, 30, 40);
0438:
0439: copy = test.dayOfMonth().addToCopy(-9 - 31 - 30 - 31 - 29 - 31);
0440: check(copy, 1971, 12, 31, 10, 20, 30, 40);
0441: }
0442:
0443: public void testPropertyAddWrapFieldToCopyDay() {
0444: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0445: 40);
0446: LocalDateTime copy = test.dayOfMonth().addWrapFieldToCopy(21);
0447: check(test, 1972, 6, 9, 10, 20, 30, 40);
0448: check(copy, 1972, 6, 30, 10, 20, 30, 40);
0449:
0450: copy = test.dayOfMonth().addWrapFieldToCopy(22);
0451: check(copy, 1972, 6, 1, 10, 20, 30, 40);
0452:
0453: copy = test.dayOfMonth().addWrapFieldToCopy(-12);
0454: check(copy, 1972, 6, 27, 10, 20, 30, 40);
0455:
0456: test = new LocalDateTime(1972, 7, 9, 10, 20, 30, 40);
0457: copy = test.dayOfMonth().addWrapFieldToCopy(21);
0458: check(copy, 1972, 7, 30, 10, 20, 30, 40);
0459:
0460: copy = test.dayOfMonth().addWrapFieldToCopy(22);
0461: check(copy, 1972, 7, 31, 10, 20, 30, 40);
0462:
0463: copy = test.dayOfMonth().addWrapFieldToCopy(23);
0464: check(copy, 1972, 7, 1, 10, 20, 30, 40);
0465:
0466: copy = test.dayOfMonth().addWrapFieldToCopy(-12);
0467: check(copy, 1972, 7, 28, 10, 20, 30, 40);
0468: }
0469:
0470: public void testPropertySetCopyDay() {
0471: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0472: 40);
0473: LocalDateTime copy = test.dayOfMonth().setCopy(12);
0474: check(test, 1972, 6, 9, 10, 20, 30, 40);
0475: check(copy, 1972, 6, 12, 10, 20, 30, 40);
0476:
0477: try {
0478: test.dayOfMonth().setCopy(31);
0479: fail();
0480: } catch (IllegalArgumentException ex) {
0481: }
0482: try {
0483: test.dayOfMonth().setCopy(0);
0484: fail();
0485: } catch (IllegalArgumentException ex) {
0486: }
0487: }
0488:
0489: public void testPropertySetCopyTextDay() {
0490: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0491: 40);
0492: LocalDateTime copy = test.dayOfMonth().setCopy("12");
0493: check(test, 1972, 6, 9, 10, 20, 30, 40);
0494: check(copy, 1972, 6, 12, 10, 20, 30, 40);
0495: }
0496:
0497: public void testPropertyWithMaximumValueDayOfMonth() {
0498: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0499: 40);
0500: LocalDateTime copy = test.dayOfMonth().withMaximumValue();
0501: check(test, 1972, 6, 9, 10, 20, 30, 40);
0502: check(copy, 1972, 6, 30, 10, 20, 30, 40);
0503: }
0504:
0505: public void testPropertyWithMinimumValueDayOfMonth() {
0506: LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30,
0507: 40);
0508: LocalDateTime copy = test.dayOfMonth().withMinimumValue();
0509: check(test, 1972, 6, 9, 10, 20, 30, 40);
0510: check(copy, 1972, 6, 1, 10, 20, 30, 40);
0511: }
0512:
0513: public void testPropertyCompareToDay() {
0514: LocalDateTime test1 = new LocalDateTime(TEST_TIME1);
0515: LocalDateTime test2 = new LocalDateTime(TEST_TIME2);
0516: assertEquals(true, test1.dayOfMonth().compareTo(test2) < 0);
0517: assertEquals(true, test2.dayOfMonth().compareTo(test1) > 0);
0518: assertEquals(true, test1.dayOfMonth().compareTo(test1) == 0);
0519: try {
0520: test1.dayOfMonth().compareTo((ReadablePartial) null);
0521: fail();
0522: } catch (IllegalArgumentException ex) {
0523: }
0524:
0525: DateTime dt1 = new DateTime(TEST_TIME1);
0526: DateTime dt2 = new DateTime(TEST_TIME2);
0527: assertEquals(true, test1.dayOfMonth().compareTo(dt2) < 0);
0528: assertEquals(true, test2.dayOfMonth().compareTo(dt1) > 0);
0529: assertEquals(true, test1.dayOfMonth().compareTo(dt1) == 0);
0530: try {
0531: test1.dayOfMonth().compareTo((ReadableInstant) null);
0532: fail();
0533: } catch (IllegalArgumentException ex) {
0534: }
0535: }
0536:
0537: public void testPropertyEquals() {
0538: LocalDateTime test1 = new LocalDateTime(2005, 11, 8, 10, 20,
0539: 30, 40);
0540: LocalDateTime test2 = new LocalDateTime(2005, 11, 9, 10, 20,
0541: 30, 40);
0542: LocalDateTime test3 = new LocalDateTime(2005, 11, 8, 10, 20,
0543: 30, 40, COPTIC_UTC);
0544: assertEquals(false, test1.dayOfMonth().equals(test1.year()));
0545: assertEquals(false, test1.dayOfMonth().equals(
0546: test1.monthOfYear()));
0547: assertEquals(true, test1.dayOfMonth()
0548: .equals(test1.dayOfMonth()));
0549: assertEquals(false, test1.dayOfMonth().equals(test2.year()));
0550: assertEquals(false, test1.dayOfMonth().equals(
0551: test2.monthOfYear()));
0552: assertEquals(false, test1.dayOfMonth().equals(
0553: test2.dayOfMonth()));
0554:
0555: assertEquals(false, test1.monthOfYear().equals(test1.year()));
0556: assertEquals(true, test1.monthOfYear().equals(
0557: test1.monthOfYear()));
0558: assertEquals(false, test1.monthOfYear().equals(
0559: test1.dayOfMonth()));
0560: assertEquals(false, test1.monthOfYear().equals(test2.year()));
0561: assertEquals(true, test1.monthOfYear().equals(
0562: test2.monthOfYear()));
0563: assertEquals(false, test1.monthOfYear().equals(
0564: test2.dayOfMonth()));
0565:
0566: assertEquals(false, test1.dayOfMonth().equals(null));
0567: assertEquals(false, test1.dayOfMonth().equals("any"));
0568:
0569: // chrono
0570: assertEquals(false, test1.dayOfMonth().equals(
0571: test3.dayOfMonth()));
0572: }
0573:
0574: public void testPropertyHashCode() {
0575: LocalDateTime test1 = new LocalDateTime(2005, 11, 8, 10, 20,
0576: 30, 40);
0577: LocalDateTime test2 = new LocalDateTime(2005, 11, 9, 10, 20,
0578: 30, 40);
0579: assertEquals(true, test1.dayOfMonth().hashCode() == test1
0580: .dayOfMonth().hashCode());
0581: assertEquals(false, test1.dayOfMonth().hashCode() == test2
0582: .dayOfMonth().hashCode());
0583: assertEquals(true, test1.monthOfYear().hashCode() == test1
0584: .monthOfYear().hashCode());
0585: assertEquals(true, test1.monthOfYear().hashCode() == test2
0586: .monthOfYear().hashCode());
0587: }
0588:
0589: //-----------------------------------------------------------------------
0590: public void testPropertyGetHour() {
0591: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0592: 40);
0593: assertSame(test.getChronology().hourOfDay(), test.hourOfDay()
0594: .getField());
0595: assertEquals("hourOfDay", test.hourOfDay().getName());
0596: assertEquals("Property[hourOfDay]", test.hourOfDay().toString());
0597: assertSame(test, test.hourOfDay().getLocalDateTime());
0598: assertEquals(10, test.hourOfDay().get());
0599: assertEquals("10", test.hourOfDay().getAsString());
0600: assertEquals("10", test.hourOfDay().getAsText());
0601: assertEquals("10", test.hourOfDay().getAsText(Locale.FRENCH));
0602: assertEquals("10", test.hourOfDay().getAsShortText());
0603: assertEquals("10", test.hourOfDay().getAsShortText(
0604: Locale.FRENCH));
0605: assertEquals(test.getChronology().hours(), test.hourOfDay()
0606: .getDurationField());
0607: assertEquals(test.getChronology().days(), test.hourOfDay()
0608: .getRangeDurationField());
0609: assertEquals(2, test.hourOfDay().getMaximumTextLength(null));
0610: assertEquals(2, test.hourOfDay()
0611: .getMaximumShortTextLength(null));
0612: }
0613:
0614: public void testPropertyRoundHour() {
0615: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20);
0616: check(test.hourOfDay().roundCeilingCopy(), 2005, 6, 9, 11, 0,
0617: 0, 0);
0618: check(test.hourOfDay().roundFloorCopy(), 2005, 6, 9, 10, 0, 0,
0619: 0);
0620: check(test.hourOfDay().roundHalfCeilingCopy(), 2005, 6, 9, 10,
0621: 0, 0, 0);
0622: check(test.hourOfDay().roundHalfFloorCopy(), 2005, 6, 9, 10, 0,
0623: 0, 0);
0624: check(test.hourOfDay().roundHalfEvenCopy(), 2005, 6, 9, 10, 0,
0625: 0, 0);
0626:
0627: test = new LocalDateTime(2005, 6, 9, 10, 40);
0628: check(test.hourOfDay().roundCeilingCopy(), 2005, 6, 9, 11, 0,
0629: 0, 0);
0630: check(test.hourOfDay().roundFloorCopy(), 2005, 6, 9, 10, 0, 0,
0631: 0);
0632: check(test.hourOfDay().roundHalfCeilingCopy(), 2005, 6, 9, 11,
0633: 0, 0, 0);
0634: check(test.hourOfDay().roundHalfFloorCopy(), 2005, 6, 9, 11, 0,
0635: 0, 0);
0636: check(test.hourOfDay().roundHalfEvenCopy(), 2005, 6, 9, 11, 0,
0637: 0, 0);
0638:
0639: test = new LocalDateTime(2005, 6, 9, 10, 30);
0640: check(test.hourOfDay().roundCeilingCopy(), 2005, 6, 9, 11, 0,
0641: 0, 0);
0642: check(test.hourOfDay().roundFloorCopy(), 2005, 6, 9, 10, 0, 0,
0643: 0);
0644: check(test.hourOfDay().roundHalfCeilingCopy(), 2005, 6, 9, 11,
0645: 0, 0, 0);
0646: check(test.hourOfDay().roundHalfFloorCopy(), 2005, 6, 9, 10, 0,
0647: 0, 0);
0648: check(test.hourOfDay().roundHalfEvenCopy(), 2005, 6, 9, 10, 0,
0649: 0, 0);
0650:
0651: test = new LocalDateTime(2005, 6, 9, 11, 30);
0652: check(test.hourOfDay().roundCeilingCopy(), 2005, 6, 9, 12, 0,
0653: 0, 0);
0654: check(test.hourOfDay().roundFloorCopy(), 2005, 6, 9, 11, 0, 0,
0655: 0);
0656: check(test.hourOfDay().roundHalfCeilingCopy(), 2005, 6, 9, 12,
0657: 0, 0, 0);
0658: check(test.hourOfDay().roundHalfFloorCopy(), 2005, 6, 9, 11, 0,
0659: 0, 0);
0660: check(test.hourOfDay().roundHalfEvenCopy(), 2005, 6, 9, 12, 0,
0661: 0, 0);
0662: }
0663:
0664: public void testPropertyGetMaxMinValuesHour() {
0665: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0666: 40);
0667: assertEquals(0, test.hourOfDay().getMinimumValue());
0668: assertEquals(0, test.hourOfDay().getMinimumValueOverall());
0669: assertEquals(23, test.hourOfDay().getMaximumValue());
0670: assertEquals(23, test.hourOfDay().getMaximumValueOverall());
0671: }
0672:
0673: public void testPropertyWithMaxMinValueHour() {
0674: LocalDateTime test = new LocalDateTime(2005, 6, 9, 0, 20, 30,
0675: 40);
0676: check(test.hourOfDay().withMaximumValue(), 2005, 6, 9, 23, 20,
0677: 30, 40);
0678: check(test.hourOfDay().withMinimumValue(), 2005, 6, 9, 0, 20,
0679: 30, 40);
0680: }
0681:
0682: public void testPropertyAddToCopyHour() {
0683: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0684: 40);
0685: LocalDateTime copy = test.hourOfDay().addToCopy(9);
0686: check(test, 2005, 6, 9, 10, 20, 30, 40);
0687: check(copy, 2005, 6, 9, 19, 20, 30, 40);
0688:
0689: copy = test.hourOfDay().addToCopy(0);
0690: check(copy, 2005, 6, 9, 10, 20, 30, 40);
0691:
0692: copy = test.hourOfDay().addToCopy(13);
0693: check(copy, 2005, 6, 9, 23, 20, 30, 40);
0694:
0695: copy = test.hourOfDay().addToCopy(14);
0696: check(copy, 2005, 6, 10, 0, 20, 30, 40);
0697:
0698: copy = test.hourOfDay().addToCopy(-10);
0699: check(copy, 2005, 6, 9, 0, 20, 30, 40);
0700:
0701: copy = test.hourOfDay().addToCopy(-11);
0702: check(copy, 2005, 6, 8, 23, 20, 30, 40);
0703: }
0704:
0705: public void testPropertyAddWrapFieldToCopyHour() {
0706: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0707: 40);
0708: LocalDateTime copy = test.hourOfDay().addWrapFieldToCopy(9);
0709: check(test, 2005, 6, 9, 10, 20, 30, 40);
0710: check(copy, 2005, 6, 9, 19, 20, 30, 40);
0711:
0712: copy = test.hourOfDay().addWrapFieldToCopy(0);
0713: check(copy, 2005, 6, 9, 10, 20, 30, 40);
0714:
0715: copy = test.hourOfDay().addWrapFieldToCopy(18);
0716: check(copy, 2005, 6, 9, 4, 20, 30, 40);
0717:
0718: copy = test.hourOfDay().addWrapFieldToCopy(-15);
0719: check(copy, 2005, 6, 9, 19, 20, 30, 40);
0720: }
0721:
0722: public void testPropertySetHour() {
0723: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0724: 40);
0725: LocalDateTime copy = test.hourOfDay().setCopy(12);
0726: check(test, 2005, 6, 9, 10, 20, 30, 40);
0727: check(copy, 2005, 6, 9, 12, 20, 30, 40);
0728:
0729: try {
0730: test.hourOfDay().setCopy(24);
0731: fail();
0732: } catch (IllegalArgumentException ex) {
0733: }
0734: try {
0735: test.hourOfDay().setCopy(-1);
0736: fail();
0737: } catch (IllegalArgumentException ex) {
0738: }
0739: }
0740:
0741: public void testPropertySetTextHour() {
0742: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0743: 40);
0744: LocalDateTime copy = test.hourOfDay().setCopy("12");
0745: check(test, 2005, 6, 9, 10, 20, 30, 40);
0746: check(copy, 2005, 6, 9, 12, 20, 30, 40);
0747: }
0748:
0749: public void testPropertyWithMaximumValueHour() {
0750: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0751: 40);
0752: LocalDateTime copy = test.hourOfDay().withMaximumValue();
0753: check(test, 2005, 6, 9, 10, 20, 30, 40);
0754: check(copy, 2005, 6, 9, 23, 20, 30, 40);
0755: }
0756:
0757: public void testPropertyWithMinimumValueHour() {
0758: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0759: 40);
0760: LocalDateTime copy = test.hourOfDay().withMinimumValue();
0761: check(test, 2005, 6, 9, 10, 20, 30, 40);
0762: check(copy, 2005, 6, 9, 0, 20, 30, 40);
0763: }
0764:
0765: public void testPropertyCompareToHour() {
0766: LocalDateTime test1 = new LocalDateTime(TEST_TIME1);
0767: LocalDateTime test2 = new LocalDateTime(TEST_TIME2);
0768: assertEquals(true, test1.hourOfDay().compareTo(test2) < 0);
0769: assertEquals(true, test2.hourOfDay().compareTo(test1) > 0);
0770: assertEquals(true, test1.hourOfDay().compareTo(test1) == 0);
0771: try {
0772: test1.hourOfDay().compareTo((ReadablePartial) null);
0773: fail();
0774: } catch (IllegalArgumentException ex) {
0775: }
0776:
0777: DateTime dt1 = new DateTime(TEST_TIME1);
0778: DateTime dt2 = new DateTime(TEST_TIME2);
0779: assertEquals(true, test1.hourOfDay().compareTo(dt2) < 0);
0780: assertEquals(true, test2.hourOfDay().compareTo(dt1) > 0);
0781: assertEquals(true, test1.hourOfDay().compareTo(dt1) == 0);
0782: try {
0783: test1.hourOfDay().compareTo((ReadableInstant) null);
0784: fail();
0785: } catch (IllegalArgumentException ex) {
0786: }
0787: }
0788:
0789: //-----------------------------------------------------------------------
0790: public void testPropertyGetMinute() {
0791: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0792: 40);
0793: assertSame(test.getChronology().minuteOfHour(), test
0794: .minuteOfHour().getField());
0795: assertEquals("minuteOfHour", test.minuteOfHour().getName());
0796: assertEquals("Property[minuteOfHour]", test.minuteOfHour()
0797: .toString());
0798: assertSame(test, test.minuteOfHour().getLocalDateTime());
0799: assertEquals(20, test.minuteOfHour().get());
0800: assertEquals("20", test.minuteOfHour().getAsString());
0801: assertEquals("20", test.minuteOfHour().getAsText());
0802: assertEquals("20", test.minuteOfHour().getAsText(Locale.FRENCH));
0803: assertEquals("20", test.minuteOfHour().getAsShortText());
0804: assertEquals("20", test.minuteOfHour().getAsShortText(
0805: Locale.FRENCH));
0806: assertEquals(test.getChronology().minutes(), test
0807: .minuteOfHour().getDurationField());
0808: assertEquals(test.getChronology().hours(), test.minuteOfHour()
0809: .getRangeDurationField());
0810: assertEquals(2, test.minuteOfHour().getMaximumTextLength(null));
0811: assertEquals(2, test.minuteOfHour().getMaximumShortTextLength(
0812: null));
0813: }
0814:
0815: public void testPropertyGetMaxMinValuesMinute() {
0816: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0817: 40);
0818: assertEquals(0, test.minuteOfHour().getMinimumValue());
0819: assertEquals(0, test.minuteOfHour().getMinimumValueOverall());
0820: assertEquals(59, test.minuteOfHour().getMaximumValue());
0821: assertEquals(59, test.minuteOfHour().getMaximumValueOverall());
0822: }
0823:
0824: public void testPropertyWithMaxMinValueMinute() {
0825: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0826: 40);
0827: check(test.minuteOfHour().withMaximumValue(), 2005, 6, 9, 10,
0828: 59, 30, 40);
0829: check(test.minuteOfHour().withMinimumValue(), 2005, 6, 9, 10,
0830: 0, 30, 40);
0831: }
0832:
0833: public void testPropertyAddToCopyMinute() {
0834: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0835: 40);
0836: LocalDateTime copy = test.minuteOfHour().addToCopy(9);
0837: check(test, 2005, 6, 9, 10, 20, 30, 40);
0838: check(copy, 2005, 6, 9, 10, 29, 30, 40);
0839:
0840: copy = test.minuteOfHour().addToCopy(39);
0841: check(copy, 2005, 6, 9, 10, 59, 30, 40);
0842:
0843: copy = test.minuteOfHour().addToCopy(40);
0844: check(copy, 2005, 6, 9, 11, 0, 30, 40);
0845:
0846: copy = test.minuteOfHour().addToCopy(1 * 60 + 45);
0847: check(copy, 2005, 6, 9, 12, 5, 30, 40);
0848:
0849: copy = test.minuteOfHour().addToCopy(13 * 60 + 39);
0850: check(copy, 2005, 6, 9, 23, 59, 30, 40);
0851:
0852: copy = test.minuteOfHour().addToCopy(13 * 60 + 40);
0853: check(copy, 2005, 6, 10, 0, 0, 30, 40);
0854:
0855: copy = test.minuteOfHour().addToCopy(-9);
0856: check(copy, 2005, 6, 9, 10, 11, 30, 40);
0857:
0858: copy = test.minuteOfHour().addToCopy(-19);
0859: check(copy, 2005, 6, 9, 10, 1, 30, 40);
0860:
0861: copy = test.minuteOfHour().addToCopy(-20);
0862: check(copy, 2005, 6, 9, 10, 0, 30, 40);
0863:
0864: copy = test.minuteOfHour().addToCopy(-21);
0865: check(copy, 2005, 6, 9, 9, 59, 30, 40);
0866:
0867: copy = test.minuteOfHour().addToCopy(-(10 * 60 + 20));
0868: check(copy, 2005, 6, 9, 0, 0, 30, 40);
0869:
0870: copy = test.minuteOfHour().addToCopy(-(10 * 60 + 21));
0871: check(copy, 2005, 6, 8, 23, 59, 30, 40);
0872: }
0873:
0874: public void testPropertyAddWrapFieldToCopyMinute() {
0875: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0876: 40);
0877: LocalDateTime copy = test.minuteOfHour().addWrapFieldToCopy(9);
0878: check(test, 2005, 6, 9, 10, 20, 30, 40);
0879: check(copy, 2005, 6, 9, 10, 29, 30, 40);
0880:
0881: copy = test.minuteOfHour().addWrapFieldToCopy(49);
0882: check(copy, 2005, 6, 9, 10, 9, 30, 40);
0883:
0884: copy = test.minuteOfHour().addWrapFieldToCopy(-47);
0885: check(copy, 2005, 6, 9, 10, 33, 30, 40);
0886: }
0887:
0888: public void testPropertySetMinute() {
0889: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0890: 40);
0891: LocalDateTime copy = test.minuteOfHour().setCopy(12);
0892: check(test, 2005, 6, 9, 10, 20, 30, 40);
0893: check(copy, 2005, 6, 9, 10, 12, 30, 40);
0894:
0895: try {
0896: test.minuteOfHour().setCopy(60);
0897: fail();
0898: } catch (IllegalArgumentException ex) {
0899: }
0900: try {
0901: test.minuteOfHour().setCopy(-1);
0902: fail();
0903: } catch (IllegalArgumentException ex) {
0904: }
0905: }
0906:
0907: public void testPropertySetTextMinute() {
0908: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0909: 40);
0910: LocalDateTime copy = test.minuteOfHour().setCopy("12");
0911: check(test, 2005, 6, 9, 10, 20, 30, 40);
0912: check(copy, 2005, 6, 9, 10, 12, 30, 40);
0913: }
0914:
0915: public void testPropertyCompareToMinute() {
0916: LocalDateTime test1 = new LocalDateTime(TEST_TIME1);
0917: LocalDateTime test2 = new LocalDateTime(TEST_TIME2);
0918: assertEquals(true, test1.minuteOfHour().compareTo(test2) < 0);
0919: assertEquals(true, test2.minuteOfHour().compareTo(test1) > 0);
0920: assertEquals(true, test1.minuteOfHour().compareTo(test1) == 0);
0921: try {
0922: test1.minuteOfHour().compareTo((ReadablePartial) null);
0923: fail();
0924: } catch (IllegalArgumentException ex) {
0925: }
0926:
0927: DateTime dt1 = new DateTime(TEST_TIME1);
0928: DateTime dt2 = new DateTime(TEST_TIME2);
0929: assertEquals(true, test1.minuteOfHour().compareTo(dt2) < 0);
0930: assertEquals(true, test2.minuteOfHour().compareTo(dt1) > 0);
0931: assertEquals(true, test1.minuteOfHour().compareTo(dt1) == 0);
0932: try {
0933: test1.minuteOfHour().compareTo((ReadableInstant) null);
0934: fail();
0935: } catch (IllegalArgumentException ex) {
0936: }
0937: }
0938:
0939: //-----------------------------------------------------------------------
0940: public void testPropertyGetSecond() {
0941: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0942: 40);
0943: assertSame(test.getChronology().secondOfMinute(), test
0944: .secondOfMinute().getField());
0945: assertEquals("secondOfMinute", test.secondOfMinute().getName());
0946: assertEquals("Property[secondOfMinute]", test.secondOfMinute()
0947: .toString());
0948: assertSame(test, test.secondOfMinute().getLocalDateTime());
0949: assertEquals(30, test.secondOfMinute().get());
0950: assertEquals("30", test.secondOfMinute().getAsString());
0951: assertEquals("30", test.secondOfMinute().getAsText());
0952: assertEquals("30", test.secondOfMinute().getAsText(
0953: Locale.FRENCH));
0954: assertEquals("30", test.secondOfMinute().getAsShortText());
0955: assertEquals("30", test.secondOfMinute().getAsShortText(
0956: Locale.FRENCH));
0957: assertEquals(test.getChronology().seconds(), test
0958: .secondOfMinute().getDurationField());
0959: assertEquals(test.getChronology().minutes(), test
0960: .secondOfMinute().getRangeDurationField());
0961: assertEquals(2, test.secondOfMinute()
0962: .getMaximumTextLength(null));
0963: assertEquals(2, test.secondOfMinute()
0964: .getMaximumShortTextLength(null));
0965: }
0966:
0967: public void testPropertyGetMaxMinValuesSecond() {
0968: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0969: 40);
0970: assertEquals(0, test.secondOfMinute().getMinimumValue());
0971: assertEquals(0, test.secondOfMinute().getMinimumValueOverall());
0972: assertEquals(59, test.secondOfMinute().getMaximumValue());
0973: assertEquals(59, test.secondOfMinute().getMaximumValueOverall());
0974: }
0975:
0976: public void testPropertyWithMaxMinValueSecond() {
0977: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0978: 40);
0979: check(test.secondOfMinute().withMaximumValue(), 2005, 6, 9, 10,
0980: 20, 59, 40);
0981: check(test.secondOfMinute().withMinimumValue(), 2005, 6, 9, 10,
0982: 20, 0, 40);
0983: }
0984:
0985: public void testPropertyAddToCopySecond() {
0986: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
0987: 40);
0988: LocalDateTime copy = test.secondOfMinute().addToCopy(9);
0989: check(test, 2005, 6, 9, 10, 20, 30, 40);
0990: check(copy, 2005, 6, 9, 10, 20, 39, 40);
0991:
0992: copy = test.secondOfMinute().addToCopy(29);
0993: check(copy, 2005, 6, 9, 10, 20, 59, 40);
0994:
0995: copy = test.secondOfMinute().addToCopy(30);
0996: check(copy, 2005, 6, 9, 10, 21, 0, 40);
0997:
0998: copy = test.secondOfMinute().addToCopy(39 * 60 + 29);
0999: check(copy, 2005, 6, 9, 10, 59, 59, 40);
1000:
1001: copy = test.secondOfMinute().addToCopy(39 * 60 + 30);
1002: check(copy, 2005, 6, 9, 11, 0, 0, 40);
1003:
1004: copy = test.secondOfMinute().addToCopy(
1005: 13 * 60 * 60 + 39 * 60 + 30);
1006: check(copy, 2005, 6, 10, 0, 0, 0, 40);
1007:
1008: copy = test.secondOfMinute().addToCopy(-9);
1009: check(copy, 2005, 6, 9, 10, 20, 21, 40);
1010:
1011: copy = test.secondOfMinute().addToCopy(-30);
1012: check(copy, 2005, 6, 9, 10, 20, 0, 40);
1013:
1014: copy = test.secondOfMinute().addToCopy(-31);
1015: check(copy, 2005, 6, 9, 10, 19, 59, 40);
1016:
1017: copy = test.secondOfMinute().addToCopy(
1018: -(10 * 60 * 60 + 20 * 60 + 30));
1019: check(copy, 2005, 6, 9, 0, 0, 0, 40);
1020:
1021: copy = test.secondOfMinute().addToCopy(
1022: -(10 * 60 * 60 + 20 * 60 + 31));
1023: check(copy, 2005, 6, 8, 23, 59, 59, 40);
1024: }
1025:
1026: public void testPropertyAddWrapFieldToCopySecond() {
1027: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
1028: 40);
1029: LocalDateTime copy = test.secondOfMinute()
1030: .addWrapFieldToCopy(9);
1031: check(test, 2005, 6, 9, 10, 20, 30, 40);
1032: check(copy, 2005, 6, 9, 10, 20, 39, 40);
1033:
1034: copy = test.secondOfMinute().addWrapFieldToCopy(49);
1035: check(copy, 2005, 6, 9, 10, 20, 19, 40);
1036:
1037: copy = test.secondOfMinute().addWrapFieldToCopy(-47);
1038: check(copy, 2005, 6, 9, 10, 20, 43, 40);
1039: }
1040:
1041: public void testPropertySetSecond() {
1042: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
1043: 40);
1044: LocalDateTime copy = test.secondOfMinute().setCopy(12);
1045: check(test, 2005, 6, 9, 10, 20, 30, 40);
1046: check(copy, 2005, 6, 9, 10, 20, 12, 40);
1047:
1048: try {
1049: test.secondOfMinute().setCopy(60);
1050: fail();
1051: } catch (IllegalArgumentException ex) {
1052: }
1053: try {
1054: test.secondOfMinute().setCopy(-1);
1055: fail();
1056: } catch (IllegalArgumentException ex) {
1057: }
1058: }
1059:
1060: public void testPropertySetTextSecond() {
1061: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
1062: 40);
1063: LocalDateTime copy = test.secondOfMinute().setCopy("12");
1064: check(test, 2005, 6, 9, 10, 20, 30, 40);
1065: check(copy, 2005, 6, 9, 10, 20, 12, 40);
1066: }
1067:
1068: public void testPropertyCompareToSecond() {
1069: LocalDateTime test1 = new LocalDateTime(TEST_TIME1);
1070: LocalDateTime test2 = new LocalDateTime(TEST_TIME2);
1071: assertEquals(true, test1.secondOfMinute().compareTo(test2) < 0);
1072: assertEquals(true, test2.secondOfMinute().compareTo(test1) > 0);
1073: assertEquals(true, test1.secondOfMinute().compareTo(test1) == 0);
1074: try {
1075: test1.secondOfMinute().compareTo((ReadablePartial) null);
1076: fail();
1077: } catch (IllegalArgumentException ex) {
1078: }
1079:
1080: DateTime dt1 = new DateTime(TEST_TIME1);
1081: DateTime dt2 = new DateTime(TEST_TIME2);
1082: assertEquals(true, test1.secondOfMinute().compareTo(dt2) < 0);
1083: assertEquals(true, test2.secondOfMinute().compareTo(dt1) > 0);
1084: assertEquals(true, test1.secondOfMinute().compareTo(dt1) == 0);
1085: try {
1086: test1.secondOfMinute().compareTo((ReadableInstant) null);
1087: fail();
1088: } catch (IllegalArgumentException ex) {
1089: }
1090: }
1091:
1092: //-----------------------------------------------------------------------
1093: public void testPropertyGetMilli() {
1094: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
1095: 40);
1096: assertSame(test.getChronology().millisOfSecond(), test
1097: .millisOfSecond().getField());
1098: assertEquals("millisOfSecond", test.millisOfSecond().getName());
1099: assertEquals("Property[millisOfSecond]", test.millisOfSecond()
1100: .toString());
1101: assertSame(test, test.millisOfSecond().getLocalDateTime());
1102: assertEquals(40, test.millisOfSecond().get());
1103: assertEquals("40", test.millisOfSecond().getAsString());
1104: assertEquals("40", test.millisOfSecond().getAsText());
1105: assertEquals("40", test.millisOfSecond().getAsText(
1106: Locale.FRENCH));
1107: assertEquals("40", test.millisOfSecond().getAsShortText());
1108: assertEquals("40", test.millisOfSecond().getAsShortText(
1109: Locale.FRENCH));
1110: assertEquals(test.getChronology().millis(), test
1111: .millisOfSecond().getDurationField());
1112: assertEquals(test.getChronology().seconds(), test
1113: .millisOfSecond().getRangeDurationField());
1114: assertEquals(3, test.millisOfSecond()
1115: .getMaximumTextLength(null));
1116: assertEquals(3, test.millisOfSecond()
1117: .getMaximumShortTextLength(null));
1118: }
1119:
1120: public void testPropertyGetMaxMinValuesMilli() {
1121: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
1122: 40);
1123: assertEquals(0, test.millisOfSecond().getMinimumValue());
1124: assertEquals(0, test.millisOfSecond().getMinimumValueOverall());
1125: assertEquals(999, test.millisOfSecond().getMaximumValue());
1126: assertEquals(999, test.millisOfSecond()
1127: .getMaximumValueOverall());
1128: }
1129:
1130: public void testPropertyWithMaxMinValueMilli() {
1131: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
1132: 40);
1133: check(test.millisOfSecond().withMaximumValue(), 2005, 6, 9, 10,
1134: 20, 30, 999);
1135: check(test.millisOfSecond().withMinimumValue(), 2005, 6, 9, 10,
1136: 20, 30, 0);
1137: }
1138:
1139: public void testPropertyAddToCopyMilli() {
1140: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
1141: 40);
1142: LocalDateTime copy = test.millisOfSecond().addToCopy(9);
1143: check(test, 2005, 6, 9, 10, 20, 30, 40);
1144: check(copy, 2005, 6, 9, 10, 20, 30, 49);
1145:
1146: copy = test.millisOfSecond().addToCopy(959);
1147: check(copy, 2005, 6, 9, 10, 20, 30, 999);
1148:
1149: copy = test.millisOfSecond().addToCopy(960);
1150: check(copy, 2005, 6, 9, 10, 20, 31, 0);
1151:
1152: copy = test.millisOfSecond().addToCopy(
1153: 13 * 60 * 60 * 1000 + 39 * 60 * 1000 + 29 * 1000 + 959);
1154: check(copy, 2005, 6, 9, 23, 59, 59, 999);
1155:
1156: copy = test.millisOfSecond().addToCopy(
1157: 13 * 60 * 60 * 1000 + 39 * 60 * 1000 + 29 * 1000 + 960);
1158: check(copy, 2005, 6, 10, 0, 0, 0, 0);
1159:
1160: copy = test.millisOfSecond().addToCopy(-9);
1161: check(copy, 2005, 6, 9, 10, 20, 30, 31);
1162:
1163: copy = test.millisOfSecond().addToCopy(-40);
1164: check(copy, 2005, 6, 9, 10, 20, 30, 0);
1165:
1166: copy = test.millisOfSecond().addToCopy(-41);
1167: check(copy, 2005, 6, 9, 10, 20, 29, 999);
1168:
1169: copy = test.millisOfSecond()
1170: .addToCopy(
1171: -(10 * 60 * 60 * 1000 + 20 * 60 * 1000 + 30
1172: * 1000 + 40));
1173: check(copy, 2005, 6, 9, 0, 0, 0, 0);
1174:
1175: copy = test.millisOfSecond()
1176: .addToCopy(
1177: -(10 * 60 * 60 * 1000 + 20 * 60 * 1000 + 30
1178: * 1000 + 41));
1179: check(copy, 2005, 6, 8, 23, 59, 59, 999);
1180: }
1181:
1182: public void testPropertyAddWrapFieldToCopyMilli() {
1183: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
1184: 40);
1185: LocalDateTime copy = test.millisOfSecond()
1186: .addWrapFieldToCopy(9);
1187: check(test, 2005, 6, 9, 10, 20, 30, 40);
1188: check(copy, 2005, 6, 9, 10, 20, 30, 49);
1189:
1190: copy = test.millisOfSecond().addWrapFieldToCopy(995);
1191: check(copy, 2005, 6, 9, 10, 20, 30, 35);
1192:
1193: copy = test.millisOfSecond().addWrapFieldToCopy(-47);
1194: check(copy, 2005, 6, 9, 10, 20, 30, 993);
1195: }
1196:
1197: public void testPropertySetMilli() {
1198: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
1199: 40);
1200: LocalDateTime copy = test.millisOfSecond().setCopy(12);
1201: check(test, 2005, 6, 9, 10, 20, 30, 40);
1202: check(copy, 2005, 6, 9, 10, 20, 30, 12);
1203:
1204: try {
1205: test.millisOfSecond().setCopy(1000);
1206: fail();
1207: } catch (IllegalArgumentException ex) {
1208: }
1209: try {
1210: test.millisOfSecond().setCopy(-1);
1211: fail();
1212: } catch (IllegalArgumentException ex) {
1213: }
1214: }
1215:
1216: public void testPropertySetTextMilli() {
1217: LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
1218: 40);
1219: LocalDateTime copy = test.millisOfSecond().setCopy("12");
1220: check(test, 2005, 6, 9, 10, 20, 30, 40);
1221: check(copy, 2005, 6, 9, 10, 20, 30, 12);
1222: }
1223:
1224: public void testPropertyCompareToMilli() {
1225: LocalDateTime test1 = new LocalDateTime(TEST_TIME1);
1226: LocalDateTime test2 = new LocalDateTime(TEST_TIME2);
1227: assertEquals(true, test1.millisOfSecond().compareTo(test2) < 0);
1228: assertEquals(true, test2.millisOfSecond().compareTo(test1) > 0);
1229: assertEquals(true, test1.millisOfSecond().compareTo(test1) == 0);
1230: try {
1231: test1.millisOfSecond().compareTo((ReadablePartial) null);
1232: fail();
1233: } catch (IllegalArgumentException ex) {
1234: }
1235:
1236: DateTime dt1 = new DateTime(TEST_TIME1);
1237: DateTime dt2 = new DateTime(TEST_TIME2);
1238: assertEquals(true, test1.millisOfSecond().compareTo(dt2) < 0);
1239: assertEquals(true, test2.millisOfSecond().compareTo(dt1) > 0);
1240: assertEquals(true, test1.millisOfSecond().compareTo(dt1) == 0);
1241: try {
1242: test1.millisOfSecond().compareTo((ReadableInstant) null);
1243: fail();
1244: } catch (IllegalArgumentException ex) {
1245: }
1246: }
1247:
1248: //-----------------------------------------------------------------------
1249: private void check(LocalDateTime test, int year, int month,
1250: int day, int hour, int min, int sec, int mil) {
1251: assertEquals(year, test.getYear());
1252: assertEquals(month, test.getMonthOfYear());
1253: assertEquals(day, test.getDayOfMonth());
1254: assertEquals(hour, test.getHourOfDay());
1255: assertEquals(min, test.getMinuteOfHour());
1256: assertEquals(sec, test.getSecondOfMinute());
1257: assertEquals(mil, test.getMillisOfSecond());
1258: }
1259: }
|