0001: /*
0002: * Copyright 2001-2007 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.io.ByteArrayInputStream;
0019: import java.io.ByteArrayOutputStream;
0020: import java.io.ObjectInputStream;
0021: import java.io.ObjectOutputStream;
0022: import java.util.Arrays;
0023: import java.util.Date;
0024: import java.util.Locale;
0025:
0026: import junit.framework.TestCase;
0027: import junit.framework.TestSuite;
0028:
0029: import org.joda.time.chrono.BuddhistChronology;
0030: import org.joda.time.chrono.CopticChronology;
0031: import org.joda.time.chrono.GJChronology;
0032: import org.joda.time.chrono.GregorianChronology;
0033: import org.joda.time.chrono.ISOChronology;
0034: import org.joda.time.chrono.LenientChronology;
0035: import org.joda.time.chrono.StrictChronology;
0036: import org.joda.time.format.DateTimeFormat;
0037: import org.joda.time.format.DateTimeFormatter;
0038:
0039: /**
0040: * This class is a Junit unit test for LocalDate.
0041: *
0042: * @author Stephen Colebourne
0043: */
0044: public class TestLocalDate_Basics extends TestCase {
0045:
0046: private static final DateTimeZone PARIS = DateTimeZone
0047: .forID("Europe/Paris");
0048: private static final DateTimeZone LONDON = DateTimeZone
0049: .forID("Europe/London");
0050: private static final DateTimeZone TOKYO = DateTimeZone
0051: .forID("Asia/Tokyo");
0052: private static final int OFFSET = 1;
0053: private static final GJChronology GJ_UTC = GJChronology
0054: .getInstanceUTC();
0055: private static final Chronology COPTIC_PARIS = CopticChronology
0056: .getInstance(PARIS);
0057: private static final Chronology COPTIC_LONDON = CopticChronology
0058: .getInstance(LONDON);
0059: private static final Chronology COPTIC_TOKYO = CopticChronology
0060: .getInstance(TOKYO);
0061: private static final Chronology COPTIC_UTC = CopticChronology
0062: .getInstanceUTC();
0063: private static final Chronology ISO_PARIS = ISOChronology
0064: .getInstance(PARIS);
0065: private static final Chronology ISO_LONDON = ISOChronology
0066: .getInstance(LONDON);
0067: private static final Chronology ISO_TOKYO = ISOChronology
0068: .getInstance(TOKYO);
0069: private static final Chronology ISO_UTC = ISOChronology
0070: .getInstanceUTC();
0071: private static final Chronology BUDDHIST_PARIS = BuddhistChronology
0072: .getInstance(PARIS);
0073: private static final Chronology BUDDHIST_LONDON = BuddhistChronology
0074: .getInstance(LONDON);
0075: private static final Chronology BUDDHIST_TOKYO = BuddhistChronology
0076: .getInstance(TOKYO);
0077: private static final Chronology BUDDHIST_UTC = BuddhistChronology
0078: .getInstanceUTC();
0079:
0080: /** Mock zone simulating Asia/Gaza cutover at midnight 2007-04-01 */
0081: private static long CUTOVER_GAZA = 1175378400000L;
0082: private static int OFFSET_GAZA = 7200000; // +02:00
0083: private static final DateTimeZone MOCK_GAZA = new MockZone(
0084: CUTOVER_GAZA, OFFSET_GAZA);
0085:
0086: private long TEST_TIME_NOW = (31L + 28L + 31L + 30L + 31L + 9L - 1L)
0087: * DateTimeConstants.MILLIS_PER_DAY;
0088:
0089: private long TEST_TIME1 = (31L + 28L + 31L + 6L - 1L)
0090: * DateTimeConstants.MILLIS_PER_DAY + 12L
0091: * DateTimeConstants.MILLIS_PER_HOUR + 24L
0092: * DateTimeConstants.MILLIS_PER_MINUTE;
0093:
0094: private long TEST_TIME2 = (365L + 31L + 28L + 31L + 30L + 7L - 1L)
0095: * DateTimeConstants.MILLIS_PER_DAY + 14L
0096: * DateTimeConstants.MILLIS_PER_HOUR + 28L
0097: * DateTimeConstants.MILLIS_PER_MINUTE;
0098:
0099: private DateTimeZone zone = null;
0100:
0101: public static void main(String[] args) {
0102: junit.textui.TestRunner.run(suite());
0103: }
0104:
0105: public static TestSuite suite() {
0106: return new TestSuite(TestLocalDate_Basics.class);
0107: }
0108:
0109: public TestLocalDate_Basics(String name) {
0110: super (name);
0111: }
0112:
0113: protected void setUp() throws Exception {
0114: DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
0115: zone = DateTimeZone.getDefault();
0116: DateTimeZone.setDefault(LONDON);
0117: }
0118:
0119: protected void tearDown() throws Exception {
0120: DateTimeUtils.setCurrentMillisSystem();
0121: DateTimeZone.setDefault(zone);
0122: zone = null;
0123: }
0124:
0125: //-----------------------------------------------------------------------
0126: public void testGet_DateTimeFieldType() {
0127: LocalDate test = new LocalDate();
0128: assertEquals(1970, test.get(DateTimeFieldType.year()));
0129: assertEquals(6, test.get(DateTimeFieldType.monthOfYear()));
0130: assertEquals(9, test.get(DateTimeFieldType.dayOfMonth()));
0131: assertEquals(2, test.get(DateTimeFieldType.dayOfWeek()));
0132: assertEquals(160, test.get(DateTimeFieldType.dayOfYear()));
0133: assertEquals(24, test.get(DateTimeFieldType.weekOfWeekyear()));
0134: assertEquals(1970, test.get(DateTimeFieldType.weekyear()));
0135: try {
0136: test.get(null);
0137: fail();
0138: } catch (IllegalArgumentException ex) {
0139: }
0140: try {
0141: test.get(DateTimeFieldType.hourOfDay());
0142: fail();
0143: } catch (IllegalArgumentException ex) {
0144: }
0145: }
0146:
0147: public void testSize() {
0148: LocalDate test = new LocalDate();
0149: assertEquals(3, test.size());
0150: }
0151:
0152: public void testGetFieldType_int() {
0153: LocalDate test = new LocalDate(COPTIC_PARIS);
0154: assertSame(DateTimeFieldType.year(), test.getFieldType(0));
0155: assertSame(DateTimeFieldType.monthOfYear(), test
0156: .getFieldType(1));
0157: assertSame(DateTimeFieldType.dayOfMonth(), test.getFieldType(2));
0158: try {
0159: test.getFieldType(-1);
0160: } catch (IndexOutOfBoundsException ex) {
0161: }
0162: try {
0163: test.getFieldType(3);
0164: } catch (IndexOutOfBoundsException ex) {
0165: }
0166: }
0167:
0168: public void testGetFieldTypes() {
0169: LocalDate test = new LocalDate(COPTIC_PARIS);
0170: DateTimeFieldType[] fields = test.getFieldTypes();
0171: assertSame(DateTimeFieldType.year(), fields[0]);
0172: assertSame(DateTimeFieldType.monthOfYear(), fields[1]);
0173: assertSame(DateTimeFieldType.dayOfMonth(), fields[2]);
0174: assertNotSame(test.getFieldTypes(), test.getFieldTypes());
0175: }
0176:
0177: public void testGetField_int() {
0178: LocalDate test = new LocalDate(COPTIC_PARIS);
0179: assertSame(COPTIC_UTC.year(), test.getField(0));
0180: assertSame(COPTIC_UTC.monthOfYear(), test.getField(1));
0181: assertSame(COPTIC_UTC.dayOfMonth(), test.getField(2));
0182: try {
0183: test.getField(-1);
0184: } catch (IndexOutOfBoundsException ex) {
0185: }
0186: try {
0187: test.getField(3);
0188: } catch (IndexOutOfBoundsException ex) {
0189: }
0190: }
0191:
0192: public void testGetFields() {
0193: LocalDate test = new LocalDate(COPTIC_PARIS);
0194: DateTimeField[] fields = test.getFields();
0195: assertSame(COPTIC_UTC.year(), fields[0]);
0196: assertSame(COPTIC_UTC.monthOfYear(), fields[1]);
0197: assertSame(COPTIC_UTC.dayOfMonth(), fields[2]);
0198: assertNotSame(test.getFields(), test.getFields());
0199: }
0200:
0201: public void testGetValue_int() {
0202: LocalDate test = new LocalDate();
0203: assertEquals(1970, test.getValue(0));
0204: assertEquals(6, test.getValue(1));
0205: assertEquals(9, test.getValue(2));
0206: try {
0207: test.getValue(-1);
0208: } catch (IndexOutOfBoundsException ex) {
0209: }
0210: try {
0211: test.getValue(3);
0212: } catch (IndexOutOfBoundsException ex) {
0213: }
0214: }
0215:
0216: public void testGetValues() {
0217: LocalDate test = new LocalDate();
0218: int[] values = test.getValues();
0219: assertEquals(1970, values[0]);
0220: assertEquals(6, values[1]);
0221: assertEquals(9, values[2]);
0222: assertNotSame(test.getValues(), test.getValues());
0223: }
0224:
0225: public void testIsSupported_DateTimeFieldType() {
0226: LocalDate test = new LocalDate(COPTIC_PARIS);
0227: assertEquals(true, test.isSupported(DateTimeFieldType.year()));
0228: assertEquals(true, test.isSupported(DateTimeFieldType
0229: .monthOfYear()));
0230: assertEquals(true, test.isSupported(DateTimeFieldType
0231: .dayOfMonth()));
0232: assertEquals(true, test.isSupported(DateTimeFieldType
0233: .dayOfWeek()));
0234: assertEquals(true, test.isSupported(DateTimeFieldType
0235: .dayOfYear()));
0236: assertEquals(true, test.isSupported(DateTimeFieldType
0237: .weekOfWeekyear()));
0238: assertEquals(true, test.isSupported(DateTimeFieldType
0239: .weekyear()));
0240: assertEquals(true, test.isSupported(DateTimeFieldType
0241: .yearOfCentury()));
0242: assertEquals(true, test.isSupported(DateTimeFieldType
0243: .yearOfEra()));
0244: assertEquals(true, test.isSupported(DateTimeFieldType
0245: .centuryOfEra()));
0246: assertEquals(true, test.isSupported(DateTimeFieldType
0247: .weekyearOfCentury()));
0248: assertEquals(true, test.isSupported(DateTimeFieldType.era()));
0249: assertEquals(false, test.isSupported(DateTimeFieldType
0250: .hourOfDay()));
0251: assertEquals(false, test.isSupported((DateTimeFieldType) null));
0252: }
0253:
0254: public void testIsSupported_DurationFieldType() {
0255: LocalDate test = new LocalDate(1970, 6, 9);
0256: assertEquals(false, test.isSupported(DurationFieldType.eras()));
0257: assertEquals(true, test.isSupported(DurationFieldType
0258: .centuries()));
0259: assertEquals(true, test.isSupported(DurationFieldType.years()));
0260: assertEquals(true, test.isSupported(DurationFieldType.months()));
0261: assertEquals(true, test.isSupported(DurationFieldType
0262: .weekyears()));
0263: assertEquals(true, test.isSupported(DurationFieldType.weeks()));
0264: assertEquals(true, test.isSupported(DurationFieldType.days()));
0265:
0266: assertEquals(false, test.isSupported(DurationFieldType.hours()));
0267: assertEquals(false, test.isSupported((DurationFieldType) null));
0268: }
0269:
0270: public void testEqualsHashCode() {
0271: LocalDate test1 = new LocalDate(1970, 6, 9, COPTIC_PARIS);
0272: LocalDate test2 = new LocalDate(1970, 6, 9, COPTIC_PARIS);
0273: assertEquals(true, test1.equals(test2));
0274: assertEquals(true, test2.equals(test1));
0275: assertEquals(true, test1.equals(test1));
0276: assertEquals(true, test2.equals(test2));
0277: assertEquals(true, test1.hashCode() == test2.hashCode());
0278: assertEquals(true, test1.hashCode() == test1.hashCode());
0279: assertEquals(true, test2.hashCode() == test2.hashCode());
0280:
0281: LocalDate test3 = new LocalDate(1971, 6, 9);
0282: assertEquals(false, test1.equals(test3));
0283: assertEquals(false, test2.equals(test3));
0284: assertEquals(false, test3.equals(test1));
0285: assertEquals(false, test3.equals(test2));
0286: assertEquals(false, test1.hashCode() == test3.hashCode());
0287: assertEquals(false, test2.hashCode() == test3.hashCode());
0288:
0289: assertEquals(false, test1.equals("Hello"));
0290: assertEquals(true, test1.equals(new MockInstant()));
0291: assertEquals(true, test1.equals(new YearMonthDay(1970, 6, 9,
0292: COPTIC_PARIS)));
0293: assertEquals(true, test1.hashCode() == new YearMonthDay(1970,
0294: 6, 9, COPTIC_PARIS).hashCode());
0295: assertEquals(false, test1.equals(MockPartial.EMPTY_INSTANCE));
0296: }
0297:
0298: class MockInstant extends MockPartial {
0299: public Chronology getChronology() {
0300: return COPTIC_UTC;
0301: }
0302:
0303: public DateTimeField[] getFields() {
0304: return new DateTimeField[] { COPTIC_UTC.year(),
0305: COPTIC_UTC.monthOfYear(), COPTIC_UTC.dayOfMonth(), };
0306: }
0307:
0308: public int[] getValues() {
0309: return new int[] { 1970, 6, 9 };
0310: }
0311: }
0312:
0313: public void testEqualsHashCodeLenient() {
0314: LocalDate test1 = new LocalDate(1970, 6, 9, LenientChronology
0315: .getInstance(COPTIC_PARIS));
0316: LocalDate test2 = new LocalDate(1970, 6, 9, LenientChronology
0317: .getInstance(COPTIC_PARIS));
0318: assertEquals(true, test1.equals(test2));
0319: assertEquals(true, test2.equals(test1));
0320: assertEquals(true, test1.equals(test1));
0321: assertEquals(true, test2.equals(test2));
0322: assertEquals(true, test1.hashCode() == test2.hashCode());
0323: assertEquals(true, test1.hashCode() == test1.hashCode());
0324: assertEquals(true, test2.hashCode() == test2.hashCode());
0325: }
0326:
0327: public void testEqualsHashCodeStrict() {
0328: LocalDate test1 = new LocalDate(1970, 6, 9, StrictChronology
0329: .getInstance(COPTIC_PARIS));
0330: LocalDate test2 = new LocalDate(1970, 6, 9, StrictChronology
0331: .getInstance(COPTIC_PARIS));
0332: assertEquals(true, test1.equals(test2));
0333: assertEquals(true, test2.equals(test1));
0334: assertEquals(true, test1.equals(test1));
0335: assertEquals(true, test2.equals(test2));
0336: assertEquals(true, test1.hashCode() == test2.hashCode());
0337: assertEquals(true, test1.hashCode() == test1.hashCode());
0338: assertEquals(true, test2.hashCode() == test2.hashCode());
0339: }
0340:
0341: //-----------------------------------------------------------------------
0342: public void testCompareTo() {
0343: LocalDate test1 = new LocalDate(2005, 6, 2);
0344: LocalDate test1a = new LocalDate(2005, 6, 2);
0345: assertEquals(0, test1.compareTo(test1a));
0346: assertEquals(0, test1a.compareTo(test1));
0347: assertEquals(0, test1.compareTo(test1));
0348: assertEquals(0, test1a.compareTo(test1a));
0349:
0350: LocalDate test2 = new LocalDate(2005, 7, 2);
0351: assertEquals(-1, test1.compareTo(test2));
0352: assertEquals(+1, test2.compareTo(test1));
0353:
0354: LocalDate test3 = new LocalDate(2005, 7, 2, GregorianChronology
0355: .getInstanceUTC());
0356: assertEquals(-1, test1.compareTo(test3));
0357: assertEquals(+1, test3.compareTo(test1));
0358: assertEquals(0, test3.compareTo(test2));
0359:
0360: DateTimeFieldType[] types = new DateTimeFieldType[] {
0361: DateTimeFieldType.year(),
0362: DateTimeFieldType.monthOfYear(),
0363: DateTimeFieldType.dayOfMonth(), };
0364: int[] values = new int[] { 2005, 6, 2 };
0365: Partial p = new Partial(types, values);
0366: assertEquals(0, test1.compareTo(p));
0367: assertEquals(0, test1.compareTo(new YearMonthDay(2005, 6, 2)));
0368: try {
0369: test1.compareTo(null);
0370: fail();
0371: } catch (NullPointerException ex) {
0372: }
0373: try {
0374: test1.compareTo(new Date());
0375: fail();
0376: } catch (ClassCastException ex) {
0377: }
0378: try {
0379: test1.compareTo(new TimeOfDay());
0380: fail();
0381: } catch (ClassCastException ex) {
0382: }
0383: Partial partial = new Partial().with(
0384: DateTimeFieldType.centuryOfEra(), 1).with(
0385: DateTimeFieldType.halfdayOfDay(), 0).with(
0386: DateTimeFieldType.dayOfMonth(), 9);
0387: try {
0388: new LocalDate(1970, 6, 9).compareTo(partial);
0389: fail();
0390: } catch (ClassCastException ex) {
0391: }
0392: }
0393:
0394: //-----------------------------------------------------------------------
0395: public void testIsEqual_LocalDate() {
0396: LocalDate test1 = new LocalDate(2005, 6, 2);
0397: LocalDate test1a = new LocalDate(2005, 6, 2);
0398: assertEquals(true, test1.isEqual(test1a));
0399: assertEquals(true, test1a.isEqual(test1));
0400: assertEquals(true, test1.isEqual(test1));
0401: assertEquals(true, test1a.isEqual(test1a));
0402:
0403: LocalDate test2 = new LocalDate(2005, 7, 2);
0404: assertEquals(false, test1.isEqual(test2));
0405: assertEquals(false, test2.isEqual(test1));
0406:
0407: LocalDate test3 = new LocalDate(2005, 7, 2, GregorianChronology
0408: .getInstanceUTC());
0409: assertEquals(false, test1.isEqual(test3));
0410: assertEquals(false, test3.isEqual(test1));
0411: assertEquals(true, test3.isEqual(test2));
0412:
0413: try {
0414: new LocalDate(2005, 7, 2).isEqual(null);
0415: fail();
0416: } catch (IllegalArgumentException ex) {
0417: }
0418: }
0419:
0420: //-----------------------------------------------------------------------
0421: public void testIsBefore_LocalDate() {
0422: LocalDate test1 = new LocalDate(2005, 6, 2);
0423: LocalDate test1a = new LocalDate(2005, 6, 2);
0424: assertEquals(false, test1.isBefore(test1a));
0425: assertEquals(false, test1a.isBefore(test1));
0426: assertEquals(false, test1.isBefore(test1));
0427: assertEquals(false, test1a.isBefore(test1a));
0428:
0429: LocalDate test2 = new LocalDate(2005, 7, 2);
0430: assertEquals(true, test1.isBefore(test2));
0431: assertEquals(false, test2.isBefore(test1));
0432:
0433: LocalDate test3 = new LocalDate(2005, 7, 2, GregorianChronology
0434: .getInstanceUTC());
0435: assertEquals(true, test1.isBefore(test3));
0436: assertEquals(false, test3.isBefore(test1));
0437: assertEquals(false, test3.isBefore(test2));
0438:
0439: try {
0440: new LocalDate(2005, 7, 2).isBefore(null);
0441: fail();
0442: } catch (IllegalArgumentException ex) {
0443: }
0444: }
0445:
0446: //-----------------------------------------------------------------------
0447: public void testIsAfter_LocalDate() {
0448: LocalDate test1 = new LocalDate(2005, 6, 2);
0449: LocalDate test1a = new LocalDate(2005, 6, 2);
0450: assertEquals(false, test1.isAfter(test1a));
0451: assertEquals(false, test1a.isAfter(test1));
0452: assertEquals(false, test1.isAfter(test1));
0453: assertEquals(false, test1a.isAfter(test1a));
0454:
0455: LocalDate test2 = new LocalDate(2005, 7, 2);
0456: assertEquals(false, test1.isAfter(test2));
0457: assertEquals(true, test2.isAfter(test1));
0458:
0459: LocalDate test3 = new LocalDate(2005, 7, 2, GregorianChronology
0460: .getInstanceUTC());
0461: assertEquals(false, test1.isAfter(test3));
0462: assertEquals(true, test3.isAfter(test1));
0463: assertEquals(false, test3.isAfter(test2));
0464:
0465: try {
0466: new LocalDate(2005, 7, 2).isAfter(null);
0467: fail();
0468: } catch (IllegalArgumentException ex) {
0469: }
0470: }
0471:
0472: //-----------------------------------------------------------------------
0473: public void testWithField_DateTimeFieldType_int_1() {
0474: LocalDate test = new LocalDate(2004, 6, 9);
0475: LocalDate result = test.withField(DateTimeFieldType.year(),
0476: 2006);
0477:
0478: assertEquals(new LocalDate(2004, 6, 9), test);
0479: assertEquals(new LocalDate(2006, 6, 9), result);
0480: }
0481:
0482: public void testWithField_DateTimeFieldType_int_2() {
0483: LocalDate test = new LocalDate(2004, 6, 9);
0484: try {
0485: test.withField(null, 6);
0486: fail();
0487: } catch (IllegalArgumentException ex) {
0488: }
0489: }
0490:
0491: public void testWithField_DateTimeFieldType_int_3() {
0492: LocalDate test = new LocalDate(2004, 6, 9);
0493: try {
0494: test.withField(DateTimeFieldType.hourOfDay(), 6);
0495: fail();
0496: } catch (IllegalArgumentException ex) {
0497: }
0498: }
0499:
0500: public void testWithField_DateTimeFieldType_int_4() {
0501: LocalDate test = new LocalDate(2004, 6, 9);
0502: LocalDate result = test.withField(DateTimeFieldType.year(),
0503: 2004);
0504: assertEquals(new LocalDate(2004, 6, 9), test);
0505: assertSame(test, result);
0506: }
0507:
0508: //-----------------------------------------------------------------------
0509: public void testWithFieldAdded_DurationFieldType_int_1() {
0510: LocalDate test = new LocalDate(2004, 6, 9);
0511: LocalDate result = test.withFieldAdded(DurationFieldType
0512: .years(), 6);
0513:
0514: assertEquals(new LocalDate(2004, 6, 9), test);
0515: assertEquals(new LocalDate(2010, 6, 9), result);
0516: }
0517:
0518: public void testWithFieldAdded_DurationFieldType_int_2() {
0519: LocalDate test = new LocalDate(2004, 6, 9);
0520: try {
0521: test.withFieldAdded(null, 0);
0522: fail();
0523: } catch (IllegalArgumentException ex) {
0524: }
0525: }
0526:
0527: public void testWithFieldAdded_DurationFieldType_int_3() {
0528: LocalDate test = new LocalDate(2004, 6, 9);
0529: try {
0530: test.withFieldAdded(null, 6);
0531: fail();
0532: } catch (IllegalArgumentException ex) {
0533: }
0534: }
0535:
0536: public void testWithFieldAdded_DurationFieldType_int_4() {
0537: LocalDate test = new LocalDate(2004, 6, 9);
0538: LocalDate result = test.withFieldAdded(DurationFieldType
0539: .years(), 0);
0540: assertSame(test, result);
0541: }
0542:
0543: public void testWithFieldAdded_DurationFieldType_int_5() {
0544: LocalDate test = new LocalDate(2004, 6, 9);
0545: try {
0546: test.withFieldAdded(DurationFieldType.hours(), 6);
0547: fail();
0548: } catch (IllegalArgumentException ex) {
0549: }
0550: }
0551:
0552: //-----------------------------------------------------------------------
0553: public void testPlus_RP() {
0554: LocalDate test = new LocalDate(2002, 5, 3, BUDDHIST_LONDON);
0555: LocalDate result = test
0556: .plus(new Period(1, 2, 3, 4, 29, 6, 7, 8));
0557: LocalDate expected = new LocalDate(2003, 7, 28, BUDDHIST_LONDON);
0558: assertEquals(expected, result);
0559:
0560: result = test.plus((ReadablePeriod) null);
0561: assertSame(test, result);
0562: }
0563:
0564: public void testPlusYears_int() {
0565: LocalDate test = new LocalDate(2002, 5, 3, BUDDHIST_LONDON);
0566: LocalDate result = test.plusYears(1);
0567: LocalDate expected = new LocalDate(2003, 5, 3, BUDDHIST_LONDON);
0568: assertEquals(expected, result);
0569:
0570: result = test.plusYears(0);
0571: assertSame(test, result);
0572: }
0573:
0574: public void testPlusMonths_int() {
0575: LocalDate test = new LocalDate(2002, 5, 3, BUDDHIST_LONDON);
0576: LocalDate result = test.plusMonths(1);
0577: LocalDate expected = new LocalDate(2002, 6, 3, BUDDHIST_LONDON);
0578: assertEquals(expected, result);
0579:
0580: result = test.plusMonths(0);
0581: assertSame(test, result);
0582: }
0583:
0584: public void testPlusWeeks_int() {
0585: LocalDate test = new LocalDate(2002, 5, 3, BUDDHIST_LONDON);
0586: LocalDate result = test.plusWeeks(1);
0587: LocalDate expected = new LocalDate(2002, 5, 10, BUDDHIST_LONDON);
0588: assertEquals(expected, result);
0589:
0590: result = test.plusWeeks(0);
0591: assertSame(test, result);
0592: }
0593:
0594: public void testPlusDays_int() {
0595: LocalDate test = new LocalDate(2002, 5, 3, BUDDHIST_LONDON);
0596: LocalDate result = test.plusDays(1);
0597: LocalDate expected = new LocalDate(2002, 5, 4, BUDDHIST_LONDON);
0598: assertEquals(expected, result);
0599:
0600: result = test.plusDays(0);
0601: assertSame(test, result);
0602: }
0603:
0604: //-----------------------------------------------------------------------
0605: public void testMinus_RP() {
0606: LocalDate test = new LocalDate(2002, 5, 3, BUDDHIST_LONDON);
0607: LocalDate result = test
0608: .minus(new Period(1, 1, 1, 1, 1, 1, 1, 1));
0609:
0610: // TODO breaks because it subtracts millis now, and thus goes
0611: // into the previous day
0612:
0613: LocalDate expected = new LocalDate(2001, 3, 26, BUDDHIST_LONDON);
0614: assertEquals(expected, result);
0615:
0616: result = test.minus((ReadablePeriod) null);
0617: assertSame(test, result);
0618: }
0619:
0620: public void testMinusYears_int() {
0621: LocalDate test = new LocalDate(2002, 5, 3, BUDDHIST_LONDON);
0622: LocalDate result = test.minusYears(1);
0623: LocalDate expected = new LocalDate(2001, 5, 3, BUDDHIST_LONDON);
0624: assertEquals(expected, result);
0625:
0626: result = test.minusYears(0);
0627: assertSame(test, result);
0628: }
0629:
0630: public void testMinusMonths_int() {
0631: LocalDate test = new LocalDate(2002, 5, 3, BUDDHIST_LONDON);
0632: LocalDate result = test.minusMonths(1);
0633: LocalDate expected = new LocalDate(2002, 4, 3, BUDDHIST_LONDON);
0634: assertEquals(expected, result);
0635:
0636: result = test.minusMonths(0);
0637: assertSame(test, result);
0638: }
0639:
0640: public void testMinusWeeks_int() {
0641: LocalDate test = new LocalDate(2002, 5, 3, BUDDHIST_LONDON);
0642: LocalDate result = test.minusWeeks(1);
0643: LocalDate expected = new LocalDate(2002, 4, 26, BUDDHIST_LONDON);
0644: assertEquals(expected, result);
0645:
0646: result = test.minusWeeks(0);
0647: assertSame(test, result);
0648: }
0649:
0650: public void testMinusDays_int() {
0651: LocalDate test = new LocalDate(2002, 5, 3, BUDDHIST_LONDON);
0652: LocalDate result = test.minusDays(1);
0653: LocalDate expected = new LocalDate(2002, 5, 2, BUDDHIST_LONDON);
0654: assertEquals(expected, result);
0655:
0656: result = test.minusDays(0);
0657: assertSame(test, result);
0658: }
0659:
0660: //-----------------------------------------------------------------------
0661: public void testGetters() {
0662: LocalDate test = new LocalDate(1970, 6, 9, GJ_UTC);
0663: assertEquals(1970, test.getYear());
0664: assertEquals(6, test.getMonthOfYear());
0665: assertEquals(9, test.getDayOfMonth());
0666: assertEquals(160, test.getDayOfYear());
0667: assertEquals(2, test.getDayOfWeek());
0668: assertEquals(24, test.getWeekOfWeekyear());
0669: assertEquals(1970, test.getWeekyear());
0670: assertEquals(70, test.getYearOfCentury());
0671: assertEquals(20, test.getCenturyOfEra());
0672: assertEquals(1970, test.getYearOfEra());
0673: assertEquals(DateTimeConstants.AD, test.getEra());
0674: }
0675:
0676: //-----------------------------------------------------------------------
0677: public void testWithers() {
0678: LocalDate test = new LocalDate(1970, 6, 9, GJ_UTC);
0679: check(test.withYear(2000), 2000, 6, 9);
0680: check(test.withMonthOfYear(2), 1970, 2, 9);
0681: check(test.withDayOfMonth(2), 1970, 6, 2);
0682: check(test.withDayOfYear(6), 1970, 1, 6);
0683: check(test.withDayOfWeek(6), 1970, 6, 13);
0684: check(test.withWeekOfWeekyear(6), 1970, 2, 3);
0685: check(test.withWeekyear(1971), 1971, 6, 15);
0686: check(test.withYearOfCentury(60), 1960, 6, 9);
0687: check(test.withCenturyOfEra(21), 2070, 6, 9);
0688: check(test.withYearOfEra(1066), 1066, 6, 9);
0689: check(test.withEra(DateTimeConstants.BC), -1970, 6, 9);
0690: try {
0691: test.withMonthOfYear(0);
0692: fail();
0693: } catch (IllegalArgumentException ex) {
0694: }
0695: try {
0696: test.withMonthOfYear(13);
0697: fail();
0698: } catch (IllegalArgumentException ex) {
0699: }
0700: }
0701:
0702: //-----------------------------------------------------------------------
0703: public void testToDateTimeAtStartOfDay() {
0704: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS);
0705:
0706: DateTime test = base.toDateTimeAtStartOfDay();
0707: check(base, 2005, 6, 9);
0708: assertEquals(
0709: new DateTime(2005, 6, 9, 0, 0, 0, 0, COPTIC_LONDON),
0710: test);
0711: }
0712:
0713: public void testToDateTimeAtStartOfDay_avoidDST() {
0714: LocalDate base = new LocalDate(2007, 4, 1);
0715:
0716: DateTimeZone.setDefault(MOCK_GAZA);
0717: DateTime test = base.toDateTimeAtStartOfDay();
0718: check(base, 2007, 4, 1);
0719: assertEquals(new DateTime(2007, 4, 1, 1, 0, 0, 0, MOCK_GAZA),
0720: test);
0721: }
0722:
0723: //-----------------------------------------------------------------------
0724: public void testToDateTimeAtStartOfDay_Zone() {
0725: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS);
0726:
0727: DateTime test = base.toDateTimeAtStartOfDay(TOKYO);
0728: check(base, 2005, 6, 9);
0729: assertEquals(
0730: new DateTime(2005, 6, 9, 0, 0, 0, 0, COPTIC_TOKYO),
0731: test);
0732: }
0733:
0734: public void testToDateTimeAtStartOfDay_Zone_avoidDST() {
0735: LocalDate base = new LocalDate(2007, 4, 1);
0736:
0737: DateTime test = base.toDateTimeAtStartOfDay(MOCK_GAZA);
0738: check(base, 2007, 4, 1);
0739: assertEquals(new DateTime(2007, 4, 1, 1, 0, 0, 0, MOCK_GAZA),
0740: test);
0741: }
0742:
0743: public void testToDateTimeAtStartOfDay_nullZone() {
0744: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS);
0745:
0746: DateTime test = base
0747: .toDateTimeAtStartOfDay((DateTimeZone) null);
0748: check(base, 2005, 6, 9);
0749: assertEquals(
0750: new DateTime(2005, 6, 9, 0, 0, 0, 0, COPTIC_LONDON),
0751: test);
0752: }
0753:
0754: //-----------------------------------------------------------------------
0755: public void testToDateTimeAtMidnight() {
0756: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS);
0757:
0758: DateTime test = base.toDateTimeAtMidnight();
0759: check(base, 2005, 6, 9);
0760: assertEquals(
0761: new DateTime(2005, 6, 9, 0, 0, 0, 0, COPTIC_LONDON),
0762: test);
0763: }
0764:
0765: //-----------------------------------------------------------------------
0766: public void testToDateTimeAtMidnight_Zone() {
0767: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS);
0768:
0769: DateTime test = base.toDateTimeAtMidnight(TOKYO);
0770: check(base, 2005, 6, 9);
0771: assertEquals(
0772: new DateTime(2005, 6, 9, 0, 0, 0, 0, COPTIC_TOKYO),
0773: test);
0774: }
0775:
0776: public void testToDateTimeAtMidnight_nullZone() {
0777: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS);
0778:
0779: DateTime test = base.toDateTimeAtMidnight((DateTimeZone) null);
0780: check(base, 2005, 6, 9);
0781: assertEquals(
0782: new DateTime(2005, 6, 9, 0, 0, 0, 0, COPTIC_LONDON),
0783: test);
0784: }
0785:
0786: //-----------------------------------------------------------------------
0787: public void testToDateTimeAtCurrentTime() {
0788: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
0789: DateTime dt = new DateTime(2004, 6, 9, 6, 7, 8, 9);
0790: DateTimeUtils.setCurrentMillisFixed(dt.getMillis());
0791:
0792: DateTime test = base.toDateTimeAtCurrentTime();
0793: check(base, 2005, 6, 9);
0794: DateTime expected = new DateTime(dt.getMillis(), COPTIC_LONDON);
0795: expected = expected.year().setCopy(2005);
0796: expected = expected.monthOfYear().setCopy(6);
0797: expected = expected.dayOfMonth().setCopy(9);
0798: assertEquals(expected, test);
0799: }
0800:
0801: //-----------------------------------------------------------------------
0802: public void testToDateTimeAtCurrentTime_Zone() {
0803: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
0804: DateTime dt = new DateTime(2004, 6, 9, 6, 7, 8, 9);
0805: DateTimeUtils.setCurrentMillisFixed(dt.getMillis());
0806:
0807: DateTime test = base.toDateTimeAtCurrentTime(TOKYO);
0808: check(base, 2005, 6, 9);
0809: DateTime expected = new DateTime(dt.getMillis(), COPTIC_TOKYO);
0810: expected = expected.year().setCopy(2005);
0811: expected = expected.monthOfYear().setCopy(6);
0812: expected = expected.dayOfMonth().setCopy(9);
0813: assertEquals(expected, test);
0814: }
0815:
0816: public void testToDateTimeAtCurrentTime_nullZone() {
0817: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
0818: DateTime dt = new DateTime(2004, 6, 9, 6, 7, 8, 9);
0819: DateTimeUtils.setCurrentMillisFixed(dt.getMillis());
0820:
0821: DateTime test = base
0822: .toDateTimeAtCurrentTime((DateTimeZone) null);
0823: check(base, 2005, 6, 9);
0824: DateTime expected = new DateTime(dt.getMillis(), COPTIC_LONDON);
0825: expected = expected.year().setCopy(2005);
0826: expected = expected.monthOfYear().setCopy(6);
0827: expected = expected.dayOfMonth().setCopy(9);
0828: assertEquals(expected, test);
0829: }
0830:
0831: //-----------------------------------------------------------------------
0832: public void testToLocalDateTime_LocalTime() {
0833: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
0834: LocalTime tod = new LocalTime(12, 13, 14, 15, COPTIC_TOKYO);
0835:
0836: LocalDateTime test = base.toLocalDateTime(tod);
0837: check(base, 2005, 6, 9);
0838: LocalDateTime expected = new LocalDateTime(2005, 6, 9, 12, 13,
0839: 14, 15, COPTIC_UTC);
0840: assertEquals(expected, test);
0841: }
0842:
0843: public void testToLocalDateTime_nullLocalTime() {
0844: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
0845:
0846: try {
0847: base.toLocalDateTime((LocalTime) null);
0848: fail();
0849: } catch (IllegalArgumentException ex) {
0850: // expected
0851: }
0852: }
0853:
0854: public void testToLocalDateTime_wrongChronologyLocalTime() {
0855: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
0856: LocalTime tod = new LocalTime(12, 13, 14, 15, BUDDHIST_PARIS); // PARIS irrelevant
0857:
0858: try {
0859: base.toLocalDateTime(tod);
0860: fail();
0861: } catch (IllegalArgumentException ex) {
0862: // expected
0863: }
0864: }
0865:
0866: //-----------------------------------------------------------------------
0867: public void testToDateTime_LocalTime() {
0868: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
0869: LocalTime tod = new LocalTime(12, 13, 14, 15, COPTIC_TOKYO);
0870:
0871: DateTime test = base.toDateTime(tod);
0872: check(base, 2005, 6, 9);
0873: DateTime expected = new DateTime(2005, 6, 9, 12, 13, 14, 15,
0874: COPTIC_LONDON);
0875: assertEquals(expected, test);
0876: }
0877:
0878: public void testToDateTime_nullLocalTime() {
0879: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
0880: long now = new DateTime(2004, 5, 8, 12, 13, 14, 15,
0881: COPTIC_LONDON).getMillis();
0882: DateTimeUtils.setCurrentMillisFixed(now);
0883:
0884: DateTime test = base.toDateTime((LocalTime) null);
0885: check(base, 2005, 6, 9);
0886: DateTime expected = new DateTime(2005, 6, 9, 12, 13, 14, 15,
0887: COPTIC_LONDON);
0888: assertEquals(expected, test);
0889: }
0890:
0891: //-----------------------------------------------------------------------
0892: public void testToDateTime_LocalTime_Zone() {
0893: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
0894: LocalTime tod = new LocalTime(12, 13, 14, 15, COPTIC_TOKYO);
0895:
0896: DateTime test = base.toDateTime(tod, TOKYO);
0897: check(base, 2005, 6, 9);
0898: DateTime expected = new DateTime(2005, 6, 9, 12, 13, 14, 15,
0899: COPTIC_TOKYO);
0900: assertEquals(expected, test);
0901: }
0902:
0903: public void testToDateTime_LocalTime_nullZone() {
0904: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
0905: LocalTime tod = new LocalTime(12, 13, 14, 15, COPTIC_TOKYO);
0906:
0907: DateTime test = base.toDateTime(tod, null);
0908: check(base, 2005, 6, 9);
0909: DateTime expected = new DateTime(2005, 6, 9, 12, 13, 14, 15,
0910: COPTIC_LONDON);
0911: assertEquals(expected, test);
0912: }
0913:
0914: public void testToDateTime_nullLocalTime_Zone() {
0915: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
0916: long now = new DateTime(2004, 5, 8, 12, 13, 14, 15,
0917: COPTIC_TOKYO).getMillis();
0918: DateTimeUtils.setCurrentMillisFixed(now);
0919:
0920: DateTime test = base.toDateTime((LocalTime) null, TOKYO);
0921: check(base, 2005, 6, 9);
0922: DateTime expected = new DateTime(2005, 6, 9, 12, 13, 14, 15,
0923: COPTIC_TOKYO);
0924: assertEquals(expected, test);
0925: }
0926:
0927: public void testToDateTime_wrongChronoLocalTime_Zone() {
0928: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
0929: LocalTime tod = new LocalTime(12, 13, 14, 15, BUDDHIST_TOKYO);
0930:
0931: try {
0932: base.toDateTime(tod, LONDON);
0933: fail();
0934: } catch (IllegalArgumentException ex) {
0935: }
0936: }
0937:
0938: //-----------------------------------------------------------------------
0939: public void testToDateMidnight() {
0940: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS);
0941:
0942: DateMidnight test = base.toDateMidnight();
0943: check(base, 2005, 6, 9);
0944: assertEquals(new DateMidnight(2005, 6, 9, COPTIC_LONDON), test);
0945: }
0946:
0947: //-----------------------------------------------------------------------
0948: public void testToDateMidnight_Zone() {
0949: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS);
0950:
0951: DateMidnight test = base.toDateMidnight(TOKYO);
0952: check(base, 2005, 6, 9);
0953: assertEquals(new DateMidnight(2005, 6, 9, COPTIC_TOKYO), test);
0954: }
0955:
0956: public void testToDateMidnight_nullZone() {
0957: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS);
0958:
0959: DateMidnight test = base.toDateMidnight((DateTimeZone) null);
0960: check(base, 2005, 6, 9);
0961: assertEquals(new DateMidnight(2005, 6, 9, COPTIC_LONDON), test);
0962: }
0963:
0964: //-----------------------------------------------------------------------
0965: public void testToDateTime_RI() {
0966: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS);
0967: DateTime dt = new DateTime(2002, 1, 3, 4, 5, 6, 7);
0968:
0969: DateTime test = base.toDateTime(dt);
0970: check(base, 2005, 6, 9);
0971: DateTime expected = dt;
0972: expected = expected.year().setCopy(2005);
0973: expected = expected.monthOfYear().setCopy(6);
0974: expected = expected.dayOfMonth().setCopy(9);
0975: assertEquals(expected, test);
0976: }
0977:
0978: public void testToDateTime_nullRI() {
0979: LocalDate base = new LocalDate(2005, 6, 9);
0980: DateTime dt = new DateTime(2002, 1, 3, 4, 5, 6, 7);
0981: DateTimeUtils.setCurrentMillisFixed(dt.getMillis());
0982:
0983: DateTime test = base.toDateTime((ReadableInstant) null);
0984: check(base, 2005, 6, 9);
0985: DateTime expected = dt;
0986: expected = expected.year().setCopy(2005);
0987: expected = expected.monthOfYear().setCopy(6);
0988: expected = expected.dayOfMonth().setCopy(9);
0989: assertEquals(expected, test);
0990: }
0991:
0992: //-----------------------------------------------------------------------
0993: public void testToInterval() {
0994: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
0995: Interval test = base.toInterval();
0996: check(base, 2005, 6, 9);
0997: DateTime start = base.toDateTimeAtMidnight();
0998: DateTime end = start.plus(Period.days(1));
0999: Interval expected = new Interval(start, end);
1000: assertEquals(expected, test);
1001: }
1002:
1003: //-----------------------------------------------------------------------
1004: public void testToInterval_Zone() {
1005: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
1006: Interval test = base.toInterval(TOKYO);
1007: check(base, 2005, 6, 9);
1008: DateTime start = base.toDateTimeAtMidnight(TOKYO);
1009: DateTime end = start.plus(Period.days(1));
1010: Interval expected = new Interval(start, end);
1011: assertEquals(expected, test);
1012: }
1013:
1014: public void testToInterval_nullZone() {
1015: LocalDate base = new LocalDate(2005, 6, 9, COPTIC_PARIS); // PARIS irrelevant
1016: Interval test = base.toInterval(null);
1017: check(base, 2005, 6, 9);
1018: DateTime start = base.toDateTimeAtMidnight(LONDON);
1019: DateTime end = start.plus(Period.days(1));
1020: Interval expected = new Interval(start, end);
1021: assertEquals(expected, test);
1022: }
1023:
1024: //-----------------------------------------------------------------------
1025: public void testProperty() {
1026: LocalDate test = new LocalDate(2005, 6, 9, GJ_UTC);
1027: assertEquals(test.year(), test.property(DateTimeFieldType
1028: .year()));
1029: assertEquals(test.monthOfYear(), test
1030: .property(DateTimeFieldType.monthOfYear()));
1031: assertEquals(test.dayOfMonth(), test.property(DateTimeFieldType
1032: .dayOfMonth()));
1033: assertEquals(test.dayOfWeek(), test.property(DateTimeFieldType
1034: .dayOfWeek()));
1035: assertEquals(test.dayOfYear(), test.property(DateTimeFieldType
1036: .dayOfYear()));
1037: assertEquals(test.weekOfWeekyear(), test
1038: .property(DateTimeFieldType.weekOfWeekyear()));
1039: assertEquals(test.weekyear(), test.property(DateTimeFieldType
1040: .weekyear()));
1041: assertEquals(test.yearOfCentury(), test
1042: .property(DateTimeFieldType.yearOfCentury()));
1043: assertEquals(test.yearOfEra(), test.property(DateTimeFieldType
1044: .yearOfEra()));
1045: assertEquals(test.centuryOfEra(), test
1046: .property(DateTimeFieldType.centuryOfEra()));
1047: assertEquals(test.era(), test.property(DateTimeFieldType.era()));
1048: try {
1049: test.property(DateTimeFieldType.millisOfDay());
1050: fail();
1051: } catch (IllegalArgumentException ex) {
1052: }
1053: try {
1054: test.property(null);
1055: fail();
1056: } catch (IllegalArgumentException ex) {
1057: }
1058: }
1059:
1060: //-----------------------------------------------------------------------
1061: public void testSerialization() throws Exception {
1062: LocalDate test = new LocalDate(1972, 6, 9, COPTIC_PARIS);
1063:
1064: ByteArrayOutputStream baos = new ByteArrayOutputStream();
1065: ObjectOutputStream oos = new ObjectOutputStream(baos);
1066: oos.writeObject(test);
1067: byte[] bytes = baos.toByteArray();
1068: oos.close();
1069:
1070: ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
1071: ObjectInputStream ois = new ObjectInputStream(bais);
1072: LocalDate result = (LocalDate) ois.readObject();
1073: ois.close();
1074:
1075: assertEquals(test, result);
1076: assertTrue(Arrays.equals(test.getValues(), result.getValues()));
1077: assertTrue(Arrays.equals(test.getFields(), result.getFields()));
1078: assertEquals(test.getChronology(), result.getChronology());
1079: }
1080:
1081: //-----------------------------------------------------------------------
1082: public void testToString() {
1083: LocalDate test = new LocalDate(2002, 6, 9);
1084: assertEquals("2002-06-09", test.toString());
1085: }
1086:
1087: //-----------------------------------------------------------------------
1088: public void testToString_String() {
1089: LocalDate test = new LocalDate(2002, 6, 9);
1090: assertEquals("2002 \ufffd\ufffd", test.toString("yyyy HH"));
1091: assertEquals("2002-06-09", test.toString((String) null));
1092: }
1093:
1094: //-----------------------------------------------------------------------
1095: public void testToString_String_Locale() {
1096: LocalDate test = new LocalDate(1970, 6, 9);
1097: assertEquals("Tue 9/6", test
1098: .toString("EEE d/M", Locale.ENGLISH));
1099: assertEquals("mar. 9/6", test
1100: .toString("EEE d/M", Locale.FRENCH));
1101: assertEquals("1970-06-09", test.toString(null, Locale.ENGLISH));
1102: assertEquals("Tue 9/6", test.toString("EEE d/M", null));
1103: assertEquals("1970-06-09", test.toString(null, null));
1104: }
1105:
1106: //-----------------------------------------------------------------------
1107: public void testToString_DTFormatter() {
1108: LocalDate test = new LocalDate(2002, 6, 9);
1109: assertEquals("2002 \ufffd\ufffd", test.toString(DateTimeFormat
1110: .forPattern("yyyy HH")));
1111: assertEquals("2002-06-09", test
1112: .toString((DateTimeFormatter) null));
1113: }
1114:
1115: //-----------------------------------------------------------------------
1116: private void check(LocalDate test, int hour, int min, int sec) {
1117: assertEquals(hour, test.getYear());
1118: assertEquals(min, test.getMonthOfYear());
1119: assertEquals(sec, test.getDayOfMonth());
1120: }
1121: }
|