Source Code Cross Referenced for TestMutableDateTime_Sets.java in  » Development » Joda-Time » org » joda » time » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » Joda Time » org.joda.time 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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