001    /*
002     *  Copyright 2001-2009 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.io.ByteArrayInputStream;
019    import java.io.ByteArrayOutputStream;
020    import java.io.ObjectInputStream;
021    import java.io.ObjectOutputStream;
022    import java.util.Calendar;
023    import java.util.Date;
024    import java.util.GregorianCalendar;
025    import java.util.Locale;
026    import java.util.TimeZone;
027    
028    import junit.framework.TestCase;
029    import junit.framework.TestSuite;
030    
031    import org.joda.time.base.AbstractInstant;
032    import org.joda.time.chrono.BuddhistChronology;
033    import org.joda.time.chrono.CopticChronology;
034    import org.joda.time.chrono.GJChronology;
035    import org.joda.time.chrono.GregorianChronology;
036    import org.joda.time.chrono.ISOChronology;
037    import org.joda.time.field.UnsupportedDateTimeField;
038    import org.joda.time.field.UnsupportedDurationField;
039    import org.joda.time.format.DateTimeFormat;
040    import org.joda.time.format.DateTimeFormatter;
041    
042    /**
043     * This class is a Junit unit test for DateMidnight.
044     *
045     * @author Stephen Colebourne
046     */
047    public class TestDateMidnight_Basics extends TestCase {
048        // Test in 2002/03 as time zones are more well known
049        // (before the late 90's they were all over the place)
050    
051        private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
052        private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
053        private static final DateTimeZone NEWYORK = DateTimeZone.forID("America/New_York");
054    
055        // the default time zone is set to LONDON in setUp()
056        // we have to hard code LONDON here (instead of ISOChronology.getInstance() etc.)
057        // as TestAll sets up a different time zone for better all-round testing
058        private static final ISOChronology ISO_DEFAULT = ISOChronology.getInstance(LONDON);
059        private static final ISOChronology ISO_PARIS = ISOChronology.getInstance(PARIS);
060        private static final GJChronology GJ_DEFAULT = GJChronology.getInstance(LONDON);
061        private static final GregorianChronology GREGORIAN_DEFAULT = GregorianChronology.getInstance(LONDON);
062        private static final GregorianChronology GREGORIAN_PARIS = GregorianChronology.getInstance(PARIS);
063        private static final BuddhistChronology BUDDHIST_DEFAULT = BuddhistChronology.getInstance(LONDON);
064        private static final CopticChronology COPTIC_DEFAULT = CopticChronology.getInstance(LONDON);
065    
066        long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
067                         366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
068                         365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
069                         366 + 365;
070        long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
071                         366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
072                         365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
073                         366 + 365 + 365;
074        
075        // 2002-06-09
076        private long TEST_TIME_NOW_UTC =
077                (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
078        private long TEST_TIME_NOW_LONDON =
079                TEST_TIME_NOW_UTC - DateTimeConstants.MILLIS_PER_HOUR;
080    //    private long TEST_TIME_NOW_PARIS =
081    //            TEST_TIME_NOW_UTC - 2*DateTimeConstants.MILLIS_PER_HOUR;
082                
083        // 2002-04-05
084        private long TEST_TIME1_UTC =
085                (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY
086                + 12L * DateTimeConstants.MILLIS_PER_HOUR
087                + 24L * DateTimeConstants.MILLIS_PER_MINUTE;
088        private long TEST_TIME1_LONDON =
089                (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY
090                - DateTimeConstants.MILLIS_PER_HOUR;
091        private long TEST_TIME1_PARIS =
092                (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY
093                - 2*DateTimeConstants.MILLIS_PER_HOUR;
094            
095        // 2003-05-06
096        private long TEST_TIME2_UTC =
097                (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
098                + 14L * DateTimeConstants.MILLIS_PER_HOUR
099                + 28L * DateTimeConstants.MILLIS_PER_MINUTE;
100        private long TEST_TIME2_LONDON =
101                (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
102                 - DateTimeConstants.MILLIS_PER_HOUR;
103        private long TEST_TIME2_PARIS =
104                (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
105                 - 2*DateTimeConstants.MILLIS_PER_HOUR;
106        
107        private DateTimeZone originalDateTimeZone = null;
108        private TimeZone originalTimeZone = null;
109        private Locale originalLocale = null;
110    
111        public static void main(String[] args) {
112            junit.textui.TestRunner.run(suite());
113        }
114    
115        public static TestSuite suite() {
116            return new TestSuite(TestDateMidnight_Basics.class);
117        }
118    
119        public TestDateMidnight_Basics(String name) {
120            super(name);
121        }
122    
123        protected void setUp() throws Exception {
124            DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW_UTC);
125            originalDateTimeZone = DateTimeZone.getDefault();
126            originalTimeZone = TimeZone.getDefault();
127            originalLocale = Locale.getDefault();
128            DateTimeZone.setDefault(LONDON);
129            TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
130            Locale.setDefault(Locale.UK);
131        }
132    
133        protected void tearDown() throws Exception {
134            DateTimeUtils.setCurrentMillisSystem();
135            DateTimeZone.setDefault(originalDateTimeZone);
136            TimeZone.setDefault(originalTimeZone);
137            Locale.setDefault(originalLocale);
138            originalDateTimeZone = null;
139            originalTimeZone = null;
140            originalLocale = null;
141        }
142    
143        //-----------------------------------------------------------------------
144        public void testTest() {
145            assertEquals("2002-06-09T00:00:00.000Z", new Instant(TEST_TIME_NOW_UTC).toString());
146            assertEquals("2002-04-05T12:24:00.000Z", new Instant(TEST_TIME1_UTC).toString());
147            assertEquals("2003-05-06T14:28:00.000Z", new Instant(TEST_TIME2_UTC).toString());
148        }
149    
150        //-----------------------------------------------------------------------
151        public void testGet_DateTimeField() {
152            DateMidnight test = new DateMidnight();
153            assertEquals(1, test.get(ISO_DEFAULT.era()));
154            assertEquals(20, test.get(ISO_DEFAULT.centuryOfEra()));
155            assertEquals(2, test.get(ISO_DEFAULT.yearOfCentury()));
156            assertEquals(2002, test.get(ISO_DEFAULT.yearOfEra()));
157            assertEquals(2002, test.get(ISO_DEFAULT.year()));
158            assertEquals(6, test.get(ISO_DEFAULT.monthOfYear()));
159            assertEquals(9, test.get(ISO_DEFAULT.dayOfMonth()));
160            assertEquals(2002, test.get(ISO_DEFAULT.weekyear()));
161            assertEquals(23, test.get(ISO_DEFAULT.weekOfWeekyear()));
162            assertEquals(7, test.get(ISO_DEFAULT.dayOfWeek()));
163            assertEquals(160, test.get(ISO_DEFAULT.dayOfYear()));
164            assertEquals(0, test.get(ISO_DEFAULT.halfdayOfDay()));
165            assertEquals(0, test.get(ISO_DEFAULT.hourOfHalfday()));
166            assertEquals(24, test.get(ISO_DEFAULT.clockhourOfDay()));
167            assertEquals(12, test.get(ISO_DEFAULT.clockhourOfHalfday()));
168            assertEquals(0, test.get(ISO_DEFAULT.hourOfDay()));
169            assertEquals(0, test.get(ISO_DEFAULT.minuteOfHour()));
170            assertEquals(0, test.get(ISO_DEFAULT.minuteOfDay()));
171            assertEquals(0, test.get(ISO_DEFAULT.secondOfMinute()));
172            assertEquals(0, test.get(ISO_DEFAULT.secondOfDay()));
173            assertEquals(0, test.get(ISO_DEFAULT.millisOfSecond()));
174            assertEquals(0, test.get(ISO_DEFAULT.millisOfDay()));
175            try {
176                test.get((DateTimeField) null);
177                fail();
178            } catch (IllegalArgumentException ex) {}
179        }
180    
181        public void testGet_DateTimeFieldType() {
182            DateMidnight test = new DateMidnight();
183            assertEquals(1, test.get(DateTimeFieldType.era()));
184            assertEquals(20, test.get(DateTimeFieldType.centuryOfEra()));
185            assertEquals(2, test.get(DateTimeFieldType.yearOfCentury()));
186            assertEquals(2002, test.get(DateTimeFieldType.yearOfEra()));
187            assertEquals(2002, test.get(DateTimeFieldType.year()));
188            assertEquals(6, test.get(DateTimeFieldType.monthOfYear()));
189            assertEquals(9, test.get(DateTimeFieldType.dayOfMonth()));
190            assertEquals(2002, test.get(DateTimeFieldType.weekyear()));
191            assertEquals(23, test.get(DateTimeFieldType.weekOfWeekyear()));
192            assertEquals(7, test.get(DateTimeFieldType.dayOfWeek()));
193            assertEquals(160, test.get(DateTimeFieldType.dayOfYear()));
194            assertEquals(0, test.get(DateTimeFieldType.halfdayOfDay()));
195            assertEquals(0, test.get(DateTimeFieldType.hourOfHalfday()));
196            assertEquals(24, test.get(DateTimeFieldType.clockhourOfDay()));
197            assertEquals(12, test.get(DateTimeFieldType.clockhourOfHalfday()));
198            assertEquals(0, test.get(DateTimeFieldType.hourOfDay()));
199            assertEquals(0, test.get(DateTimeFieldType.minuteOfHour()));
200            assertEquals(0, test.get(DateTimeFieldType.minuteOfDay()));
201            assertEquals(0, test.get(DateTimeFieldType.secondOfMinute()));
202            assertEquals(0, test.get(DateTimeFieldType.secondOfDay()));
203            assertEquals(0, test.get(DateTimeFieldType.millisOfSecond()));
204            assertEquals(0, test.get(DateTimeFieldType.millisOfDay()));
205            try {
206                test.get((DateTimeFieldType) null);
207                fail();
208            } catch (IllegalArgumentException ex) {}
209        }
210    
211        //-----------------------------------------------------------------------
212        public void testGetters() {
213            DateMidnight test = new DateMidnight();
214            
215            assertEquals(ISO_DEFAULT, test.getChronology());
216            assertEquals(LONDON, test.getZone());
217            assertEquals(TEST_TIME_NOW_LONDON, test.getMillis());
218            
219            assertEquals(1, test.getEra());
220            assertEquals(20, test.getCenturyOfEra());
221            assertEquals(2, test.getYearOfCentury());
222            assertEquals(2002, test.getYearOfEra());
223            assertEquals(2002, test.getYear());
224            assertEquals(6, test.getMonthOfYear());
225            assertEquals(9, test.getDayOfMonth());
226            assertEquals(2002, test.getWeekyear());
227            assertEquals(23, test.getWeekOfWeekyear());
228            assertEquals(7, test.getDayOfWeek());
229            assertEquals(160, test.getDayOfYear());
230            assertEquals(0, test.getHourOfDay());
231            assertEquals(0, test.getMinuteOfHour());
232            assertEquals(0, test.getMinuteOfDay());
233            assertEquals(0, test.getSecondOfMinute());
234            assertEquals(0, test.getSecondOfDay());
235            assertEquals(0, test.getMillisOfSecond());
236            assertEquals(0, test.getMillisOfDay());
237        }
238    
239        public void testWithers() {
240            DateMidnight test = new DateMidnight(1970, 6, 9, GJ_DEFAULT);
241            check(test.withYear(2000), 2000, 6, 9);
242            check(test.withMonthOfYear(2), 1970, 2, 9);
243            check(test.withDayOfMonth(2), 1970, 6, 2);
244            check(test.withDayOfYear(6), 1970, 1, 6);
245            check(test.withDayOfWeek(6), 1970, 6, 13);
246            check(test.withWeekOfWeekyear(6), 1970, 2, 3);
247            check(test.withWeekyear(1971), 1971, 6, 15);
248            check(test.withYearOfCentury(60), 1960, 6, 9);
249            check(test.withCenturyOfEra(21), 2070, 6, 9);
250            check(test.withYearOfEra(1066), 1066, 6, 9);
251            check(test.withEra(DateTimeConstants.BC), -1970, 6, 9);
252            
253            try {
254                test.withMonthOfYear(0);
255                fail();
256            } catch (IllegalArgumentException ex) {}
257            try {
258                test.withMonthOfYear(13);
259                fail();
260            } catch (IllegalArgumentException ex) {}
261        }
262    
263        //-----------------------------------------------------------------------
264        public void testEqualsHashCode() {
265            DateMidnight test1 = new DateMidnight(TEST_TIME1_UTC);
266            DateMidnight test2 = new DateMidnight(TEST_TIME1_UTC);
267            assertEquals(true, test1.equals(test2));
268            assertEquals(true, test2.equals(test1));
269            assertEquals(true, test1.equals(test1));
270            assertEquals(true, test2.equals(test2));
271            assertEquals(true, test1.hashCode() == test2.hashCode());
272            assertEquals(true, test1.hashCode() == test1.hashCode());
273            assertEquals(true, test2.hashCode() == test2.hashCode());
274            
275            DateMidnight test3 = new DateMidnight(TEST_TIME2_UTC);
276            assertEquals(false, test1.equals(test3));
277            assertEquals(false, test2.equals(test3));
278            assertEquals(false, test3.equals(test1));
279            assertEquals(false, test3.equals(test2));
280            assertEquals(false, test1.hashCode() == test3.hashCode());
281            assertEquals(false, test2.hashCode() == test3.hashCode());
282            
283            assertEquals(false, test1.equals("Hello"));
284            assertEquals(true, test1.equals(new MockInstant()));
285            assertEquals(false, test1.equals(new DateMidnight(TEST_TIME1_UTC, GREGORIAN_DEFAULT)));
286        }
287        
288        class MockInstant extends AbstractInstant {
289            public String toString() {
290                return null;
291            }
292            public long getMillis() {
293                return TEST_TIME1_LONDON;
294            }
295            public Chronology getChronology() {
296                return ISO_DEFAULT;
297            }
298        }
299    
300        public void testCompareTo() {
301            DateMidnight test1 = new DateMidnight(TEST_TIME1_UTC);
302            DateMidnight test1a = new DateMidnight(TEST_TIME1_UTC);
303            assertEquals(0, test1.compareTo(test1a));
304            assertEquals(0, test1a.compareTo(test1));
305            assertEquals(0, test1.compareTo(test1));
306            assertEquals(0, test1a.compareTo(test1a));
307            
308            DateMidnight test2 = new DateMidnight(TEST_TIME2_UTC);
309            assertEquals(-1, test1.compareTo(test2));
310            assertEquals(+1, test2.compareTo(test1));
311            
312            DateMidnight test3 = new DateMidnight(TEST_TIME2_UTC, GREGORIAN_PARIS);
313            assertEquals(-1, test1.compareTo(test3));
314            assertEquals(+1, test3.compareTo(test1));
315            assertEquals(-1, test3.compareTo(test2));  // midnight paris before london
316            
317            assertEquals(+1, test2.compareTo(new MockInstant()));
318            assertEquals(0, test1.compareTo(new MockInstant()));
319            
320            try {
321                test1.compareTo(null);
322                fail();
323            } catch (NullPointerException ex) {}
324    //        try {
325    //            test1.compareTo(new Date());
326    //            fail();
327    //        } catch (ClassCastException ex) {}
328        }
329        
330        public void testIsEqual() {
331            DateMidnight test1 = new DateMidnight(TEST_TIME1_UTC);
332            DateMidnight test1a = new DateMidnight(TEST_TIME1_UTC);
333            assertEquals(true, test1.isEqual(test1a));
334            assertEquals(true, test1a.isEqual(test1));
335            assertEquals(true, test1.isEqual(test1));
336            assertEquals(true, test1a.isEqual(test1a));
337            
338            DateMidnight test2 = new DateMidnight(TEST_TIME2_UTC);
339            assertEquals(false, test1.isEqual(test2));
340            assertEquals(false, test2.isEqual(test1));
341            
342            DateMidnight test3 = new DateMidnight(TEST_TIME2_UTC, GREGORIAN_PARIS);
343            assertEquals(false, test1.isEqual(test3));
344            assertEquals(false, test3.isEqual(test1));
345            assertEquals(false, test3.isEqual(test2));  // midnight paris before london
346            
347            assertEquals(false, test2.isEqual(new MockInstant()));
348            assertEquals(true, test1.isEqual(new MockInstant()));
349            
350            assertEquals(false, new DateMidnight(TEST_TIME_NOW_UTC + DateTimeConstants.MILLIS_PER_DAY, DateTimeZone.UTC).isEqual(null));
351            assertEquals(true, new DateMidnight(TEST_TIME_NOW_UTC, DateTimeZone.UTC).isEqual(null));
352            assertEquals(false, new DateMidnight(TEST_TIME_NOW_UTC - DateTimeConstants.MILLIS_PER_DAY, DateTimeZone.UTC).isEqual(null));
353            
354            assertEquals(false, new DateMidnight(2004, 6, 9).isEqual(new DateTime(2004, 6, 8, 23, 59, 59, 999)));
355            assertEquals(true, new DateMidnight(2004, 6, 9).isEqual(new DateTime(2004, 6, 9, 0, 0, 0, 0)));
356            assertEquals(false, new DateMidnight(2004, 6, 9).isEqual(new DateTime(2004, 6, 9, 0, 0, 0, 1)));
357        }
358        
359        public void testIsBefore() {
360            DateMidnight test1 = new DateMidnight(TEST_TIME1_UTC);
361            DateMidnight test1a = new DateMidnight(TEST_TIME1_UTC);
362            assertEquals(false, test1.isBefore(test1a));
363            assertEquals(false, test1a.isBefore(test1));
364            assertEquals(false, test1.isBefore(test1));
365            assertEquals(false, test1a.isBefore(test1a));
366            
367            DateMidnight test2 = new DateMidnight(TEST_TIME2_UTC);
368            assertEquals(true, test1.isBefore(test2));
369            assertEquals(false, test2.isBefore(test1));
370            
371            DateMidnight test3 = new DateMidnight(TEST_TIME2_UTC, GREGORIAN_PARIS);
372            assertEquals(true, test1.isBefore(test3));
373            assertEquals(false, test3.isBefore(test1));
374            assertEquals(true, test3.isBefore(test2));  // midnight paris before london
375            
376            assertEquals(false, test2.isBefore(new MockInstant()));
377            assertEquals(false, test1.isBefore(new MockInstant()));
378            
379            assertEquals(false, new DateMidnight(TEST_TIME_NOW_UTC + DateTimeConstants.MILLIS_PER_DAY, DateTimeZone.UTC).isBefore(null));
380            assertEquals(false, new DateMidnight(TEST_TIME_NOW_UTC, DateTimeZone.UTC).isBefore(null));
381            assertEquals(true, new DateMidnight(TEST_TIME_NOW_UTC - DateTimeConstants.MILLIS_PER_DAY, DateTimeZone.UTC).isBefore(null));
382            
383            assertEquals(false, new DateMidnight(2004, 6, 9).isBefore(new DateTime(2004, 6, 8, 23, 59, 59, 999)));
384            assertEquals(false, new DateMidnight(2004, 6, 9).isBefore(new DateTime(2004, 6, 9, 0, 0, 0, 0)));
385            assertEquals(true, new DateMidnight(2004, 6, 9).isBefore(new DateTime(2004, 6, 9, 0, 0, 0, 1)));
386        }
387        
388        public void testIsAfter() {
389            DateMidnight test1 = new DateMidnight(TEST_TIME1_UTC);
390            DateMidnight test1a = new DateMidnight(TEST_TIME1_UTC);
391            assertEquals(false, test1.isAfter(test1a));
392            assertEquals(false, test1a.isAfter(test1));
393            assertEquals(false, test1.isAfter(test1));
394            assertEquals(false, test1a.isAfter(test1a));
395            
396            DateMidnight test2 = new DateMidnight(TEST_TIME2_UTC);
397            assertEquals(false, test1.isAfter(test2));
398            assertEquals(true, test2.isAfter(test1));
399            
400            DateMidnight test3 = new DateMidnight(TEST_TIME2_UTC, GREGORIAN_PARIS);
401            assertEquals(false, test1.isAfter(test3));
402            assertEquals(true, test3.isAfter(test1));
403            assertEquals(false, test3.isAfter(test2));  // midnight paris before london
404            
405            assertEquals(true, test2.isAfter(new MockInstant()));
406            assertEquals(false, test1.isAfter(new MockInstant()));
407            
408            assertEquals(true, new DateMidnight(TEST_TIME_NOW_UTC + DateTimeConstants.MILLIS_PER_DAY, DateTimeZone.UTC).isAfter(null));
409            assertEquals(false, new DateMidnight(TEST_TIME_NOW_UTC, DateTimeZone.UTC).isAfter(null));
410            assertEquals(false, new DateMidnight(TEST_TIME_NOW_UTC - DateTimeConstants.MILLIS_PER_DAY, DateTimeZone.UTC).isAfter(null));
411            
412            assertEquals(true, new DateMidnight(2004, 6, 9).isAfter(new DateTime(2004, 6, 8, 23, 59, 59, 999)));
413            assertEquals(false, new DateMidnight(2004, 6, 9).isAfter(new DateTime(2004, 6, 9, 0, 0, 0, 0)));
414            assertEquals(false, new DateMidnight(2004, 6, 9).isAfter(new DateTime(2004, 6, 9, 0, 0, 0, 1)));
415        }
416        
417        //-----------------------------------------------------------------------
418        public void testSerialization() throws Exception {
419            DateMidnight test = new DateMidnight(TEST_TIME_NOW_UTC);
420            
421            ByteArrayOutputStream baos = new ByteArrayOutputStream();
422            ObjectOutputStream oos = new ObjectOutputStream(baos);
423            oos.writeObject(test);
424            byte[] bytes = baos.toByteArray();
425            oos.close();
426            
427            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
428            ObjectInputStream ois = new ObjectInputStream(bais);
429            DateMidnight result = (DateMidnight) ois.readObject();
430            ois.close();
431            
432            assertEquals(test, result);
433        }
434    
435        //-----------------------------------------------------------------------
436        public void testToString() {
437            DateMidnight test = new DateMidnight(TEST_TIME_NOW_UTC);
438            assertEquals("2002-06-09T00:00:00.000+01:00", test.toString());
439            
440            test = new DateMidnight(TEST_TIME_NOW_UTC, PARIS);
441            assertEquals("2002-06-09T00:00:00.000+02:00", test.toString());
442            
443            test = new DateMidnight(TEST_TIME_NOW_UTC, NEWYORK);
444            assertEquals("2002-06-08T00:00:00.000-04:00", test.toString());  // the 8th
445        }
446    
447        public void testToString_String() {
448            DateMidnight test = new DateMidnight(TEST_TIME_NOW_UTC);
449            assertEquals("2002 00", test.toString("yyyy HH"));
450            assertEquals("2002-06-09T00:00:00.000+01:00", test.toString((String) null));
451        }
452    
453        public void testToString_String_String() {
454            DateMidnight test = new DateMidnight(TEST_TIME_NOW_UTC);
455            assertEquals("Sun 9/6", test.toString("EEE d/M", Locale.ENGLISH));
456            assertEquals("dim. 9/6", test.toString("EEE d/M", Locale.FRENCH));
457            assertEquals("2002-06-09T00:00:00.000+01:00", test.toString(null, Locale.ENGLISH));
458            assertEquals("Sun 9/6", test.toString("EEE d/M", null));
459            assertEquals("2002-06-09T00:00:00.000+01:00", test.toString(null, null));
460        }
461    
462        public void testToString_DTFormatter() {
463            DateMidnight test = new DateMidnight(TEST_TIME_NOW_UTC);
464            assertEquals("2002 00", test.toString(DateTimeFormat.forPattern("yyyy HH")));
465            assertEquals("2002-06-09T00:00:00.000+01:00", test.toString((DateTimeFormatter) null));
466        }
467    
468        //-----------------------------------------------------------------------
469        public void testToInstant() {
470            DateMidnight test = new DateMidnight(TEST_TIME1_UTC);
471            Instant result = test.toInstant();
472            assertEquals(TEST_TIME1_LONDON, result.getMillis());
473        }
474    
475        public void testToDateTime() {
476            DateMidnight test = new DateMidnight(TEST_TIME1_UTC, PARIS);
477            DateTime result = test.toDateTime();
478            assertEquals(test.getMillis(), result.getMillis());
479            assertEquals(TEST_TIME1_PARIS, result.getMillis());
480            assertEquals(PARIS, result.getZone());
481        }
482    
483        public void testToDateTimeISO() {
484            DateMidnight test = new DateMidnight(TEST_TIME1_UTC, PARIS);
485            DateTime result = test.toDateTimeISO();
486            assertSame(DateTime.class, result.getClass());
487            assertSame(ISOChronology.class, result.getChronology().getClass());
488            assertEquals(test.getMillis(), result.getMillis());
489            assertEquals(ISO_PARIS, result.getChronology());
490        }
491    
492        public void testToDateTime_DateTimeZone() {
493            DateMidnight test = new DateMidnight(TEST_TIME1_UTC);
494            DateTime result = test.toDateTime(LONDON);
495            assertEquals(test.getMillis(), result.getMillis());
496            assertEquals(TEST_TIME1_LONDON, result.getMillis());
497            assertEquals(LONDON, result.getZone());
498    
499            test = new DateMidnight(TEST_TIME1_UTC);
500            result = test.toDateTime(PARIS);
501            assertEquals(test.getMillis(), result.getMillis());
502            assertEquals(TEST_TIME1_LONDON, result.getMillis());
503            assertEquals(PARIS, result.getZone());
504    
505            test = new DateMidnight(TEST_TIME1_UTC, PARIS);
506            result = test.toDateTime((DateTimeZone) null);
507            assertEquals(test.getMillis(), result.getMillis());
508            assertEquals(TEST_TIME1_PARIS, result.getMillis());
509            assertEquals(LONDON, result.getZone());
510    
511            test = new DateMidnight(TEST_TIME1_UTC);
512            result = test.toDateTime((DateTimeZone) null);
513            assertEquals(test.getMillis(), result.getMillis());
514            assertEquals(TEST_TIME1_LONDON, result.getMillis());
515            assertEquals(LONDON, result.getZone());
516        }
517    
518        public void testToDateTime_Chronology() {
519            DateMidnight test = new DateMidnight(TEST_TIME1_UTC);
520            DateTime result = test.toDateTime(ISO_DEFAULT);
521            assertEquals(test.getMillis(), result.getMillis());
522            assertEquals(TEST_TIME1_LONDON, result.getMillis());
523            assertEquals(LONDON, result.getZone());
524    
525            test = new DateMidnight(TEST_TIME1_UTC);
526            result = test.toDateTime(GREGORIAN_PARIS);
527            assertEquals(test.getMillis(), result.getMillis());
528            assertEquals(TEST_TIME1_LONDON, result.getMillis());
529            assertEquals(GREGORIAN_PARIS, result.getChronology());
530    
531            test = new DateMidnight(TEST_TIME1_UTC, GREGORIAN_PARIS);
532            result = test.toDateTime((Chronology) null);
533            assertEquals(test.getMillis(), result.getMillis());
534            assertEquals(TEST_TIME1_PARIS, result.getMillis());
535            assertEquals(ISO_DEFAULT, result.getChronology());
536    
537            test = new DateMidnight(TEST_TIME1_UTC);
538            result = test.toDateTime((Chronology) null);
539            assertEquals(test.getMillis(), result.getMillis());
540            assertEquals(TEST_TIME1_LONDON, result.getMillis());
541            assertEquals(ISO_DEFAULT, result.getChronology());
542        }
543    
544        public void testToMutableDateTime() {
545            DateMidnight test = new DateMidnight(TEST_TIME1_UTC, PARIS);
546            MutableDateTime result = test.toMutableDateTime();
547            assertEquals(test.getMillis(), result.getMillis());
548            assertEquals(ISO_PARIS, result.getChronology());
549        }
550    
551        public void testToMutableDateTimeISO() {
552            DateMidnight test = new DateMidnight(TEST_TIME1_UTC, PARIS);
553            MutableDateTime result = test.toMutableDateTimeISO();
554            assertSame(MutableDateTime.class, result.getClass());
555            assertSame(ISOChronology.class, result.getChronology().getClass());
556            assertEquals(test.getMillis(), result.getMillis());
557            assertEquals(ISO_PARIS, result.getChronology());
558        }
559    
560        public void testToMutableDateTime_DateTimeZone() {
561            DateMidnight test = new DateMidnight(TEST_TIME1_UTC);
562            MutableDateTime result = test.toMutableDateTime(LONDON);
563            assertEquals(test.getMillis(), result.getMillis());
564            assertEquals(ISO_DEFAULT, result.getChronology());
565    
566            test = new DateMidnight(TEST_TIME1_UTC);
567            result = test.toMutableDateTime(PARIS);
568            assertEquals(test.getMillis(), result.getMillis());
569            assertEquals(ISO_PARIS, result.getChronology());
570    
571            test = new DateMidnight(TEST_TIME1_UTC, PARIS);
572            result = test.toMutableDateTime((DateTimeZone) null);
573            assertEquals(test.getMillis(), result.getMillis());
574            assertEquals(ISO_DEFAULT, result.getChronology());
575    
576            test = new DateMidnight(TEST_TIME1_UTC);
577            result = test.toMutableDateTime((DateTimeZone) null);
578            assertEquals(test.getMillis(), result.getMillis());
579            assertEquals(ISO_DEFAULT, result.getChronology());
580        }
581    
582        public void testToMutableDateTime_Chronology() {
583            DateMidnight test = new DateMidnight(TEST_TIME1_UTC);
584            MutableDateTime result = test.toMutableDateTime(ISO_DEFAULT);
585            assertEquals(test.getMillis(), result.getMillis());
586            assertEquals(ISO_DEFAULT, result.getChronology());
587    
588            test = new DateMidnight(TEST_TIME1_UTC);
589            result = test.toMutableDateTime(GREGORIAN_PARIS);
590            assertEquals(test.getMillis(), result.getMillis());
591            assertEquals(GREGORIAN_PARIS, result.getChronology());
592    
593            test = new DateMidnight(TEST_TIME1_UTC, GREGORIAN_PARIS);
594            result = test.toMutableDateTime((Chronology) null);
595            assertEquals(test.getMillis(), result.getMillis());
596            assertEquals(ISO_DEFAULT, result.getChronology());
597    
598            test = new DateMidnight(TEST_TIME1_UTC);
599            result = test.toMutableDateTime((Chronology) null);
600            assertEquals(test.getMillis(), result.getMillis());
601            assertEquals(ISO_DEFAULT, result.getChronology());
602        }
603    
604        public void testToDate() {
605            DateMidnight test = new DateMidnight(TEST_TIME1_UTC);
606            Date result = test.toDate();
607            assertEquals(test.getMillis(), result.getTime());
608        }
609    
610        public void testToCalendar_Locale() {
611            DateMidnight test = new DateMidnight(TEST_TIME1_UTC);
612            Calendar result = test.toCalendar(null);
613            assertEquals(test.getMillis(), result.getTime().getTime());
614            assertEquals(TimeZone.getTimeZone("Europe/London"), result.getTimeZone());
615    
616            test = new DateMidnight(TEST_TIME1_UTC, PARIS);
617            result = test.toCalendar(null);
618            assertEquals(test.getMillis(), result.getTime().getTime());
619            assertEquals(TimeZone.getTimeZone("Europe/Paris"), result.getTimeZone());
620    
621            test = new DateMidnight(TEST_TIME1_UTC, PARIS);
622            result = test.toCalendar(Locale.UK);
623            assertEquals(test.getMillis(), result.getTime().getTime());
624            assertEquals(TimeZone.getTimeZone("Europe/Paris"), result.getTimeZone());
625        }
626    
627        public void testToGregorianCalendar() {
628            DateMidnight test = new DateMidnight(TEST_TIME1_UTC);
629            GregorianCalendar result = test.toGregorianCalendar();
630            assertEquals(test.getMillis(), result.getTime().getTime());
631            assertEquals(TimeZone.getTimeZone("Europe/London"), result.getTimeZone());
632    
633            test = new DateMidnight(TEST_TIME1_UTC, PARIS);
634            result = test.toGregorianCalendar();
635            assertEquals(test.getMillis(), result.getTime().getTime());
636            assertEquals(TimeZone.getTimeZone("Europe/Paris"), result.getTimeZone());
637        }
638    
639        //-----------------------------------------------------------------------
640        public void testToYearMonthDay() {
641            DateMidnight base = new DateMidnight(TEST_TIME1_UTC, COPTIC_DEFAULT);
642            YearMonthDay test = base.toYearMonthDay();
643            assertEquals(new YearMonthDay(TEST_TIME1_UTC, COPTIC_DEFAULT), test);
644        }
645    
646        public void testToLocalDate() {
647            DateMidnight base = new DateMidnight(TEST_TIME1_UTC, COPTIC_DEFAULT);
648            LocalDate test = base.toLocalDate();
649            assertEquals(new LocalDate(TEST_TIME1_UTC, COPTIC_DEFAULT), test);
650        }
651    
652        public void testToInterval() {
653            DateMidnight base = new DateMidnight(TEST_TIME1_UTC, COPTIC_DEFAULT);
654            Interval test = base.toInterval();
655            DateMidnight end = base.plus(Period.days(1));
656            assertEquals(new Interval(base, end), test);
657        }
658    
659        //-----------------------------------------------------------------------
660        public void testWithMillis_long() {
661            DateMidnight test = new DateMidnight(TEST_TIME1_UTC);
662            DateMidnight result = test.withMillis(TEST_TIME2_UTC);
663            assertEquals(TEST_TIME2_LONDON, result.getMillis());
664            assertEquals(test.getChronology(), result.getChronology());
665            
666            test = new DateMidnight(TEST_TIME1_UTC, GREGORIAN_PARIS);
667            result = test.withMillis(TEST_TIME2_UTC);
668            assertEquals(TEST_TIME2_PARIS, result.getMillis());
669            assertEquals(test.getChronology(), result.getChronology());
670            
671            test = new DateMidnight(TEST_TIME1_UTC);
672            result = test.withMillis(TEST_TIME1_UTC);
673            assertSame(test, result);
674        }
675    
676        public void testWithChronology_Chronology() {
677            DateMidnight test = new DateMidnight(TEST_TIME1_UTC);
678            DateMidnight result = test.withChronology(GREGORIAN_PARIS);
679            assertEquals(TEST_TIME1_LONDON, test.getMillis());
680            assertEquals(TEST_TIME1_PARIS, result.getMillis());
681            assertEquals(GREGORIAN_PARIS, result.getChronology());
682            
683            test = new DateMidnight(TEST_TIME1_UTC, GREGORIAN_PARIS);
684            result = test.withChronology(null);
685            assertEquals(TEST_TIME1_PARIS, test.getMillis());
686            // midnight Paris is previous day in London
687            assertEquals(TEST_TIME1_LONDON - DateTimeConstants.MILLIS_PER_DAY, result.getMillis());
688            assertEquals(ISO_DEFAULT, result.getChronology());
689            
690            test = new DateMidnight(TEST_TIME1_UTC);
691            result = test.withChronology(null);
692            assertEquals(test.getMillis(), result.getMillis());
693            assertEquals(ISO_DEFAULT, result.getChronology());
694            
695            test = new DateMidnight(TEST_TIME1_UTC);
696            result = test.withChronology(ISO_DEFAULT);
697            assertSame(test, result);
698        }
699    
700        public void testWithZoneRetainFields_DateTimeZone() {
701            DateMidnight test = new DateMidnight(TEST_TIME1_UTC);
702            DateMidnight result = test.withZoneRetainFields(PARIS);
703            assertEquals(TEST_TIME1_LONDON, test.getMillis());
704            assertEquals(TEST_TIME1_PARIS, result.getMillis());
705            assertEquals(ISO_PARIS, result.getChronology());
706            
707            test = new DateMidnight(TEST_TIME1_UTC, GREGORIAN_PARIS);
708            result = test.withZoneRetainFields(null);
709            assertEquals(TEST_TIME1_PARIS, test.getMillis());
710            assertEquals(TEST_TIME1_LONDON, result.getMillis());
711            assertEquals(GREGORIAN_DEFAULT, result.getChronology());
712            
713            test = new DateMidnight(TEST_TIME1_UTC);
714            result = test.withZoneRetainFields(LONDON);
715            assertSame(test, result);
716            
717            test = new DateMidnight(TEST_TIME1_UTC);
718            result = test.withZoneRetainFields(null);
719            assertSame(test, result);
720            
721            test = new DateMidnight(TEST_TIME1_UTC, new MockNullZoneChronology());
722            result = test.withZoneRetainFields(LONDON);
723            assertSame(test, result);
724        }
725    
726        //-----------------------------------------------------------------------
727        public void testWithFields_RPartial() {
728            DateMidnight test = new DateMidnight(2004, 5, 6);
729            DateMidnight result = test.withFields(new YearMonthDay(2003, 4, 5));
730            DateMidnight expected = new DateMidnight(2003, 4, 5);
731            assertEquals(expected, result);
732            
733            test = new DateMidnight(TEST_TIME1_UTC);
734            result = test.withFields(null);
735            assertSame(test, result);
736        }
737    
738        //-----------------------------------------------------------------------
739        public void testWithField1() {
740            DateMidnight test = new DateMidnight(2004, 6, 9);
741            DateMidnight result = test.withField(DateTimeFieldType.year(), 2006);
742            
743            assertEquals(new DateMidnight(2004, 6, 9), test);
744            assertEquals(new DateMidnight(2006, 6, 9), result);
745        }
746    
747        public void testWithField2() {
748            DateMidnight test = new DateMidnight(2004, 6, 9);
749            try {
750                test.withField(null, 6);
751                fail();
752            } catch (IllegalArgumentException ex) {}
753        }
754    
755        //-----------------------------------------------------------------------
756        public void testWithFieldAdded1() {
757            DateMidnight test = new DateMidnight(2004, 6, 9);
758            DateMidnight result = test.withFieldAdded(DurationFieldType.years(), 6);
759            
760            assertEquals(new DateMidnight(2004, 6, 9), test);
761            assertEquals(new DateMidnight(2010, 6, 9), result);
762        }
763    
764        public void testWithFieldAdded2() {
765            DateMidnight test = new DateMidnight(2004, 6, 9);
766            try {
767                test.withFieldAdded(null, 0);
768                fail();
769            } catch (IllegalArgumentException ex) {}
770        }
771    
772        public void testWithFieldAdded3() {
773            DateMidnight test = new DateMidnight(2004, 6, 9);
774            try {
775                test.withFieldAdded(null, 6);
776                fail();
777            } catch (IllegalArgumentException ex) {}
778        }
779    
780        public void testWithFieldAdded4() {
781            DateMidnight test = new DateMidnight(2004, 6, 9);
782            DateMidnight result = test.withFieldAdded(DurationFieldType.years(), 0);
783            assertSame(test, result);
784        }
785    
786        //-----------------------------------------------------------------------
787        public void testWithDurationAdded_long_int() {
788            DateMidnight test = new DateMidnight(TEST_TIME1_UTC, BUDDHIST_DEFAULT);
789            DateMidnight result = test.withDurationAdded(123456789L, 1);
790            DateMidnight expected = new DateMidnight(test.getMillis() + 123456789L, BUDDHIST_DEFAULT);
791            assertEquals(expected, result);
792            
793            result = test.withDurationAdded(123456789L, 0);
794            assertSame(test, result);
795            
796            result = test.withDurationAdded(123456789L, 2);
797            expected = new DateMidnight(test.getMillis() + (2L * 123456789L), BUDDHIST_DEFAULT);
798            assertEquals(expected, result);
799            
800            result = test.withDurationAdded(123456789L, -3);
801            expected = new DateMidnight(test.getMillis() - (3L * 123456789L), BUDDHIST_DEFAULT);
802            assertEquals(expected, result);
803        }
804        
805        //-----------------------------------------------------------------------
806        public void testWithDurationAdded_RD_int() {
807            DateMidnight test = new DateMidnight(TEST_TIME1_UTC, BUDDHIST_DEFAULT);
808            DateMidnight result = test.withDurationAdded(new Duration(123456789L), 1);
809            DateMidnight expected = new DateMidnight(test.getMillis() + 123456789L, BUDDHIST_DEFAULT);
810            assertEquals(expected, result);
811            
812            result = test.withDurationAdded(null, 1);
813            assertSame(test, result);
814            
815            result = test.withDurationAdded(new Duration(123456789L), 0);
816            assertSame(test, result);
817            
818            result = test.withDurationAdded(new Duration(123456789L), 2);
819            expected = new DateMidnight(test.getMillis() + (2L * 123456789L), BUDDHIST_DEFAULT);
820            assertEquals(expected, result);
821            
822            result = test.withDurationAdded(new Duration(123456789L), -3);
823            expected = new DateMidnight(test.getMillis() - (3L * 123456789L), BUDDHIST_DEFAULT);
824            assertEquals(expected, result);
825        }
826    
827        //-----------------------------------------------------------------------
828        public void testWithDurationAdded_RP_int() {
829            DateMidnight test = new DateMidnight(2002, 5, 3, BUDDHIST_DEFAULT);
830            DateMidnight result = test.withPeriodAdded(new Period(1, 2, 3, 4, 5, 6, 7, 8), 1);
831            DateMidnight expected = new DateMidnight(2003, 7, 28, BUDDHIST_DEFAULT);
832            assertEquals(expected, result);
833            
834            result = test.withPeriodAdded(null, 1);
835            assertSame(test, result);
836            
837            result = test.withPeriodAdded(new Period(1, 2, 3, 4, 5, 6, 7, 8), 0);
838            assertSame(test, result);
839            
840            result = test.withPeriodAdded(new Period(1, 2, 0, 4, 5, 6, 7, 8), 3);
841            expected = new DateMidnight(2005, 11, 15, BUDDHIST_DEFAULT);
842            assertEquals(expected, result);
843            
844            result = test.withPeriodAdded(new Period(1, 2, 0, 1, 1, 2, 3, 4), -1);
845            expected = new DateMidnight(2001, 3, 1, BUDDHIST_DEFAULT);
846            assertEquals(expected, result);
847        }
848    
849        //-----------------------------------------------------------------------    
850        public void testPlus_long() {
851            DateMidnight test = new DateMidnight(TEST_TIME1_UTC, BUDDHIST_DEFAULT);
852            DateMidnight result = test.plus(123456789L);
853            DateMidnight expected = new DateMidnight(test.getMillis() + 123456789L, BUDDHIST_DEFAULT);
854            assertEquals(expected, result);
855        }
856        
857        public void testPlus_RD() {
858            DateMidnight test = new DateMidnight(TEST_TIME1_UTC, BUDDHIST_DEFAULT);
859            DateMidnight result = test.plus(new Duration(123456789L));
860            DateMidnight expected = new DateMidnight(test.getMillis() + 123456789L, BUDDHIST_DEFAULT);
861            assertEquals(expected, result);
862            
863            result = test.plus((ReadableDuration) null);
864            assertSame(test, result);
865        }
866    
867        public void testPlus_RP() {
868            DateMidnight test = new DateMidnight(2002, 5, 3, BUDDHIST_DEFAULT);
869            DateMidnight result = test.plus(new Period(1, 2, 3, 4, 5, 6, 7, 8));
870            DateMidnight expected = new DateMidnight(2003, 7, 28, BUDDHIST_DEFAULT);
871            assertEquals(expected, result);
872            
873            result = test.plus((ReadablePeriod) null);
874            assertSame(test, result);
875        }
876    
877        public void testPlusYears_int() {
878            DateMidnight test = new DateMidnight(2002, 5, 3, BUDDHIST_DEFAULT);
879            DateMidnight result = test.plusYears(1);
880            DateMidnight expected = new DateMidnight(2003, 5, 3, BUDDHIST_DEFAULT);
881            assertEquals(expected, result);
882            
883            result = test.plusYears(0);
884            assertSame(test, result);
885        }
886    
887        public void testPlusMonths_int() {
888            DateMidnight test = new DateMidnight(2002, 5, 3, BUDDHIST_DEFAULT);
889            DateMidnight result = test.plusMonths(1);
890            DateMidnight expected = new DateMidnight(2002, 6, 3, BUDDHIST_DEFAULT);
891            assertEquals(expected, result);
892            
893            result = test.plusMonths(0);
894            assertSame(test, result);
895        }
896    
897        public void testPlusWeeks_int() {
898            DateMidnight test = new DateMidnight(2002, 5, 3, BUDDHIST_DEFAULT);
899            DateMidnight result = test.plusWeeks(1);
900            DateMidnight expected = new DateMidnight(2002, 5, 10, BUDDHIST_DEFAULT);
901            assertEquals(expected, result);
902            
903            result = test.plusWeeks(0);
904            assertSame(test, result);
905        }
906    
907        public void testPlusDays_int() {
908            DateMidnight test = new DateMidnight(2002, 5, 3, BUDDHIST_DEFAULT);
909            DateMidnight result = test.plusDays(1);
910            DateMidnight expected = new DateMidnight(2002, 5, 4, BUDDHIST_DEFAULT);
911            assertEquals(expected, result);
912            
913            result = test.plusDays(0);
914            assertSame(test, result);
915        }
916    
917        //-----------------------------------------------------------------------    
918        public void testMinus_long() {
919            DateMidnight test = new DateMidnight(TEST_TIME1_UTC, BUDDHIST_DEFAULT);
920            DateMidnight result = test.minus(123456789L);
921            DateMidnight expected = new DateMidnight(test.getMillis() - 123456789L, BUDDHIST_DEFAULT);
922            assertEquals(expected, result);
923        }
924    
925        public void testMinus_RD() {
926            DateMidnight test = new DateMidnight(TEST_TIME1_UTC, BUDDHIST_DEFAULT);
927            DateMidnight result = test.minus(new Duration(123456789L));
928            DateMidnight expected = new DateMidnight(test.getMillis() - 123456789L, BUDDHIST_DEFAULT);
929            assertEquals(expected, result);
930            
931            result = test.minus((ReadableDuration) null);
932            assertSame(test, result);
933        }
934    
935        public void testMinus_RP() {
936            DateMidnight test = new DateMidnight(2002, 5, 3, BUDDHIST_DEFAULT);
937            DateMidnight result = test.minus(new Period(1, 1, 1, 1, 1, 1, 1, 1));
938            DateMidnight expected = new DateMidnight(2001, 3, 25, BUDDHIST_DEFAULT);
939            assertEquals(expected, result);
940            
941            result = test.minus((ReadablePeriod) null);
942            assertSame(test, result);
943        }
944    
945        public void testMinusYears_int() {
946            DateMidnight test = new DateMidnight(2002, 5, 3, BUDDHIST_DEFAULT);
947            DateMidnight result = test.minusYears(1);
948            DateMidnight expected = new DateMidnight(2001, 5, 3, BUDDHIST_DEFAULT);
949            assertEquals(expected, result);
950            
951            result = test.minusYears(0);
952            assertSame(test, result);
953        }
954    
955        public void testMinusMonths_int() {
956            DateMidnight test = new DateMidnight(2002, 5, 3, BUDDHIST_DEFAULT);
957            DateMidnight result = test.minusMonths(1);
958            DateMidnight expected = new DateMidnight(2002, 4, 3, BUDDHIST_DEFAULT);
959            assertEquals(expected, result);
960            
961            result = test.minusMonths(0);
962            assertSame(test, result);
963        }
964    
965        public void testMinusWeeks_int() {
966            DateMidnight test = new DateMidnight(2002, 5, 3, BUDDHIST_DEFAULT);
967            DateMidnight result = test.minusWeeks(1);
968            DateMidnight expected = new DateMidnight(2002, 4, 26, BUDDHIST_DEFAULT);
969            assertEquals(expected, result);
970            
971            result = test.minusWeeks(0);
972            assertSame(test, result);
973        }
974    
975        public void testMinusDays_int() {
976            DateMidnight test = new DateMidnight(2002, 5, 3, BUDDHIST_DEFAULT);
977            DateMidnight result = test.minusDays(1);
978            DateMidnight expected = new DateMidnight(2002, 5, 2, BUDDHIST_DEFAULT);
979            assertEquals(expected, result);
980            
981            result = test.minusDays(0);
982            assertSame(test, result);
983        }
984    
985        //-----------------------------------------------------------------------
986        public void testProperty() {
987            DateMidnight test = new DateMidnight();
988            assertEquals(test.year(), test.property(DateTimeFieldType.year()));
989            assertEquals(test.dayOfWeek(), test.property(DateTimeFieldType.dayOfWeek()));
990            assertEquals(test.weekOfWeekyear(), test.property(DateTimeFieldType.weekOfWeekyear()));
991            assertEquals(test.property(DateTimeFieldType.millisOfSecond()), test.property(DateTimeFieldType.millisOfSecond()));
992            DateTimeFieldType bad = new DateTimeFieldType("bad") {
993                public DurationFieldType getDurationType() {
994                    return DurationFieldType.weeks();
995                }
996                public DurationFieldType getRangeDurationType() {
997                    return null;
998                }
999                public DateTimeField getField(Chronology chronology) {
1000                    return UnsupportedDateTimeField.getInstance(this, UnsupportedDurationField.getInstance(getDurationType()));
1001                }
1002            };
1003            try {
1004                test.property(bad);
1005                fail();
1006            } catch (IllegalArgumentException ex) {}
1007            try {
1008                test.property(null);
1009                fail();
1010            } catch (IllegalArgumentException ex) {}
1011        }
1012    
1013        //-----------------------------------------------------------------------
1014        private void check(DateMidnight test, int year, int month, int day) {
1015            assertEquals(year, test.getYear());
1016            assertEquals(month, test.getMonthOfYear());
1017            assertEquals(day, test.getDayOfMonth());
1018        }
1019    
1020    }