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 import java.util.TimeZone;
020
021 import junit.framework.TestCase;
022 import junit.framework.TestSuite;
023
024 import org.joda.time.chrono.BuddhistChronology;
025 import org.joda.time.chrono.GregorianChronology;
026 import org.joda.time.chrono.ISOChronology;
027
028 /**
029 * This class is a JUnit test for MutableDateTime.
030 *
031 * @author Stephen Colebourne
032 */
033 public class TestMutableDateTime_Sets 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.forID("Europe/Paris");
038 private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
039
040 long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
041 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 +
042 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
043 366 + 365;
044 long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
045 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 +
046 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
047 366 + 365 + 365;
048
049 // 2002-06-09
050 private long TEST_TIME_NOW =
051 (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
052
053 // 2002-04-05
054 private long TEST_TIME1 =
055 (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY
056 + 12L * DateTimeConstants.MILLIS_PER_HOUR
057 + 24L * DateTimeConstants.MILLIS_PER_MINUTE;
058
059 // 2003-05-06
060 private long TEST_TIME2 =
061 (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
062 + 14L * DateTimeConstants.MILLIS_PER_HOUR
063 + 28L * DateTimeConstants.MILLIS_PER_MINUTE;
064
065 private DateTimeZone originalDateTimeZone = null;
066 private TimeZone originalTimeZone = null;
067 private Locale originalLocale = null;
068
069 public static void main(String[] args) {
070 junit.textui.TestRunner.run(suite());
071 }
072
073 public static TestSuite suite() {
074 return new TestSuite(TestMutableDateTime_Sets.class);
075 }
076
077 public TestMutableDateTime_Sets(String name) {
078 super(name);
079 }
080
081 protected void setUp() throws Exception {
082 DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
083 originalDateTimeZone = DateTimeZone.getDefault();
084 originalTimeZone = TimeZone.getDefault();
085 originalLocale = Locale.getDefault();
086 DateTimeZone.setDefault(LONDON);
087 TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
088 Locale.setDefault(Locale.UK);
089 }
090
091 protected void tearDown() throws Exception {
092 DateTimeUtils.setCurrentMillisSystem();
093 DateTimeZone.setDefault(originalDateTimeZone);
094 TimeZone.setDefault(originalTimeZone);
095 Locale.setDefault(originalLocale);
096 originalDateTimeZone = null;
097 originalTimeZone = null;
098 originalLocale = null;
099 }
100
101 //-----------------------------------------------------------------------
102 public void testTest() {
103 assertEquals("2002-06-09T00:00:00.000Z", new Instant(TEST_TIME_NOW).toString());
104 assertEquals("2002-04-05T12:24:00.000Z", new Instant(TEST_TIME1).toString());
105 assertEquals("2003-05-06T14:28:00.000Z", new Instant(TEST_TIME2).toString());
106 }
107
108 //-----------------------------------------------------------------------
109 public void testSetMillis_long1() {
110 MutableDateTime test = new MutableDateTime(TEST_TIME1);
111 test.setMillis(TEST_TIME2);
112 assertEquals(TEST_TIME2, test.getMillis());
113 assertEquals(ISOChronology.getInstance(), test.getChronology());
114 }
115
116 //-----------------------------------------------------------------------
117 public void testSetChronology_Chronology1() {
118 MutableDateTime test = new MutableDateTime(TEST_TIME1);
119 test.setChronology(GregorianChronology.getInstance(PARIS));
120 assertEquals(TEST_TIME1, test.getMillis());
121 assertEquals(GregorianChronology.getInstance(PARIS), test.getChronology());
122 }
123
124 public void testSetChronology_Chronology2() {
125 MutableDateTime test = new MutableDateTime(TEST_TIME1);
126 test.setChronology(null);
127 assertEquals(TEST_TIME1, test.getMillis());
128 assertEquals(ISOChronology.getInstance(), test.getChronology());
129 }
130
131 //-----------------------------------------------------------------------
132 public void testSetZone_DateTimeZone1() {
133 MutableDateTime test = new MutableDateTime(TEST_TIME1);
134 test.setZone(PARIS);
135 assertEquals(TEST_TIME1, test.getMillis());
136 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
137 }
138
139 public void testSetZone_DateTimeZone2() {
140 MutableDateTime test = new MutableDateTime(TEST_TIME1);
141 test.setZone(null);
142 assertEquals(TEST_TIME1, test.getMillis());
143 assertEquals(ISOChronology.getInstance(), test.getChronology());
144 }
145
146 //-----------------------------------------------------------------------
147 public void testSetZoneRetainFields_DateTimeZone1() {
148 MutableDateTime test = new MutableDateTime(TEST_TIME1);
149 test.setZoneRetainFields(PARIS);
150 assertEquals(TEST_TIME1 - DateTimeConstants.MILLIS_PER_HOUR, test.getMillis());
151 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
152 }
153
154 public void testSetZoneRetainFields_DateTimeZone2() {
155 MutableDateTime test = new MutableDateTime(TEST_TIME1);
156 test.setZoneRetainFields(null);
157 assertEquals(TEST_TIME1, test.getMillis());
158 assertEquals(ISOChronology.getInstance(), test.getChronology());
159 }
160
161 public void testSetZoneRetainFields_DateTimeZone3() {
162 MutableDateTime test = new MutableDateTime(TEST_TIME1, GregorianChronology.getInstance(PARIS));
163 test.setZoneRetainFields(null);
164 assertEquals(TEST_TIME1 + DateTimeConstants.MILLIS_PER_HOUR, test.getMillis());
165 assertEquals(GregorianChronology.getInstance(), test.getChronology());
166 }
167
168 public void testSetZoneRetainFields_DateTimeZone4() {
169 Chronology chrono = new MockNullZoneChronology();
170 MutableDateTime test = new MutableDateTime(TEST_TIME1, chrono);
171 test.setZoneRetainFields(PARIS);
172 assertEquals(TEST_TIME1 - DateTimeConstants.MILLIS_PER_HOUR, test.getMillis());
173 assertSame(chrono, test.getChronology());
174 }
175
176 //-----------------------------------------------------------------------
177 public void testSetMillis_RI1() {
178 MutableDateTime test = new MutableDateTime(TEST_TIME1, BuddhistChronology.getInstance());
179 test.setMillis(new Instant(TEST_TIME2));
180 assertEquals(TEST_TIME2, test.getMillis());
181 assertEquals(BuddhistChronology.getInstance(), test.getChronology());
182 }
183
184 public void testSetMillis_RI2() {
185 MutableDateTime test = new MutableDateTime(TEST_TIME1, BuddhistChronology.getInstance());
186 test.setMillis(null);
187 assertEquals(TEST_TIME_NOW, test.getMillis());
188 assertEquals(BuddhistChronology.getInstance(), test.getChronology());
189 }
190
191 //-----------------------------------------------------------------------
192 public void testSet_DateTimeFieldType_int1() {
193 MutableDateTime test = new MutableDateTime(TEST_TIME1);
194 test.set(DateTimeFieldType.year(), 2010);
195 assertEquals(2010, test.getYear());
196 }
197
198 public void testSet_DateTimeFieldType_int2() {
199 MutableDateTime test = new MutableDateTime(TEST_TIME1);
200 try {
201 test.set(null, 0);
202 fail();
203 } catch (IllegalArgumentException ex) {}
204 assertEquals(TEST_TIME1, test.getMillis());
205 }
206
207 public void testSet_DateTimeFieldType_int3() {
208 MutableDateTime test = new MutableDateTime(TEST_TIME1);
209 try {
210 test.set(DateTimeFieldType.monthOfYear(), 13);
211 fail();
212 } catch (IllegalArgumentException ex) {}
213 assertEquals(TEST_TIME1, test.getMillis());
214 }
215
216 //-----------------------------------------------------------------------
217 public void testSetDate_int_int_int1() {
218 MutableDateTime test = new MutableDateTime(2002, 6, 9, 12, 24, 48, 501);
219 test.setDate(2010, 12, 3);
220 assertEquals(2010, test.getYear());
221 assertEquals(12, test.getMonthOfYear());
222 assertEquals(3, test.getDayOfMonth());
223 assertEquals(12, test.getHourOfDay());
224 assertEquals(24, test.getMinuteOfHour());
225 assertEquals(48, test.getSecondOfMinute());
226 assertEquals(501, test.getMillisOfSecond());
227 }
228
229 public void testSetDate_int_int_int2() {
230 MutableDateTime test = new MutableDateTime(TEST_TIME1);
231 try {
232 test.setDate(2010, 13, 3);
233 fail();
234 } catch (IllegalArgumentException ex) {}
235 assertEquals(TEST_TIME1, test.getMillis());
236 }
237
238 //-----------------------------------------------------------------------
239 public void testSetDate_long1() {
240 long setter = new DateTime(2010, 12, 3, 5, 7, 9, 501).getMillis();
241 MutableDateTime test = new MutableDateTime(2002, 6, 9, 12, 24, 48, 501);
242 test.setDate(setter);
243 assertEquals(2010, test.getYear());
244 assertEquals(12, test.getMonthOfYear());
245 assertEquals(3, test.getDayOfMonth());
246 assertEquals(12, test.getHourOfDay());
247 assertEquals(24, test.getMinuteOfHour());
248 assertEquals(48, test.getSecondOfMinute());
249 assertEquals(501, test.getMillisOfSecond());
250 }
251
252 //-----------------------------------------------------------------------
253 public void testSetDate_RI1() {
254 DateTime setter = new DateTime(2010, 12, 3, 5, 7, 9, 501);
255 MutableDateTime test = new MutableDateTime(2002, 6, 9, 12, 24, 48, 501);
256 test.setDate(setter);
257 assertEquals(2010, test.getYear());
258 assertEquals(12, test.getMonthOfYear());
259 assertEquals(3, test.getDayOfMonth());
260 assertEquals(12, test.getHourOfDay());
261 assertEquals(24, test.getMinuteOfHour());
262 assertEquals(48, test.getSecondOfMinute());
263 assertEquals(501, test.getMillisOfSecond());
264 }
265
266 public void testSetDate_RI2() {
267 MutableDateTime test = new MutableDateTime(2010, 7, 8, 12, 24, 48, 501);
268 test.setDate(null); // sets to TEST_TIME_NOW
269 assertEquals(2002, test.getYear());
270 assertEquals(6, test.getMonthOfYear());
271 assertEquals(9, test.getDayOfMonth());
272 assertEquals(12, test.getHourOfDay());
273 assertEquals(24, test.getMinuteOfHour());
274 assertEquals(48, test.getSecondOfMinute());
275 assertEquals(501, test.getMillisOfSecond());
276 }
277
278 public void testSetDate_RI_same() {
279 MutableDateTime setter = new MutableDateTime(2010, 12, 3, 2, 24, 48, 501, DateTimeZone.forID("America/Los_Angeles"));
280 MutableDateTime test = new MutableDateTime(2010, 12, 3, 2, 24, 48, 501, DateTimeZone.forID("America/Los_Angeles"));
281 test.setDate(setter);
282 assertEquals(2010, test.getYear());
283 assertEquals(12, test.getMonthOfYear());
284 assertEquals(3, test.getDayOfMonth());
285 assertEquals(2, test.getHourOfDay());
286 assertEquals(24, test.getMinuteOfHour());
287 assertEquals(48, test.getSecondOfMinute());
288 assertEquals(501, test.getMillisOfSecond());
289 }
290
291 public void testSetDate_RI_different1() {
292 MutableDateTime setter = new MutableDateTime(2010, 12, 1, 0, 0, 0, 0, DateTimeZone.forID("America/Los_Angeles"));
293 MutableDateTime test = new MutableDateTime(2010, 12, 3, 2, 24, 48, 501, DateTimeZone.forID("Europe/Moscow"));
294 test.setDate(setter);
295 assertEquals(2010, test.getYear());
296 assertEquals(12, test.getMonthOfYear());
297 assertEquals(1, test.getDayOfMonth());
298 assertEquals(2, test.getHourOfDay());
299 assertEquals(24, test.getMinuteOfHour());
300 assertEquals(48, test.getSecondOfMinute());
301 assertEquals(501, test.getMillisOfSecond());
302 }
303
304 public void testSetDate_RI_different2() {
305 MutableDateTime setter = new MutableDateTime(2010, 12, 1, 0, 0, 0, 0, DateTimeZone.forID("Europe/Moscow"));
306 MutableDateTime test = new MutableDateTime(2010, 12, 3, 2, 24, 48, 501, DateTimeZone.forID("America/Los_Angeles"));
307 test.setDate(setter);
308 assertEquals(2010, test.getYear());
309 assertEquals(12, test.getMonthOfYear());
310 assertEquals(1, test.getDayOfMonth());
311 assertEquals(2, test.getHourOfDay());
312 assertEquals(24, test.getMinuteOfHour());
313 assertEquals(48, test.getSecondOfMinute());
314 assertEquals(501, test.getMillisOfSecond());
315 }
316
317 //-----------------------------------------------------------------------
318 public void testSetTime_int_int_int_int1() {
319 MutableDateTime test = new MutableDateTime(2002, 6, 9, 12, 24, 48, 501);
320 test.setTime(5, 6, 7, 8);
321 assertEquals(2002, test.getYear());
322 assertEquals(6, test.getMonthOfYear());
323 assertEquals(9, test.getDayOfMonth());
324 assertEquals(5, test.getHourOfDay());
325 assertEquals(6, test.getMinuteOfHour());
326 assertEquals(7, test.getSecondOfMinute());
327 assertEquals(8, test.getMillisOfSecond());
328 }
329
330 public void testSetTime_int_int_int2() {
331 MutableDateTime test = new MutableDateTime(TEST_TIME1);
332 try {
333 test.setTime(60, 6, 7, 8);
334 fail();
335 } catch (IllegalArgumentException ex) {}
336 assertEquals(TEST_TIME1, test.getMillis());
337 }
338
339 //-----------------------------------------------------------------------
340 public void testSetTime_long1() {
341 long setter = new DateTime(2010, 12, 3, 5, 7, 9, 11).getMillis();
342 MutableDateTime test = new MutableDateTime(2002, 6, 9, 12, 24, 48, 501);
343 test.setTime(setter);
344 assertEquals(2002, test.getYear());
345 assertEquals(6, test.getMonthOfYear());
346 assertEquals(9, test.getDayOfMonth());
347 assertEquals(5, test.getHourOfDay());
348 assertEquals(7, test.getMinuteOfHour());
349 assertEquals(9, test.getSecondOfMinute());
350 assertEquals(11, test.getMillisOfSecond());
351 }
352
353 //-----------------------------------------------------------------------
354 public void testSetTime_RI1() {
355 DateTime setter = new DateTime(2010, 12, 3, 5, 7, 9, 11);
356 MutableDateTime test = new MutableDateTime(2002, 6, 9, 12, 24, 48, 501);
357 test.setTime(setter);
358 assertEquals(2002, test.getYear());
359 assertEquals(6, test.getMonthOfYear());
360 assertEquals(9, test.getDayOfMonth());
361 assertEquals(5, test.getHourOfDay());
362 assertEquals(7, test.getMinuteOfHour());
363 assertEquals(9, test.getSecondOfMinute());
364 assertEquals(11, test.getMillisOfSecond());
365 }
366
367 public void testSetTime_RI2() {
368 MutableDateTime test = new MutableDateTime(2010, 7, 8, 12, 24, 48, 501);
369 test.setTime(null); // sets to TEST_TIME_NOW, which has no time part
370 assertEquals(2010, test.getYear());
371 assertEquals(7, test.getMonthOfYear());
372 assertEquals(8, test.getDayOfMonth());
373 assertEquals(new DateTime(TEST_TIME_NOW).getHourOfDay(), test.getHourOfDay());
374 assertEquals(new DateTime(TEST_TIME_NOW).getMinuteOfHour(), test.getMinuteOfHour());
375 assertEquals(new DateTime(TEST_TIME_NOW).getSecondOfMinute(), test.getSecondOfMinute());
376 assertEquals(new DateTime(TEST_TIME_NOW).getMillisOfSecond(), test.getMillisOfSecond());
377 }
378
379 public void testSetTime_Object3() {
380 DateTime temp = new DateTime(2010, 12, 3, 5, 7, 9, 11);
381 DateTime setter = new DateTime(temp.getMillis(), new MockNullZoneChronology());
382 MutableDateTime test = new MutableDateTime(2002, 6, 9, 12, 24, 48, 501);
383 test.setTime(setter);
384 assertEquals(2002, test.getYear());
385 assertEquals(6, test.getMonthOfYear());
386 assertEquals(9, test.getDayOfMonth());
387 assertEquals(5, test.getHourOfDay());
388 assertEquals(7, test.getMinuteOfHour());
389 assertEquals(9, test.getSecondOfMinute());
390 assertEquals(11, test.getMillisOfSecond());
391 }
392
393 //-----------------------------------------------------------------------
394 public void testSetDateTime_int_int_int_int_int_int_int1() {
395 MutableDateTime test = new MutableDateTime(2002, 6, 9, 12, 24, 48, 501);
396 test.setDateTime(2010, 12, 3, 5, 6, 7, 8);
397 assertEquals(2010, test.getYear());
398 assertEquals(12, test.getMonthOfYear());
399 assertEquals(3, test.getDayOfMonth());
400 assertEquals(5, test.getHourOfDay());
401 assertEquals(6, test.getMinuteOfHour());
402 assertEquals(7, test.getSecondOfMinute());
403 assertEquals(8, test.getMillisOfSecond());
404 }
405
406 public void testSetDateTime_int_int_int_int_int_int_int2() {
407 MutableDateTime test = new MutableDateTime(TEST_TIME1);
408 try {
409 test.setDateTime(2010, 13, 3, 5, 6, 7, 8);
410 fail();
411 } catch (IllegalArgumentException ex) {
412 }
413 assertEquals(TEST_TIME1, test.getMillis());
414 }
415
416 //-----------------------------------------------------------------------
417 public void testSetYear_int1() {
418 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
419 test.setYear(2010);
420 assertEquals("2010-06-09T05:06:07.008+01:00", test.toString());
421 }
422
423 //-----------------------------------------------------------------------
424 public void testSetMonthOfYear_int1() {
425 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
426 test.setMonthOfYear(12);
427 assertEquals("2002-12-09T05:06:07.008Z", test.toString());
428 }
429
430 public void testSetMonthOfYear_int2() {
431 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
432 try {
433 test.setMonthOfYear(13);
434 fail();
435 } catch (IllegalArgumentException ex) {}
436 assertEquals("2002-06-09T05:06:07.008+01:00", test.toString());
437 }
438
439 //-----------------------------------------------------------------------
440 public void testSetDayOfMonth_int1() {
441 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
442 test.setDayOfMonth(17);
443 assertEquals("2002-06-17T05:06:07.008+01:00", test.toString());
444 }
445
446 public void testSetDayOfMonth_int2() {
447 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
448 try {
449 test.setDayOfMonth(31);
450 fail();
451 } catch (IllegalArgumentException ex) {}
452 assertEquals("2002-06-09T05:06:07.008+01:00", test.toString());
453 }
454
455 //-----------------------------------------------------------------------
456 public void testSetDayOfYear_int1() {
457 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
458 test.setDayOfYear(3);
459 assertEquals("2002-01-03T05:06:07.008Z", test.toString());
460 }
461
462 public void testSetDayOfYear_int2() {
463 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
464 try {
465 test.setDayOfYear(366);
466 fail();
467 } catch (IllegalArgumentException ex) {}
468 assertEquals("2002-06-09T05:06:07.008+01:00", test.toString());
469 }
470
471 //-----------------------------------------------------------------------
472 public void testSetWeekyear_int1() {
473 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
474 test.setWeekyear(2001);
475 assertEquals("2001-06-10T05:06:07.008+01:00", test.toString());
476 }
477
478 //-----------------------------------------------------------------------
479 public void testSetWeekOfWeekyear_int1() {
480 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
481 test.setWeekOfWeekyear(2);
482 assertEquals("2002-01-13T05:06:07.008Z", test.toString());
483 }
484
485 public void testSetWeekOfWeekyear_int2() {
486 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
487 try {
488 test.setWeekOfWeekyear(53);
489 fail();
490 } catch (IllegalArgumentException ex) {}
491 assertEquals("2002-06-09T05:06:07.008+01:00", test.toString());
492 }
493
494 //-----------------------------------------------------------------------
495 public void testSetDayOfWeek_int1() {
496 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
497 test.setDayOfWeek(5);
498 assertEquals("2002-06-07T05:06:07.008+01:00", test.toString());
499 }
500
501 public void testSetDayOfWeek_int2() {
502 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
503 try {
504 test.setDayOfWeek(8);
505 fail();
506 } catch (IllegalArgumentException ex) {}
507 assertEquals("2002-06-09T05:06:07.008+01:00", test.toString());
508 }
509
510 //-----------------------------------------------------------------------
511 public void testSetHourOfDay_int1() {
512 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
513 test.setHourOfDay(13);
514 assertEquals("2002-06-09T13:06:07.008+01:00", test.toString());
515 }
516
517 public void testSetHourOfDay_int2() {
518 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
519 try {
520 test.setHourOfDay(24);
521 fail();
522 } catch (IllegalArgumentException ex) {}
523 assertEquals("2002-06-09T05:06:07.008+01:00", test.toString());
524 }
525
526 //-----------------------------------------------------------------------
527 public void testSetMinuteOfHour_int1() {
528 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
529 test.setMinuteOfHour(13);
530 assertEquals("2002-06-09T05:13:07.008+01:00", test.toString());
531 }
532
533 public void testSetMinuteOfHour_int2() {
534 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
535 try {
536 test.setMinuteOfHour(60);
537 fail();
538 } catch (IllegalArgumentException ex) {}
539 assertEquals("2002-06-09T05:06:07.008+01:00", test.toString());
540 }
541
542 //-----------------------------------------------------------------------
543 public void testSetMinuteOfDay_int1() {
544 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
545 test.setMinuteOfDay(13);
546 assertEquals("2002-06-09T00:13:07.008+01:00", test.toString());
547 }
548
549 public void testSetMinuteOfDay_int2() {
550 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
551 try {
552 test.setMinuteOfDay(24 * 60);
553 fail();
554 } catch (IllegalArgumentException ex) {}
555 assertEquals("2002-06-09T05:06:07.008+01:00", test.toString());
556 }
557
558 //-----------------------------------------------------------------------
559 public void testSetSecondOfMinute_int1() {
560 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
561 test.setSecondOfMinute(13);
562 assertEquals("2002-06-09T05:06:13.008+01:00", test.toString());
563 }
564
565 public void testSetSecondOfMinute_int2() {
566 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
567 try {
568 test.setSecondOfMinute(60);
569 fail();
570 } catch (IllegalArgumentException ex) {}
571 assertEquals("2002-06-09T05:06:07.008+01:00", test.toString());
572 }
573
574 //-----------------------------------------------------------------------
575 public void testSetSecondOfDay_int1() {
576 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
577 test.setSecondOfDay(13);
578 assertEquals("2002-06-09T00:00:13.008+01:00", test.toString());
579 }
580
581 public void testSetSecondOfDay_int2() {
582 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
583 try {
584 test.setSecondOfDay(24 * 60 * 60);
585 fail();
586 } catch (IllegalArgumentException ex) {}
587 assertEquals("2002-06-09T05:06:07.008+01:00", test.toString());
588 }
589
590 //-----------------------------------------------------------------------
591 public void testSetMilliOfSecond_int1() {
592 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
593 test.setMillisOfSecond(13);
594 assertEquals("2002-06-09T05:06:07.013+01:00", test.toString());
595 }
596
597 public void testSetMilliOfSecond_int2() {
598 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
599 try {
600 test.setMillisOfSecond(1000);
601 fail();
602 } catch (IllegalArgumentException ex) {}
603 assertEquals("2002-06-09T05:06:07.008+01:00", test.toString());
604 }
605
606 //-----------------------------------------------------------------------
607 public void testSetMilliOfDay_int1() {
608 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
609 test.setMillisOfDay(13);
610 assertEquals("2002-06-09T00:00:00.013+01:00", test.toString());
611 }
612
613 public void testSetMilliOfDay_int2() {
614 MutableDateTime test = new MutableDateTime(2002, 6, 9, 5, 6, 7, 8);
615 try {
616 test.setMillisOfDay(24 * 60 * 60 * 1000);
617 fail();
618 } catch (IllegalArgumentException ex) {}
619 assertEquals("2002-06-09T05:06:07.008+01:00", test.toString());
620 }
621
622 }