001: /*
002: * Copyright 2001-2005 Stephen Colebourne
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.joda.time;
017:
018: import java.util.Locale;
019:
020: import junit.framework.TestCase;
021: import junit.framework.TestSuite;
022:
023: import org.joda.time.chrono.CopticChronology;
024: import org.joda.time.chrono.LenientChronology;
025: import org.joda.time.chrono.StrictChronology;
026:
027: /**
028: * This class is a Junit unit test for DateTime.
029: *
030: * @author Stephen Colebourne
031: * @author Mike Schrag
032: */
033: public class TestDateMidnight_Properties extends TestCase {
034: // Test in 2002/03 as time zones are more well known
035: // (before the late 90's they were all over the place)
036:
037: private static final DateTimeZone PARIS = DateTimeZone
038: .forID("Europe/Paris");
039: private static final Chronology COPTIC_PARIS = CopticChronology
040: .getInstance(PARIS);
041:
042: //private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
043: private static final DateTimeZone LONDON = DateTimeZone
044: .forID("Europe/London");
045:
046: long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
047: + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365
048: + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
049: + 365 + 365 + 366 + 365;
050: long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
051: + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365
052: + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
053: + 365 + 365 + 366 + 365 + 365;
054:
055: // 2002-06-09
056: private long TEST_TIME_NOW = (y2002days + 31L + 28L + 31L + 30L
057: + 31L + 9L - 1L)
058: * DateTimeConstants.MILLIS_PER_DAY;
059:
060: // 2002-04-05 Fri
061: private long TEST_TIME1 = (y2002days + 31L + 28L + 31L + 5L - 1L)
062: * DateTimeConstants.MILLIS_PER_DAY + 12L
063: * DateTimeConstants.MILLIS_PER_HOUR + 24L
064: * DateTimeConstants.MILLIS_PER_MINUTE;
065:
066: // 2003-05-06 Tue
067: private long TEST_TIME2 = (y2003days + 31L + 28L + 31L + 30L + 6L - 1L)
068: * DateTimeConstants.MILLIS_PER_DAY
069: + 14L
070: * DateTimeConstants.MILLIS_PER_HOUR
071: + 28L
072: * DateTimeConstants.MILLIS_PER_MINUTE;
073:
074: private DateTimeZone zone = null;
075: private Locale locale = null;
076:
077: public static void main(String[] args) {
078: junit.textui.TestRunner.run(suite());
079: }
080:
081: public static TestSuite suite() {
082: return new TestSuite(TestDateMidnight_Properties.class);
083: }
084:
085: public TestDateMidnight_Properties(String name) {
086: super (name);
087: }
088:
089: protected void setUp() throws Exception {
090: DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
091: zone = DateTimeZone.getDefault();
092: locale = Locale.getDefault();
093: DateTimeZone.setDefault(LONDON);
094: Locale.setDefault(Locale.UK);
095: }
096:
097: protected void tearDown() throws Exception {
098: DateTimeUtils.setCurrentMillisSystem();
099: DateTimeZone.setDefault(zone);
100: Locale.setDefault(locale);
101: zone = null;
102: }
103:
104: //-----------------------------------------------------------------------
105: public void testTest() {
106: assertEquals("2002-06-09T00:00:00.000Z", new Instant(
107: TEST_TIME_NOW).toString());
108: assertEquals("2002-04-05T12:24:00.000Z",
109: new Instant(TEST_TIME1).toString());
110: assertEquals("2003-05-06T14:28:00.000Z",
111: new Instant(TEST_TIME2).toString());
112: }
113:
114: //-----------------------------------------------------------------------
115: public void testPropertyGetEra() {
116: DateMidnight test = new DateMidnight(2004, 6, 9);
117: assertSame(test.getChronology().era(), test.era().getField());
118: assertEquals("era", test.era().getName());
119: assertEquals("Property[era]", test.era().toString());
120: assertSame(test, test.era().getDateMidnight());
121: assertEquals(1, test.era().get());
122: assertEquals("AD", test.era().getAsText());
123: assertEquals("ap. J.-C.", test.era().getAsText(Locale.FRENCH));
124: assertEquals("AD", test.era().getAsShortText());
125: assertEquals("ap. J.-C.", test.era().getAsShortText(
126: Locale.FRENCH));
127: assertEquals(test.getChronology().eras(), test.era()
128: .getDurationField());
129: assertEquals(null, test.era().getRangeDurationField());
130: assertEquals(2, test.era().getMaximumTextLength(null));
131: assertEquals(9, test.era().getMaximumTextLength(Locale.FRENCH));
132: assertEquals(2, test.era().getMaximumShortTextLength(null));
133: assertEquals(9, test.era().getMaximumShortTextLength(
134: Locale.FRENCH));
135: }
136:
137: //-----------------------------------------------------------------------
138: public void testPropertyGetYearOfEra() {
139: DateMidnight test = new DateMidnight(2004, 6, 9);
140: assertSame(test.getChronology().yearOfEra(), test.yearOfEra()
141: .getField());
142: assertEquals("yearOfEra", test.yearOfEra().getName());
143: assertEquals("Property[yearOfEra]", test.yearOfEra().toString());
144: assertSame(test, test.yearOfEra().getDateMidnight());
145: assertEquals(2004, test.yearOfEra().get());
146: assertEquals("2004", test.yearOfEra().getAsText());
147: assertEquals("2004", test.yearOfEra().getAsText(Locale.FRENCH));
148: assertEquals("2004", test.yearOfEra().getAsShortText());
149: assertEquals("2004", test.yearOfEra().getAsShortText(
150: Locale.FRENCH));
151: assertEquals(test.getChronology().years(), test.yearOfEra()
152: .getDurationField());
153: assertEquals(null, test.yearOfEra().getRangeDurationField());
154: assertEquals(9, test.yearOfEra().getMaximumTextLength(null));
155: assertEquals(9, test.yearOfEra()
156: .getMaximumShortTextLength(null));
157: }
158:
159: //-----------------------------------------------------------------------
160: public void testPropertyGetCenturyOfEra() {
161: DateMidnight test = new DateMidnight(2004, 6, 9);
162: assertSame(test.getChronology().centuryOfEra(), test
163: .centuryOfEra().getField());
164: assertEquals("centuryOfEra", test.centuryOfEra().getName());
165: assertEquals("Property[centuryOfEra]", test.centuryOfEra()
166: .toString());
167: assertSame(test, test.centuryOfEra().getDateMidnight());
168: assertEquals(20, test.centuryOfEra().get());
169: assertEquals("20", test.centuryOfEra().getAsText());
170: assertEquals("20", test.centuryOfEra().getAsText(Locale.FRENCH));
171: assertEquals("20", test.centuryOfEra().getAsShortText());
172: assertEquals("20", test.centuryOfEra().getAsShortText(
173: Locale.FRENCH));
174: assertEquals(test.getChronology().centuries(), test
175: .centuryOfEra().getDurationField());
176: assertEquals(null, test.centuryOfEra().getRangeDurationField());
177: assertEquals(7, test.centuryOfEra().getMaximumTextLength(null));
178: assertEquals(7, test.centuryOfEra().getMaximumShortTextLength(
179: null));
180: }
181:
182: //-----------------------------------------------------------------------
183: public void testPropertyGetYearOfCentury() {
184: DateMidnight test = new DateMidnight(2004, 6, 9);
185: assertSame(test.getChronology().yearOfCentury(), test
186: .yearOfCentury().getField());
187: assertEquals("yearOfCentury", test.yearOfCentury().getName());
188: assertEquals("Property[yearOfCentury]", test.yearOfCentury()
189: .toString());
190: assertSame(test, test.yearOfCentury().getDateMidnight());
191: assertEquals(4, test.yearOfCentury().get());
192: assertEquals("4", test.yearOfCentury().getAsText());
193: assertEquals("4", test.yearOfCentury().getAsText(Locale.FRENCH));
194: assertEquals("4", test.yearOfCentury().getAsShortText());
195: assertEquals("4", test.yearOfCentury().getAsShortText(
196: Locale.FRENCH));
197: assertEquals(test.getChronology().years(), test.yearOfCentury()
198: .getDurationField());
199: assertEquals(test.getChronology().centuries(), test
200: .yearOfCentury().getRangeDurationField());
201: assertEquals(2, test.yearOfCentury().getMaximumTextLength(null));
202: assertEquals(2, test.yearOfCentury().getMaximumShortTextLength(
203: null));
204: }
205:
206: //-----------------------------------------------------------------------
207: public void testPropertyGetWeekyear() {
208: DateMidnight test = new DateMidnight(2004, 6, 9);
209: assertSame(test.getChronology().weekyear(), test.weekyear()
210: .getField());
211: assertEquals("weekyear", test.weekyear().getName());
212: assertEquals("Property[weekyear]", test.weekyear().toString());
213: assertSame(test, test.weekyear().getDateMidnight());
214: assertEquals(2004, test.weekyear().get());
215: assertEquals("2004", test.weekyear().getAsText());
216: assertEquals("2004", test.weekyear().getAsText(Locale.FRENCH));
217: assertEquals("2004", test.weekyear().getAsShortText());
218: assertEquals("2004", test.weekyear().getAsShortText(
219: Locale.FRENCH));
220: assertEquals(test.getChronology().weekyears(), test.weekyear()
221: .getDurationField());
222: assertEquals(null, test.weekyear().getRangeDurationField());
223: assertEquals(9, test.weekyear().getMaximumTextLength(null));
224: assertEquals(9, test.weekyear().getMaximumShortTextLength(null));
225: }
226:
227: //-----------------------------------------------------------------------
228: public void testPropertyGetYear() {
229: DateMidnight test = new DateMidnight(2004, 6, 9);
230: assertSame(test.getChronology().year(), test.year().getField());
231: assertEquals("year", test.year().getName());
232: assertEquals("Property[year]", test.year().toString());
233: assertSame(test, test.year().getDateMidnight());
234: assertEquals(2004, test.year().get());
235: assertEquals("2004", test.year().getAsText());
236: assertEquals("2004", test.year().getAsText(Locale.FRENCH));
237: assertEquals("2004", test.year().getAsShortText());
238: assertEquals("2004", test.year().getAsShortText(Locale.FRENCH));
239: assertEquals(test.getChronology().years(), test.year()
240: .getDurationField());
241: assertEquals(null, test.year().getRangeDurationField());
242: assertEquals(9, test.year().getMaximumTextLength(null));
243: assertEquals(9, test.year().getMaximumShortTextLength(null));
244: assertEquals(-292275054, test.year().getMinimumValue());
245: assertEquals(-292275054, test.year().getMinimumValueOverall());
246: assertEquals(292278993, test.year().getMaximumValue());
247: assertEquals(292278993, test.year().getMaximumValueOverall());
248: }
249:
250: //-----------------------------------------------------------------------
251: public void testPropertyGetMonthOfYear() {
252: DateMidnight test = new DateMidnight(2004, 6, 9);
253: assertSame(test.getChronology().monthOfYear(), test
254: .monthOfYear().getField());
255: assertEquals("monthOfYear", test.monthOfYear().getName());
256: assertEquals("Property[monthOfYear]", test.monthOfYear()
257: .toString());
258: assertSame(test, test.monthOfYear().getDateMidnight());
259: assertEquals(6, test.monthOfYear().get());
260: assertEquals("6", test.monthOfYear().getAsString());
261: assertEquals("June", test.monthOfYear().getAsText());
262: assertEquals("juin", test.monthOfYear()
263: .getAsText(Locale.FRENCH));
264: assertEquals("Jun", test.monthOfYear().getAsShortText());
265: assertEquals("juin", test.monthOfYear().getAsShortText(
266: Locale.FRENCH));
267: assertEquals(test.getChronology().months(), test.monthOfYear()
268: .getDurationField());
269: assertEquals(test.getChronology().years(), test.monthOfYear()
270: .getRangeDurationField());
271: assertEquals(9, test.monthOfYear().getMaximumTextLength(null));
272: assertEquals(3, test.monthOfYear().getMaximumShortTextLength(
273: null));
274: test = new DateMidnight(2004, 7, 9);
275: assertEquals("juillet", test.monthOfYear().getAsText(
276: Locale.FRENCH));
277: assertEquals("juil.", test.monthOfYear().getAsShortText(
278: Locale.FRENCH));
279: assertEquals(1, test.monthOfYear().getMinimumValue());
280: assertEquals(1, test.monthOfYear().getMinimumValueOverall());
281: assertEquals(12, test.monthOfYear().getMaximumValue());
282: assertEquals(12, test.monthOfYear().getMaximumValueOverall());
283: assertEquals(1, test.monthOfYear().getMinimumValue());
284: assertEquals(1, test.monthOfYear().getMinimumValueOverall());
285: assertEquals(12, test.monthOfYear().getMaximumValue());
286: assertEquals(12, test.monthOfYear().getMaximumValueOverall());
287: }
288:
289: public void testPropertySetMonthOfYear() {
290: DateMidnight test = new DateMidnight(2004, 6, 9);
291: DateMidnight copy = test.monthOfYear().setCopy(8);
292: assertEquals(2004, copy.getYear());
293: assertEquals(8, copy.getMonthOfYear());
294: assertEquals(9, copy.getDayOfMonth());
295: }
296:
297: public void testPropertySetTextMonthOfYear() {
298: DateMidnight test = new DateMidnight(2004, 6, 9);
299: DateMidnight copy = test.monthOfYear().setCopy("8");
300: assertEquals(2004, copy.getYear());
301: assertEquals(8, copy.getMonthOfYear());
302: assertEquals(9, copy.getDayOfMonth());
303: }
304:
305: public void testPropertySetTextLocaleMonthOfYear() {
306: DateMidnight test = new DateMidnight(2004, 6, 9);
307: DateMidnight copy = test.monthOfYear().setCopy("mars",
308: Locale.FRENCH);
309: assertEquals(2004, copy.getYear());
310: assertEquals(3, copy.getMonthOfYear());
311: assertEquals(9, copy.getDayOfMonth());
312: }
313:
314: public void testPropertyAddMonthOfYear() {
315: DateMidnight test = new DateMidnight(2004, 6, 9);
316: DateMidnight copy = test.monthOfYear().addToCopy(8);
317: assertEquals(2005, copy.getYear());
318: assertEquals(2, copy.getMonthOfYear());
319: assertEquals(9, copy.getDayOfMonth());
320: }
321:
322: public void testPropertyAddLongMonthOfYear() {
323: DateMidnight test = new DateMidnight(2004, 6, 9);
324: DateMidnight copy = test.monthOfYear().addToCopy(8L);
325: assertEquals(2005, copy.getYear());
326: assertEquals(2, copy.getMonthOfYear());
327: assertEquals(9, copy.getDayOfMonth());
328: }
329:
330: public void testPropertyAddWrapFieldMonthOfYear() {
331: DateMidnight test = new DateMidnight(2004, 6, 9);
332: DateMidnight copy = test.monthOfYear().addWrapFieldToCopy(8);
333: assertEquals(2004, copy.getYear());
334: assertEquals(2, copy.getMonthOfYear());
335: assertEquals(9, copy.getDayOfMonth());
336: }
337:
338: public void testPropertyGetDifferenceMonthOfYear() {
339: DateMidnight test1 = new DateMidnight(2004, 6, 9);
340: DateMidnight test2 = new DateMidnight(2004, 8, 9);
341: assertEquals(-2, test1.monthOfYear().getDifference(test2));
342: assertEquals(2, test2.monthOfYear().getDifference(test1));
343: assertEquals(-2L, test1.monthOfYear()
344: .getDifferenceAsLong(test2));
345: assertEquals(2L, test2.monthOfYear().getDifferenceAsLong(test1));
346: }
347:
348: public void testPropertyRoundFloorMonthOfYear() {
349: DateMidnight test = new DateMidnight(2004, 6, 16);
350: DateMidnight copy = test.monthOfYear().roundFloorCopy();
351: assertEquals("2004-06-01T00:00:00.000+01:00", copy.toString());
352: }
353:
354: public void testPropertyRoundCeilingMonthOfYear() {
355: DateMidnight test = new DateMidnight(2004, 6, 16);
356: DateMidnight copy = test.monthOfYear().roundCeilingCopy();
357: assertEquals("2004-07-01T00:00:00.000+01:00", copy.toString());
358: }
359:
360: public void testPropertyRoundHalfFloorMonthOfYear() {
361: DateMidnight test = new DateMidnight(2004, 6, 16);
362: DateMidnight copy = test.monthOfYear().roundHalfFloorCopy();
363: assertEquals("2004-06-01T00:00:00.000+01:00", copy.toString());
364:
365: test = new DateMidnight(2004, 6, 17);
366: copy = test.monthOfYear().roundHalfFloorCopy();
367: assertEquals("2004-07-01T00:00:00.000+01:00", copy.toString());
368:
369: test = new DateMidnight(2004, 6, 15);
370: copy = test.monthOfYear().roundHalfFloorCopy();
371: assertEquals("2004-06-01T00:00:00.000+01:00", copy.toString());
372: }
373:
374: public void testPropertyRoundHalfCeilingMonthOfYear() {
375: DateMidnight test = new DateMidnight(2004, 6, 16);
376: DateMidnight copy = test.monthOfYear().roundHalfCeilingCopy();
377: assertEquals("2004-07-01T00:00:00.000+01:00", copy.toString());
378:
379: test = new DateMidnight(2004, 6, 17);
380: copy = test.monthOfYear().roundHalfCeilingCopy();
381: assertEquals("2004-07-01T00:00:00.000+01:00", copy.toString());
382:
383: test = new DateMidnight(2004, 6, 15);
384: copy = test.monthOfYear().roundHalfCeilingCopy();
385: assertEquals("2004-06-01T00:00:00.000+01:00", copy.toString());
386: }
387:
388: public void testPropertyRoundHalfEvenMonthOfYear() {
389: DateMidnight test = new DateMidnight(2004, 6, 16);
390: DateMidnight copy = test.monthOfYear().roundHalfEvenCopy();
391: assertEquals("2004-06-01T00:00:00.000+01:00", copy.toString());
392:
393: test = new DateMidnight(2004, 9, 16);
394: copy = test.monthOfYear().roundHalfEvenCopy();
395: assertEquals("2004-10-01T00:00:00.000+01:00", copy.toString());
396:
397: test = new DateMidnight(2004, 6, 17);
398: copy = test.monthOfYear().roundHalfEvenCopy();
399: assertEquals("2004-07-01T00:00:00.000+01:00", copy.toString());
400:
401: test = new DateMidnight(2004, 6, 15);
402: copy = test.monthOfYear().roundHalfEvenCopy();
403: assertEquals("2004-06-01T00:00:00.000+01:00", copy.toString());
404: }
405:
406: public void testPropertyRemainderMonthOfYear() {
407: DateMidnight test = new DateMidnight(2004, 6, 9);
408: assertEquals((9L - 1L) * DateTimeConstants.MILLIS_PER_DAY, test
409: .monthOfYear().remainder());
410: }
411:
412: //-----------------------------------------------------------------------
413: public void testPropertyGetDayOfMonth() {
414: DateMidnight test = new DateMidnight(2004, 6, 9);
415: assertSame(test.getChronology().dayOfMonth(), test.dayOfMonth()
416: .getField());
417: assertEquals("dayOfMonth", test.dayOfMonth().getName());
418: assertEquals("Property[dayOfMonth]", test.dayOfMonth()
419: .toString());
420: assertSame(test, test.dayOfMonth().getDateMidnight());
421: assertEquals(9, test.dayOfMonth().get());
422: assertEquals("9", test.dayOfMonth().getAsText());
423: assertEquals("9", test.dayOfMonth().getAsText(Locale.FRENCH));
424: assertEquals("9", test.dayOfMonth().getAsShortText());
425: assertEquals("9", test.dayOfMonth().getAsShortText(
426: Locale.FRENCH));
427: assertEquals(test.getChronology().days(), test.dayOfMonth()
428: .getDurationField());
429: assertEquals(test.getChronology().months(), test.dayOfMonth()
430: .getRangeDurationField());
431: assertEquals(2, test.dayOfMonth().getMaximumTextLength(null));
432: assertEquals(2, test.dayOfMonth().getMaximumShortTextLength(
433: null));
434: assertEquals(1, test.dayOfMonth().getMinimumValue());
435: assertEquals(1, test.dayOfMonth().getMinimumValueOverall());
436: assertEquals(30, test.dayOfMonth().getMaximumValue());
437: assertEquals(31, test.dayOfMonth().getMaximumValueOverall());
438: assertEquals(false, test.dayOfMonth().isLeap());
439: assertEquals(0, test.dayOfMonth().getLeapAmount());
440: assertEquals(null, test.dayOfMonth().getLeapDurationField());
441: }
442:
443: public void testPropertyWithMaximumValueDayOfMonth() {
444: DateMidnight test = new DateMidnight(2004, 6, 9);
445: DateMidnight copy = test.dayOfMonth().withMaximumValue();
446: assertEquals("2004-06-09T00:00:00.000+01:00", test.toString());
447: assertEquals("2004-06-30T00:00:00.000+01:00", copy.toString());
448: }
449:
450: public void testPropertyWithMinimumValueDayOfMonth() {
451: DateMidnight test = new DateMidnight(2004, 6, 9);
452: DateMidnight copy = test.dayOfMonth().withMinimumValue();
453: assertEquals("2004-06-09T00:00:00.000+01:00", test.toString());
454: assertEquals("2004-06-01T00:00:00.000+01:00", copy.toString());
455: }
456:
457: //-----------------------------------------------------------------------
458: public void testPropertyGetDayOfYear() {
459: // 31+29+31+30+31+9 = 161
460: DateMidnight test = new DateMidnight(2004, 6, 9);
461: assertSame(test.getChronology().dayOfYear(), test.dayOfYear()
462: .getField());
463: assertEquals("dayOfYear", test.dayOfYear().getName());
464: assertEquals("Property[dayOfYear]", test.dayOfYear().toString());
465: assertSame(test, test.dayOfYear().getDateMidnight());
466: assertEquals(161, test.dayOfYear().get());
467: assertEquals("161", test.dayOfYear().getAsText());
468: assertEquals("161", test.dayOfYear().getAsText(Locale.FRENCH));
469: assertEquals("161", test.dayOfYear().getAsShortText());
470: assertEquals("161", test.dayOfYear().getAsShortText(
471: Locale.FRENCH));
472: assertEquals(test.getChronology().days(), test.dayOfYear()
473: .getDurationField());
474: assertEquals(test.getChronology().years(), test.dayOfYear()
475: .getRangeDurationField());
476: assertEquals(3, test.dayOfYear().getMaximumTextLength(null));
477: assertEquals(3, test.dayOfYear()
478: .getMaximumShortTextLength(null));
479: assertEquals(false, test.dayOfYear().isLeap());
480: assertEquals(0, test.dayOfYear().getLeapAmount());
481: assertEquals(null, test.dayOfYear().getLeapDurationField());
482: }
483:
484: //-----------------------------------------------------------------------
485: public void testPropertyGetWeekOfWeekyear() {
486: DateMidnight test = new DateMidnight(2004, 6, 9);
487: assertSame(test.getChronology().weekOfWeekyear(), test
488: .weekOfWeekyear().getField());
489: assertEquals("weekOfWeekyear", test.weekOfWeekyear().getName());
490: assertEquals("Property[weekOfWeekyear]", test.weekOfWeekyear()
491: .toString());
492: assertSame(test, test.weekOfWeekyear().getDateMidnight());
493: assertEquals(24, test.weekOfWeekyear().get());
494: assertEquals("24", test.weekOfWeekyear().getAsText());
495: assertEquals("24", test.weekOfWeekyear().getAsText(
496: Locale.FRENCH));
497: assertEquals("24", test.weekOfWeekyear().getAsShortText());
498: assertEquals("24", test.weekOfWeekyear().getAsShortText(
499: Locale.FRENCH));
500: assertEquals(test.getChronology().weeks(), test
501: .weekOfWeekyear().getDurationField());
502: assertEquals(test.getChronology().weekyears(), test
503: .weekOfWeekyear().getRangeDurationField());
504: assertEquals(2, test.weekOfWeekyear()
505: .getMaximumTextLength(null));
506: assertEquals(2, test.weekOfWeekyear()
507: .getMaximumShortTextLength(null));
508: assertEquals(false, test.weekOfWeekyear().isLeap());
509: assertEquals(0, test.weekOfWeekyear().getLeapAmount());
510: assertEquals(null, test.weekOfWeekyear().getLeapDurationField());
511: }
512:
513: //-----------------------------------------------------------------------
514: public void testPropertyGetDayOfWeek() {
515: DateMidnight test = new DateMidnight(2004, 6, 9);
516: assertSame(test.getChronology().dayOfWeek(), test.dayOfWeek()
517: .getField());
518: assertEquals("dayOfWeek", test.dayOfWeek().getName());
519: assertEquals("Property[dayOfWeek]", test.dayOfWeek().toString());
520: assertSame(test, test.dayOfWeek().getDateMidnight());
521: assertEquals(3, test.dayOfWeek().get());
522: assertEquals("3", test.dayOfWeek().getAsString());
523: assertEquals("Wednesday", test.dayOfWeek().getAsText());
524: assertEquals("mercredi", test.dayOfWeek().getAsText(
525: Locale.FRENCH));
526: assertEquals("Wed", test.dayOfWeek().getAsShortText());
527: assertEquals("mer.", test.dayOfWeek().getAsShortText(
528: Locale.FRENCH));
529: assertEquals(test.getChronology().days(), test.dayOfWeek()
530: .getDurationField());
531: assertEquals(test.getChronology().weeks(), test.dayOfWeek()
532: .getRangeDurationField());
533: assertEquals(9, test.dayOfWeek().getMaximumTextLength(null));
534: assertEquals(8, test.dayOfWeek().getMaximumTextLength(
535: Locale.FRENCH));
536: assertEquals(3, test.dayOfWeek()
537: .getMaximumShortTextLength(null));
538: assertEquals(4, test.dayOfWeek().getMaximumShortTextLength(
539: Locale.FRENCH));
540: assertEquals(1, test.dayOfWeek().getMinimumValue());
541: assertEquals(1, test.dayOfWeek().getMinimumValueOverall());
542: assertEquals(7, test.dayOfWeek().getMaximumValue());
543: assertEquals(7, test.dayOfWeek().getMaximumValueOverall());
544: assertEquals(false, test.dayOfWeek().isLeap());
545: assertEquals(0, test.dayOfWeek().getLeapAmount());
546: assertEquals(null, test.dayOfWeek().getLeapDurationField());
547: }
548:
549: //-----------------------------------------------------------------------
550: public void testPropertyToIntervalYearOfEra() {
551: DateMidnight test = new DateMidnight(2004, 6, 9);
552: Interval testInterval = test.yearOfEra().toInterval();
553: assertEquals(new DateMidnight(2004, 1, 1), testInterval
554: .getStart());
555: assertEquals(new DateMidnight(2005, 1, 1), testInterval
556: .getEnd());
557: }
558:
559: public void testPropertyToIntervalYearOfCentury() {
560: DateMidnight test = new DateMidnight(2004, 6, 9);
561: Interval testInterval = test.yearOfCentury().toInterval();
562: assertEquals(new DateMidnight(2004, 1, 1), testInterval
563: .getStart());
564: assertEquals(new DateMidnight(2005, 1, 1), testInterval
565: .getEnd());
566: }
567:
568: public void testPropertyToIntervalYear() {
569: DateMidnight test = new DateMidnight(2004, 6, 9);
570: Interval testInterval = test.year().toInterval();
571: assertEquals(new DateMidnight(2004, 1, 1), testInterval
572: .getStart());
573: assertEquals(new DateMidnight(2005, 1, 1), testInterval
574: .getEnd());
575: }
576:
577: public void testPropertyToIntervalMonthOfYear() {
578: DateMidnight test = new DateMidnight(2004, 6, 9);
579: Interval testInterval = test.monthOfYear().toInterval();
580: assertEquals(new DateMidnight(2004, 6, 1), testInterval
581: .getStart());
582: assertEquals(new DateMidnight(2004, 7, 1), testInterval
583: .getEnd());
584: }
585:
586: public void testPropertyToIntervalDayOfMonth() {
587: DateMidnight test = new DateMidnight(2004, 6, 9);
588: Interval testInterval = test.dayOfMonth().toInterval();
589: assertEquals(new DateMidnight(2004, 6, 9), testInterval
590: .getStart());
591: assertEquals(new DateMidnight(2004, 6, 10), testInterval
592: .getEnd());
593:
594: DateMidnight febTest = new DateMidnight(2004, 2, 29);
595: Interval febTestInterval = febTest.dayOfMonth().toInterval();
596: assertEquals(new DateMidnight(2004, 2, 29), febTestInterval
597: .getStart());
598: assertEquals(new DateMidnight(2004, 3, 1), febTestInterval
599: .getEnd());
600: }
601:
602: public void testPropertyEqualsHashCodeLenient() {
603: DateMidnight test1 = new DateMidnight(1970, 6, 9,
604: LenientChronology.getInstance(COPTIC_PARIS));
605: DateMidnight test2 = new DateMidnight(1970, 6, 9,
606: LenientChronology.getInstance(COPTIC_PARIS));
607: assertEquals(true, test1.dayOfMonth()
608: .equals(test2.dayOfMonth()));
609: assertEquals(true, test2.dayOfMonth()
610: .equals(test1.dayOfMonth()));
611: assertEquals(true, test1.dayOfMonth()
612: .equals(test1.dayOfMonth()));
613: assertEquals(true, test2.dayOfMonth()
614: .equals(test2.dayOfMonth()));
615: assertEquals(true, test1.dayOfMonth().hashCode() == test2
616: .dayOfMonth().hashCode());
617: assertEquals(true, test1.dayOfMonth().hashCode() == test1
618: .dayOfMonth().hashCode());
619: assertEquals(true, test2.dayOfMonth().hashCode() == test2
620: .dayOfMonth().hashCode());
621: }
622:
623: public void testPropertyEqualsHashCodeStrict() {
624: DateMidnight test1 = new DateMidnight(1970, 6, 9,
625: StrictChronology.getInstance(COPTIC_PARIS));
626: DateMidnight test2 = new DateMidnight(1970, 6, 9,
627: StrictChronology.getInstance(COPTIC_PARIS));
628: assertEquals(true, test1.dayOfMonth()
629: .equals(test2.dayOfMonth()));
630: assertEquals(true, test2.dayOfMonth()
631: .equals(test1.dayOfMonth()));
632: assertEquals(true, test1.dayOfMonth()
633: .equals(test1.dayOfMonth()));
634: assertEquals(true, test2.dayOfMonth()
635: .equals(test2.dayOfMonth()));
636: assertEquals(true, test1.dayOfMonth().hashCode() == test2
637: .dayOfMonth().hashCode());
638: assertEquals(true, test1.dayOfMonth().hashCode() == test1
639: .dayOfMonth().hashCode());
640: assertEquals(true, test2.dayOfMonth().hashCode() == test2
641: .dayOfMonth().hashCode());
642: }
643:
644: }
|