Source Code Cross Referenced for TestLocalDateTime_Constructors.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-2006 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.Calendar;
019:        import java.util.Date;
020:        import java.util.GregorianCalendar;
021:
022:        import junit.framework.TestCase;
023:        import junit.framework.TestSuite;
024:
025:        import org.joda.time.chrono.BuddhistChronology;
026:        import org.joda.time.chrono.GregorianChronology;
027:        import org.joda.time.chrono.ISOChronology;
028:
029:        /**
030:         * This class is a Junit unit test for LocalDateTime.
031:         *
032:         * @author Stephen Colebourne
033:         */
034:        public class TestLocalDateTime_Constructors extends TestCase {
035:
036:            private static final DateTimeZone LONDON = DateTimeZone
037:                    .forID("Europe/London");
038:            private static final DateTimeZone PARIS = DateTimeZone
039:                    .forID("Europe/Paris");
040:            private static final DateTimeZone MOSCOW = DateTimeZone
041:                    .forID("Europe/Moscow");
042:            private static final Chronology ISO_UTC = ISOChronology
043:                    .getInstanceUTC();
044:            private static final Chronology GREGORIAN_UTC = GregorianChronology
045:                    .getInstanceUTC();
046:            private static final Chronology GREGORIAN_PARIS = GregorianChronology
047:                    .getInstance(PARIS);
048:            private static final Chronology GREGORIAN_MOSCOW = GregorianChronology
049:                    .getInstance(MOSCOW);
050:            private static final Chronology BUDDHIST_UTC = BuddhistChronology
051:                    .getInstanceUTC();
052:            private static final int OFFSET_PARIS = PARIS.getOffset(0L)
053:                    / DateTimeConstants.MILLIS_PER_HOUR;
054:            private static final int OFFSET_MOSCOW = MOSCOW.getOffset(0L)
055:                    / DateTimeConstants.MILLIS_PER_HOUR;
056:
057:            private long MILLIS_OF_DAY = 10L
058:                    * DateTimeConstants.MILLIS_PER_HOUR + 20L
059:                    * DateTimeConstants.MILLIS_PER_MINUTE + 30L
060:                    * DateTimeConstants.MILLIS_PER_SECOND + 40L;
061:            private long TEST_TIME_NOW = (31L + 28L + 31L + 30L + 31L + 9L - 1L)
062:                    * DateTimeConstants.MILLIS_PER_DAY + MILLIS_OF_DAY;
063:
064:            private long TEST_TIME1 = (31L + 28L + 31L + 6L - 1L)
065:                    * DateTimeConstants.MILLIS_PER_DAY + 12L
066:                    * DateTimeConstants.MILLIS_PER_HOUR + 24L
067:                    * DateTimeConstants.MILLIS_PER_MINUTE;
068:            private long TEST_TIME2 = (365L + 31L + 28L + 31L + 30L + 7L - 1L)
069:                    * DateTimeConstants.MILLIS_PER_DAY + 14L
070:                    * DateTimeConstants.MILLIS_PER_HOUR + 28L
071:                    * DateTimeConstants.MILLIS_PER_MINUTE;
072:
073:            private DateTimeZone zone = null;
074:
075:            public static void main(String[] args) {
076:                junit.textui.TestRunner.run(suite());
077:            }
078:
079:            public static TestSuite suite() {
080:                return new TestSuite(TestLocalDateTime_Constructors.class);
081:            }
082:
083:            public TestLocalDateTime_Constructors(String name) {
084:                super (name);
085:            }
086:
087:            protected void setUp() throws Exception {
088:                DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
089:                zone = DateTimeZone.getDefault();
090:                DateTimeZone.setDefault(MOSCOW);
091:            }
092:
093:            protected void tearDown() throws Exception {
094:                DateTimeUtils.setCurrentMillisSystem();
095:                DateTimeZone.setDefault(zone);
096:                zone = null;
097:            }
098:
099:            //-----------------------------------------------------------------------
100:            public void testFactory_FromCalendarFields() throws Exception {
101:                GregorianCalendar cal = new GregorianCalendar(1970, 1, 3, 4, 5,
102:                        6);
103:                cal.set(Calendar.MILLISECOND, 7);
104:                LocalDateTime expected = new LocalDateTime(1970, 2, 3, 4, 5, 6,
105:                        7);
106:                assertEquals(expected, LocalDateTime.fromCalendarFields(cal));
107:                try {
108:                    LocalDateTime.fromCalendarFields((Calendar) null);
109:                    fail();
110:                } catch (IllegalArgumentException ex) {
111:                }
112:            }
113:
114:            //-----------------------------------------------------------------------
115:            public void testFactory_FromDateFields() throws Exception {
116:                GregorianCalendar cal = new GregorianCalendar(1970, 1, 3, 4, 5,
117:                        6);
118:                cal.set(Calendar.MILLISECOND, 7);
119:                LocalDateTime expected = new LocalDateTime(1970, 2, 3, 4, 5, 6,
120:                        7);
121:                assertEquals(expected, LocalDateTime.fromDateFields(cal
122:                        .getTime()));
123:                try {
124:                    LocalDateTime.fromDateFields((Date) null);
125:                    fail();
126:                } catch (IllegalArgumentException ex) {
127:                }
128:            }
129:
130:            //-----------------------------------------------------------------------
131:            public void testConstructor() throws Throwable {
132:                LocalDateTime test = new LocalDateTime();
133:                assertEquals(ISO_UTC, test.getChronology());
134:                assertEquals(1970, test.getYear());
135:                assertEquals(6, test.getMonthOfYear());
136:                assertEquals(9, test.getDayOfMonth());
137:                assertEquals(10 + OFFSET_MOSCOW, test.getHourOfDay());
138:                assertEquals(20, test.getMinuteOfHour());
139:                assertEquals(30, test.getSecondOfMinute());
140:                assertEquals(40, test.getMillisOfSecond());
141:            }
142:
143:            //-----------------------------------------------------------------------
144:            public void testConstructor_DateTimeZone() throws Throwable {
145:                DateTime dt = new DateTime(2005, 6, 8, 23, 59, 0, 0, LONDON);
146:                DateTimeUtils.setCurrentMillisFixed(dt.getMillis());
147:                // 23:59 in London is 00:59 the following day in Paris
148:
149:                LocalDateTime test = new LocalDateTime(LONDON);
150:                assertEquals(ISO_UTC, test.getChronology());
151:                assertEquals(2005, test.getYear());
152:                assertEquals(6, test.getMonthOfYear());
153:                assertEquals(8, test.getDayOfMonth());
154:                assertEquals(23, test.getHourOfDay());
155:                assertEquals(59, test.getMinuteOfHour());
156:                assertEquals(0, test.getSecondOfMinute());
157:                assertEquals(0, test.getMillisOfSecond());
158:
159:                test = new LocalDateTime(PARIS);
160:                assertEquals(ISO_UTC, test.getChronology());
161:                assertEquals(2005, test.getYear());
162:                assertEquals(6, test.getMonthOfYear());
163:                assertEquals(9, test.getDayOfMonth());
164:                assertEquals(0, test.getHourOfDay());
165:                assertEquals(59, test.getMinuteOfHour());
166:                assertEquals(0, test.getSecondOfMinute());
167:                assertEquals(0, test.getMillisOfSecond());
168:            }
169:
170:            public void testConstructor_nullDateTimeZone() throws Throwable {
171:                LocalDateTime test = new LocalDateTime((DateTimeZone) null);
172:                assertEquals(ISO_UTC, test.getChronology());
173:                assertEquals(1970, test.getYear());
174:                assertEquals(6, test.getMonthOfYear());
175:                assertEquals(9, test.getDayOfMonth());
176:                assertEquals(10 + OFFSET_MOSCOW, test.getHourOfDay());
177:                assertEquals(20, test.getMinuteOfHour());
178:                assertEquals(30, test.getSecondOfMinute());
179:                assertEquals(40, test.getMillisOfSecond());
180:            }
181:
182:            //-----------------------------------------------------------------------
183:            public void testConstructor_Chronology() throws Throwable {
184:                LocalDateTime test = new LocalDateTime(GREGORIAN_PARIS);
185:                assertEquals(GREGORIAN_UTC, test.getChronology());
186:                assertEquals(1970, test.getYear());
187:                assertEquals(6, test.getMonthOfYear());
188:                assertEquals(9, test.getDayOfMonth());
189:                assertEquals(10 + OFFSET_PARIS, test.getHourOfDay());
190:                assertEquals(20, test.getMinuteOfHour());
191:                assertEquals(30, test.getSecondOfMinute());
192:                assertEquals(40, test.getMillisOfSecond());
193:            }
194:
195:            public void testConstructor_nullChronology() throws Throwable {
196:                LocalDateTime test = new LocalDateTime((Chronology) null);
197:                assertEquals(ISO_UTC, test.getChronology());
198:                assertEquals(1970, test.getYear());
199:                assertEquals(6, test.getMonthOfYear());
200:                assertEquals(9, test.getDayOfMonth());
201:                assertEquals(10 + OFFSET_MOSCOW, test.getHourOfDay());
202:                assertEquals(20, test.getMinuteOfHour());
203:                assertEquals(30, test.getSecondOfMinute());
204:                assertEquals(40, test.getMillisOfSecond());
205:            }
206:
207:            //-----------------------------------------------------------------------
208:            public void testConstructor_long1() throws Throwable {
209:                LocalDateTime test = new LocalDateTime(TEST_TIME1);
210:                assertEquals(ISO_UTC, test.getChronology());
211:                assertEquals(1970, test.getYear());
212:                assertEquals(4, test.getMonthOfYear());
213:                assertEquals(6, test.getDayOfMonth());
214:                assertEquals(12 + OFFSET_MOSCOW, test.getHourOfDay());
215:                assertEquals(24, test.getMinuteOfHour());
216:                assertEquals(0, test.getSecondOfMinute());
217:                assertEquals(0, test.getMillisOfSecond());
218:            }
219:
220:            public void testConstructor_long2() throws Throwable {
221:                LocalDateTime test = new LocalDateTime(TEST_TIME2);
222:                assertEquals(ISO_UTC, test.getChronology());
223:                assertEquals(1971, test.getYear());
224:                assertEquals(5, test.getMonthOfYear());
225:                assertEquals(7, test.getDayOfMonth());
226:                assertEquals(14 + OFFSET_MOSCOW, test.getHourOfDay());
227:                assertEquals(28, test.getMinuteOfHour());
228:                assertEquals(0, test.getSecondOfMinute());
229:                assertEquals(0, test.getMillisOfSecond());
230:            }
231:
232:            //-----------------------------------------------------------------------
233:            public void testConstructor_long1_DateTimeZone() throws Throwable {
234:                LocalDateTime test = new LocalDateTime(TEST_TIME1, PARIS);
235:                assertEquals(ISO_UTC, test.getChronology());
236:                assertEquals(1970, test.getYear());
237:                assertEquals(4, test.getMonthOfYear());
238:                assertEquals(6, test.getDayOfMonth());
239:                assertEquals(12 + OFFSET_PARIS, test.getHourOfDay());
240:                assertEquals(24, test.getMinuteOfHour());
241:                assertEquals(0, test.getSecondOfMinute());
242:                assertEquals(0, test.getMillisOfSecond());
243:            }
244:
245:            public void testConstructor_long2_DateTimeZone() throws Throwable {
246:                LocalDateTime test = new LocalDateTime(TEST_TIME2, PARIS);
247:                assertEquals(ISO_UTC, test.getChronology());
248:                assertEquals(1971, test.getYear());
249:                assertEquals(5, test.getMonthOfYear());
250:                assertEquals(7, test.getDayOfMonth());
251:                assertEquals(14 + OFFSET_PARIS, test.getHourOfDay());
252:                assertEquals(28, test.getMinuteOfHour());
253:                assertEquals(0, test.getSecondOfMinute());
254:                assertEquals(0, test.getMillisOfSecond());
255:            }
256:
257:            public void testConstructor_long_nullDateTimeZone()
258:                    throws Throwable {
259:                LocalDateTime test = new LocalDateTime(TEST_TIME1,
260:                        (DateTimeZone) null);
261:                assertEquals(ISO_UTC, test.getChronology());
262:                assertEquals(1970, test.getYear());
263:                assertEquals(4, test.getMonthOfYear());
264:                assertEquals(6, test.getDayOfMonth());
265:                assertEquals(12 + OFFSET_MOSCOW, test.getHourOfDay());
266:                assertEquals(24, test.getMinuteOfHour());
267:                assertEquals(0, test.getSecondOfMinute());
268:                assertEquals(0, test.getMillisOfSecond());
269:            }
270:
271:            //-----------------------------------------------------------------------
272:            public void testConstructor_long1_Chronology() throws Throwable {
273:                LocalDateTime test = new LocalDateTime(TEST_TIME1,
274:                        GREGORIAN_PARIS);
275:                assertEquals(GREGORIAN_UTC, test.getChronology());
276:                assertEquals(1970, test.getYear());
277:                assertEquals(4, test.getMonthOfYear());
278:                assertEquals(6, test.getDayOfMonth());
279:                assertEquals(12 + OFFSET_PARIS, test.getHourOfDay());
280:                assertEquals(24, test.getMinuteOfHour());
281:                assertEquals(0, test.getSecondOfMinute());
282:                assertEquals(0, test.getMillisOfSecond());
283:            }
284:
285:            public void testConstructor_long2_Chronology() throws Throwable {
286:                LocalDateTime test = new LocalDateTime(TEST_TIME2,
287:                        GREGORIAN_PARIS);
288:                assertEquals(GREGORIAN_UTC, test.getChronology());
289:                assertEquals(1971, test.getYear());
290:                assertEquals(5, test.getMonthOfYear());
291:                assertEquals(7, test.getDayOfMonth());
292:                assertEquals(14 + OFFSET_PARIS, test.getHourOfDay());
293:                assertEquals(28, test.getMinuteOfHour());
294:                assertEquals(0, test.getSecondOfMinute());
295:                assertEquals(0, test.getMillisOfSecond());
296:            }
297:
298:            public void testConstructor_long_nullChronology() throws Throwable {
299:                LocalDateTime test = new LocalDateTime(TEST_TIME1,
300:                        (Chronology) null);
301:                assertEquals(ISO_UTC, test.getChronology());
302:                assertEquals(1970, test.getYear());
303:                assertEquals(4, test.getMonthOfYear());
304:                assertEquals(6, test.getDayOfMonth());
305:                assertEquals(12 + OFFSET_MOSCOW, test.getHourOfDay());
306:                assertEquals(24, test.getMinuteOfHour());
307:                assertEquals(0, test.getSecondOfMinute());
308:                assertEquals(0, test.getMillisOfSecond());
309:            }
310:
311:            //-----------------------------------------------------------------------
312:            public void testConstructor_Object1() throws Throwable {
313:                Date date = new Date(TEST_TIME1);
314:                LocalDateTime test = new LocalDateTime(date);
315:                assertEquals(ISO_UTC, test.getChronology());
316:                assertEquals(1970, test.getYear());
317:                assertEquals(4, test.getMonthOfYear());
318:                assertEquals(6, test.getDayOfMonth());
319:                assertEquals(12 + OFFSET_MOSCOW, test.getHourOfDay());
320:                assertEquals(24, test.getMinuteOfHour());
321:                assertEquals(0, test.getSecondOfMinute());
322:                assertEquals(0, test.getMillisOfSecond());
323:            }
324:
325:            public void testConstructor_nullObject() throws Throwable {
326:                LocalDateTime test = new LocalDateTime((Object) null);
327:                assertEquals(ISO_UTC, test.getChronology());
328:                assertEquals(1970, test.getYear());
329:                assertEquals(6, test.getMonthOfYear());
330:                assertEquals(9, test.getDayOfMonth());
331:                assertEquals(10 + OFFSET_MOSCOW, test.getHourOfDay());
332:                assertEquals(20, test.getMinuteOfHour());
333:                assertEquals(30, test.getSecondOfMinute());
334:                assertEquals(40, test.getMillisOfSecond());
335:            }
336:
337:            public void testConstructor_ObjectString1() throws Throwable {
338:                LocalDateTime test = new LocalDateTime("1972-04-06");
339:                assertEquals(ISO_UTC, test.getChronology());
340:                assertEquals(1972, test.getYear());
341:                assertEquals(4, test.getMonthOfYear());
342:                assertEquals(6, test.getDayOfMonth());
343:                assertEquals(0, test.getHourOfDay());
344:                assertEquals(0, test.getMinuteOfHour());
345:                assertEquals(0, test.getSecondOfMinute());
346:                assertEquals(0, test.getMillisOfSecond());
347:            }
348:
349:            public void testConstructor_ObjectString2() throws Throwable {
350:                LocalDateTime test = new LocalDateTime("1972-037");
351:                assertEquals(ISO_UTC, test.getChronology());
352:                assertEquals(1972, test.getYear());
353:                assertEquals(2, test.getMonthOfYear());
354:                assertEquals(6, test.getDayOfMonth());
355:                assertEquals(0, test.getHourOfDay());
356:                assertEquals(0, test.getMinuteOfHour());
357:                assertEquals(0, test.getSecondOfMinute());
358:                assertEquals(0, test.getMillisOfSecond());
359:            }
360:
361:            public void testConstructor_ObjectString3() throws Throwable {
362:                LocalDateTime test = new LocalDateTime(
363:                        "1972-04-06T10:20:30.040");
364:                assertEquals(ISO_UTC, test.getChronology());
365:                assertEquals(1972, test.getYear());
366:                assertEquals(4, test.getMonthOfYear());
367:                assertEquals(6, test.getDayOfMonth());
368:                assertEquals(10, test.getHourOfDay());
369:                assertEquals(20, test.getMinuteOfHour());
370:                assertEquals(30, test.getSecondOfMinute());
371:                assertEquals(40, test.getMillisOfSecond());
372:            }
373:
374:            public void testConstructor_ObjectString4() throws Throwable {
375:                LocalDateTime test = new LocalDateTime("1972-04-06T10:20");
376:                assertEquals(ISO_UTC, test.getChronology());
377:                assertEquals(1972, test.getYear());
378:                assertEquals(4, test.getMonthOfYear());
379:                assertEquals(6, test.getDayOfMonth());
380:                assertEquals(10, test.getHourOfDay());
381:                assertEquals(20, test.getMinuteOfHour());
382:                assertEquals(0, test.getSecondOfMinute());
383:                assertEquals(0, test.getMillisOfSecond());
384:            }
385:
386:            public void testConstructor_ObjectStringEx1() throws Throwable {
387:                try {
388:                    new LocalDateTime("1970-04-06T+14:00");
389:                    fail();
390:                } catch (IllegalArgumentException ex) {
391:                }
392:            }
393:
394:            public void testConstructor_ObjectStringEx2() throws Throwable {
395:                try {
396:                    new LocalDateTime("1970-04-06T10:20:30.040+14:00");
397:                    fail();
398:                } catch (IllegalArgumentException ex) {
399:                }
400:            }
401:
402:            public void testConstructor_ObjectStringEx3() throws Throwable {
403:                try {
404:                    new LocalDateTime("T10:20:30.040");
405:                    fail();
406:                } catch (IllegalArgumentException ex) {
407:                }
408:            }
409:
410:            public void testConstructor_ObjectStringEx4() throws Throwable {
411:                try {
412:                    new LocalDateTime("T10:20:30.040+14:00");
413:                    fail();
414:                } catch (IllegalArgumentException ex) {
415:                }
416:            }
417:
418:            public void testConstructor_ObjectStringEx5() throws Throwable {
419:                try {
420:                    new LocalDateTime("10:20:30.040");
421:                    fail();
422:                } catch (IllegalArgumentException ex) {
423:                }
424:            }
425:
426:            public void testConstructor_ObjectStringEx6() throws Throwable {
427:                try {
428:                    new LocalDateTime("10:20:30.040+14:00");
429:                    fail();
430:                } catch (IllegalArgumentException ex) {
431:                }
432:            }
433:
434:            public void testConstructor_ObjectLocalDateTime() throws Throwable {
435:                LocalDateTime dt = new LocalDateTime(1970, 5, 6, 10, 20, 30,
436:                        40, BUDDHIST_UTC);
437:                LocalDateTime test = new LocalDateTime(dt);
438:                assertEquals(BUDDHIST_UTC, test.getChronology());
439:                assertEquals(1970, test.getYear());
440:                assertEquals(5, test.getMonthOfYear());
441:                assertEquals(6, test.getDayOfMonth());
442:                assertEquals(10, test.getHourOfDay());
443:                assertEquals(20, test.getMinuteOfHour());
444:                assertEquals(30, test.getSecondOfMinute());
445:                assertEquals(40, test.getMillisOfSecond());
446:            }
447:
448:            public void testConstructor_ObjectLocalDate() throws Throwable {
449:                LocalDate date = new LocalDate(1970, 5, 6);
450:                try {
451:                    new LocalDateTime(date);
452:                    fail();
453:                } catch (IllegalArgumentException ex) {
454:                }
455:            }
456:
457:            public void testConstructor_ObjectLocalTime() throws Throwable {
458:                LocalTime time = new LocalTime(10, 20, 30, 40);
459:                try {
460:                    new LocalDateTime(time);
461:                    fail();
462:                } catch (IllegalArgumentException ex) {
463:                }
464:            }
465:
466:            //-----------------------------------------------------------------------
467:            public void testConstructor_Object_DateTimeZone() throws Throwable {
468:                Date date = new Date(TEST_TIME1);
469:                LocalDateTime test = new LocalDateTime(date, PARIS);
470:                assertEquals(ISO_UTC, test.getChronology());
471:                assertEquals(1970, test.getYear());
472:                assertEquals(4, test.getMonthOfYear());
473:                assertEquals(6, test.getDayOfMonth());
474:                assertEquals(12 + OFFSET_PARIS, test.getHourOfDay());
475:                assertEquals(24, test.getMinuteOfHour());
476:                assertEquals(0, test.getSecondOfMinute());
477:                assertEquals(0, test.getMillisOfSecond());
478:            }
479:
480:            public void testConstructor_Object_DateTimeZoneMoscow()
481:                    throws Throwable {
482:                LocalDateTime test = new LocalDateTime("1970-04-06T12:24:00",
483:                        MOSCOW);
484:                assertEquals(ISO_UTC, test.getChronology());
485:                assertEquals(1970, test.getYear());
486:                assertEquals(4, test.getMonthOfYear());
487:                assertEquals(6, test.getDayOfMonth());
488:                assertEquals(12, test.getHourOfDay());
489:                assertEquals(24, test.getMinuteOfHour());
490:                assertEquals(0, test.getSecondOfMinute());
491:                assertEquals(0, test.getMillisOfSecond());
492:            }
493:
494:            public void testConstructor_Object_DateTimeZoneMoscowBadDateTime()
495:                    throws Throwable {
496:                // 1981-03-31T23:59:59.999+03:00 followed by 1981-04-01T01:00:00.000+04:00
497:                // 1981-09-30T23:59:59.999+04:00 followed by 1981-09-30T23:00:00.000+03:00
498:
499:                // when a DST non-existing time is passed in, it should still work (ie. zone ignored)
500:                LocalDateTime test = new LocalDateTime("1981-04-01T00:30:00",
501:                        MOSCOW); // doesnt exist
502:                assertEquals(ISO_UTC, test.getChronology());
503:                assertEquals(1981, test.getYear());
504:                assertEquals(4, test.getMonthOfYear());
505:                assertEquals(1, test.getDayOfMonth());
506:                assertEquals(0, test.getHourOfDay());
507:                assertEquals(30, test.getMinuteOfHour());
508:                assertEquals(0, test.getSecondOfMinute());
509:                assertEquals(0, test.getMillisOfSecond());
510:            }
511:
512:            public void testConstructor_nullObject_DateTimeZone()
513:                    throws Throwable {
514:                LocalDateTime test = new LocalDateTime((Object) null, PARIS);
515:                assertEquals(ISO_UTC, test.getChronology());
516:                assertEquals(1970, test.getYear());
517:                assertEquals(6, test.getMonthOfYear());
518:                assertEquals(9, test.getDayOfMonth());
519:                assertEquals(10 + OFFSET_PARIS, test.getHourOfDay());
520:                assertEquals(20, test.getMinuteOfHour());
521:                assertEquals(30, test.getSecondOfMinute());
522:                assertEquals(40, test.getMillisOfSecond());
523:            }
524:
525:            public void testConstructor_Object_nullDateTimeZone()
526:                    throws Throwable {
527:                Date date = new Date(TEST_TIME1);
528:                LocalDateTime test = new LocalDateTime(date,
529:                        (DateTimeZone) null);
530:                assertEquals(ISO_UTC, test.getChronology());
531:                assertEquals(1970, test.getYear());
532:                assertEquals(4, test.getMonthOfYear());
533:                assertEquals(6, test.getDayOfMonth());
534:                assertEquals(12 + OFFSET_MOSCOW, test.getHourOfDay());
535:                assertEquals(24, test.getMinuteOfHour());
536:                assertEquals(0, test.getSecondOfMinute());
537:                assertEquals(0, test.getMillisOfSecond());
538:            }
539:
540:            public void testConstructor_nullObject_nullDateTimeZone()
541:                    throws Throwable {
542:                LocalDateTime test = new LocalDateTime((Object) null,
543:                        (DateTimeZone) null);
544:                assertEquals(ISO_UTC, test.getChronology());
545:                assertEquals(1970, test.getYear());
546:                assertEquals(6, test.getMonthOfYear());
547:                assertEquals(9, test.getDayOfMonth());
548:                assertEquals(10 + OFFSET_MOSCOW, test.getHourOfDay());
549:                assertEquals(20, test.getMinuteOfHour());
550:                assertEquals(30, test.getSecondOfMinute());
551:                assertEquals(40, test.getMillisOfSecond());
552:            }
553:
554:            //-----------------------------------------------------------------------
555:            public void testConstructor_Object_Chronology() throws Throwable {
556:                Date date = new Date(TEST_TIME1);
557:                LocalDateTime test = new LocalDateTime(date, GREGORIAN_PARIS);
558:                assertEquals(GREGORIAN_UTC, test.getChronology());
559:                assertEquals(1970, test.getYear());
560:                assertEquals(4, test.getMonthOfYear());
561:                assertEquals(6, test.getDayOfMonth());
562:                assertEquals(12 + OFFSET_PARIS, test.getHourOfDay());
563:                assertEquals(24, test.getMinuteOfHour());
564:                assertEquals(0, test.getSecondOfMinute());
565:                assertEquals(0, test.getMillisOfSecond());
566:            }
567:
568:            public void testConstructor_Object_ChronologyMoscow()
569:                    throws Throwable {
570:                LocalDateTime test = new LocalDateTime("1970-04-06T12:24:00",
571:                        GREGORIAN_MOSCOW);
572:                assertEquals(GREGORIAN_UTC, test.getChronology());
573:                assertEquals(1970, test.getYear());
574:                assertEquals(4, test.getMonthOfYear());
575:                assertEquals(6, test.getDayOfMonth());
576:                assertEquals(12, test.getHourOfDay());
577:                assertEquals(24, test.getMinuteOfHour());
578:                assertEquals(0, test.getSecondOfMinute());
579:                assertEquals(0, test.getMillisOfSecond());
580:            }
581:
582:            public void testConstructor_Object_ChronologyMoscowBadDateTime()
583:                    throws Throwable {
584:                // 1981-03-31T23:59:59.999+03:00 followed by 1981-04-01T01:00:00.000+04:00
585:                // 1981-09-30T23:59:59.999+04:00 followed by 1981-09-30T23:00:00.000+03:00
586:
587:                // when a DST non-existing time is passed in, it should still work (ie. zone ignored)
588:                LocalDateTime test = new LocalDateTime("1981-04-01T00:30:00",
589:                        GREGORIAN_MOSCOW); // doesnt exist
590:                assertEquals(GREGORIAN_UTC, test.getChronology());
591:                assertEquals(1981, test.getYear());
592:                assertEquals(4, test.getMonthOfYear());
593:                assertEquals(1, test.getDayOfMonth());
594:                assertEquals(0, test.getHourOfDay());
595:                assertEquals(30, test.getMinuteOfHour());
596:                assertEquals(0, test.getSecondOfMinute());
597:                assertEquals(0, test.getMillisOfSecond());
598:            }
599:
600:            public void testConstructor_nullObject_Chronology()
601:                    throws Throwable {
602:                LocalDateTime test = new LocalDateTime((Object) null,
603:                        GREGORIAN_PARIS);
604:                assertEquals(GREGORIAN_UTC, test.getChronology());
605:                assertEquals(1970, test.getYear());
606:                assertEquals(6, test.getMonthOfYear());
607:                assertEquals(9, test.getDayOfMonth());
608:                assertEquals(10 + OFFSET_PARIS, test.getHourOfDay());
609:                assertEquals(20, test.getMinuteOfHour());
610:                assertEquals(30, test.getSecondOfMinute());
611:                assertEquals(40, test.getMillisOfSecond());
612:            }
613:
614:            public void testConstructor_Object_nullChronology()
615:                    throws Throwable {
616:                Date date = new Date(TEST_TIME1);
617:                LocalDateTime test = new LocalDateTime(date, (Chronology) null);
618:                assertEquals(ISO_UTC, test.getChronology());
619:                assertEquals(1970, test.getYear());
620:                assertEquals(4, test.getMonthOfYear());
621:                assertEquals(6, test.getDayOfMonth());
622:                assertEquals(12 + OFFSET_MOSCOW, test.getHourOfDay());
623:                assertEquals(24, test.getMinuteOfHour());
624:                assertEquals(0, test.getSecondOfMinute());
625:                assertEquals(0, test.getMillisOfSecond());
626:            }
627:
628:            public void testConstructor_nullObject_nullChronology()
629:                    throws Throwable {
630:                LocalDateTime test = new LocalDateTime((Object) null,
631:                        (Chronology) null);
632:                assertEquals(ISO_UTC, test.getChronology());
633:                assertEquals(1970, test.getYear());
634:                assertEquals(6, test.getMonthOfYear());
635:                assertEquals(9, test.getDayOfMonth());
636:                assertEquals(10 + OFFSET_MOSCOW, test.getHourOfDay());
637:                assertEquals(20, test.getMinuteOfHour());
638:                assertEquals(30, test.getSecondOfMinute());
639:                assertEquals(40, test.getMillisOfSecond());
640:            }
641:
642:            //-----------------------------------------------------------------------
643:            public void testConstructor_int_int_int_int_int() throws Throwable {
644:                LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20);
645:                assertEquals(ISO_UTC, test.getChronology());
646:                assertEquals(2005, test.getYear());
647:                assertEquals(6, test.getMonthOfYear());
648:                assertEquals(9, test.getDayOfMonth());
649:                assertEquals(10, test.getHourOfDay());
650:                assertEquals(20, test.getMinuteOfHour());
651:                assertEquals(0, test.getSecondOfMinute());
652:                assertEquals(0, test.getMillisOfSecond());
653:            }
654:
655:            //-----------------------------------------------------------------------
656:            public void testConstructor_int_int_int_int_int_int()
657:                    throws Throwable {
658:                LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30);
659:                assertEquals(ISO_UTC, test.getChronology());
660:                assertEquals(2005, test.getYear());
661:                assertEquals(6, test.getMonthOfYear());
662:                assertEquals(9, test.getDayOfMonth());
663:                assertEquals(10, test.getHourOfDay());
664:                assertEquals(20, test.getMinuteOfHour());
665:                assertEquals(30, test.getSecondOfMinute());
666:                assertEquals(0, test.getMillisOfSecond());
667:            }
668:
669:            //-----------------------------------------------------------------------
670:            public void testConstructor_int_int_int_int_int_int_int()
671:                    throws Throwable {
672:                LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
673:                        40);
674:                assertEquals(ISO_UTC, test.getChronology());
675:                assertEquals(2005, test.getYear());
676:                assertEquals(6, test.getMonthOfYear());
677:                assertEquals(9, test.getDayOfMonth());
678:                assertEquals(10, test.getHourOfDay());
679:                assertEquals(20, test.getMinuteOfHour());
680:                assertEquals(30, test.getSecondOfMinute());
681:                assertEquals(40, test.getMillisOfSecond());
682:                try {
683:                    new LocalDateTime(Integer.MIN_VALUE, 6, 9, 10, 20, 30, 40);
684:                    fail();
685:                } catch (IllegalArgumentException ex) {
686:                }
687:                try {
688:                    new LocalDateTime(Integer.MAX_VALUE, 6, 9, 10, 20, 30, 40);
689:                    fail();
690:                } catch (IllegalArgumentException ex) {
691:                }
692:                try {
693:                    new LocalDateTime(2005, 0, 9, 10, 20, 30, 40);
694:                    fail();
695:                } catch (IllegalArgumentException ex) {
696:                }
697:                try {
698:                    new LocalDateTime(2005, 13, 9, 10, 20, 30, 40);
699:                    fail();
700:                } catch (IllegalArgumentException ex) {
701:                }
702:                try {
703:                    new LocalDateTime(2005, 6, 0, 10, 20, 30, 40);
704:                    fail();
705:                } catch (IllegalArgumentException ex) {
706:                }
707:                try {
708:                    new LocalDateTime(2005, 6, 31, 10, 20, 30, 40);
709:                    fail();
710:                } catch (IllegalArgumentException ex) {
711:                }
712:                new LocalDateTime(2005, 7, 31, 10, 20, 30, 40);
713:                try {
714:                    new LocalDateTime(2005, 7, 32, 10, 20, 30, 40);
715:                    fail();
716:                } catch (IllegalArgumentException ex) {
717:                }
718:            }
719:
720:            public void testConstructor_int_int_int_Chronology()
721:                    throws Throwable {
722:                LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
723:                        40, GREGORIAN_PARIS);
724:                assertEquals(GREGORIAN_UTC, test.getChronology());
725:                assertEquals(2005, test.getYear());
726:                assertEquals(6, test.getMonthOfYear());
727:                assertEquals(9, test.getDayOfMonth());
728:                assertEquals(10, test.getHourOfDay()); // PARIS has no effect
729:                assertEquals(20, test.getMinuteOfHour());
730:                assertEquals(30, test.getSecondOfMinute());
731:                assertEquals(40, test.getMillisOfSecond());
732:                try {
733:                    new LocalDateTime(Integer.MIN_VALUE, 6, 9, 10, 20, 30, 40,
734:                            GREGORIAN_PARIS);
735:                    fail();
736:                } catch (IllegalArgumentException ex) {
737:                }
738:                try {
739:                    new LocalDateTime(Integer.MAX_VALUE, 6, 9, 10, 20, 30, 40,
740:                            GREGORIAN_PARIS);
741:                    fail();
742:                } catch (IllegalArgumentException ex) {
743:                }
744:                try {
745:                    new LocalDateTime(2005, 0, 9, 10, 20, 30, 40,
746:                            GREGORIAN_PARIS);
747:                    fail();
748:                } catch (IllegalArgumentException ex) {
749:                }
750:                try {
751:                    new LocalDateTime(2005, 13, 9, 10, 20, 30, 40,
752:                            GREGORIAN_PARIS);
753:                    fail();
754:                } catch (IllegalArgumentException ex) {
755:                }
756:                try {
757:                    new LocalDateTime(2005, 6, 0, 10, 20, 30, 40,
758:                            GREGORIAN_PARIS);
759:                    fail();
760:                } catch (IllegalArgumentException ex) {
761:                }
762:                try {
763:                    new LocalDateTime(2005, 6, 31, 10, 20, 30, 40,
764:                            GREGORIAN_PARIS);
765:                    fail();
766:                } catch (IllegalArgumentException ex) {
767:                }
768:                new LocalDateTime(2005, 7, 31, 10, 20, 30, 40, GREGORIAN_PARIS);
769:                try {
770:                    new LocalDateTime(2005, 7, 32, 10, 20, 30, 40,
771:                            GREGORIAN_PARIS);
772:                    fail();
773:                } catch (IllegalArgumentException ex) {
774:                }
775:            }
776:
777:            public void testConstructor_int_int_int_nullChronology()
778:                    throws Throwable {
779:                LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30,
780:                        40, null);
781:                assertEquals(ISO_UTC, test.getChronology());
782:                assertEquals(2005, test.getYear());
783:                assertEquals(6, test.getMonthOfYear());
784:                assertEquals(9, test.getDayOfMonth());
785:            }
786:
787:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.