Source Code Cross Referenced for TestISODateTimeFormat_Fields.java in  » Development » Joda-Time » org » joda » time » format » 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.format 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  Copyright 2001-2005 Stephen Colebourne
0003:         *
0004:         *  Licensed under the Apache License, Version 2.0 (the "License");
0005:         *  you may not use this file except in compliance with the License.
0006:         *  You may obtain a copy of the License at
0007:         *
0008:         *      http://www.apache.org/licenses/LICENSE-2.0
0009:         *
0010:         *  Unless required by applicable law or agreed to in writing, software
0011:         *  distributed under the License is distributed on an "AS IS" BASIS,
0012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013:         *  See the License for the specific language governing permissions and
0014:         *  limitations under the License.
0015:         */
0016:        package org.joda.time.format;
0017:
0018:        import java.util.ArrayList;
0019:        import java.util.Arrays;
0020:        import java.util.Collection;
0021:        import java.util.List;
0022:
0023:        import junit.framework.TestCase;
0024:        import junit.framework.TestSuite;
0025:
0026:        import org.joda.time.DateTimeFieldType;
0027:        import org.joda.time.Partial;
0028:
0029:        /**
0030:         * This class is a Junit unit test for ISODateTimeFormat.
0031:         *
0032:         * @author Stephen Colebourne
0033:         */
0034:        public class TestISODateTimeFormat_Fields extends TestCase {
0035:
0036:            public static void main(String[] args) {
0037:                junit.textui.TestRunner.run(suite());
0038:            }
0039:
0040:            public static TestSuite suite() {
0041:                return new TestSuite(TestISODateTimeFormat_Fields.class);
0042:            }
0043:
0044:            public TestISODateTimeFormat_Fields(String name) {
0045:                super (name);
0046:            }
0047:
0048:            protected void setUp() throws Exception {
0049:            }
0050:
0051:            protected void tearDown() throws Exception {
0052:            }
0053:
0054:            //-----------------------------------------------------------------------
0055:            public void testForFields_null() {
0056:                try {
0057:                    ISODateTimeFormat.forFields((Collection) null, true, true);
0058:                    fail();
0059:                } catch (IllegalArgumentException ex) {
0060:                }
0061:            }
0062:
0063:            //-----------------------------------------------------------------------
0064:            public void testForFields_empty() {
0065:                try {
0066:                    ISODateTimeFormat.forFields(new ArrayList(), true, true);
0067:                    fail();
0068:                } catch (IllegalArgumentException ex) {
0069:                }
0070:            }
0071:
0072:            //-----------------------------------------------------------------------
0073:            //-----------------------------------------------------------------------
0074:            //-----------------------------------------------------------------------
0075:            public void testForFields_calBased_YMD() {
0076:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0077:                        DateTimeFieldType.year(),
0078:                        DateTimeFieldType.monthOfYear(),
0079:                        DateTimeFieldType.dayOfMonth(), };
0080:                int[] values = new int[] { 2005, 6, 25 };
0081:                List types = new ArrayList(Arrays.asList(fields));
0082:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0083:                        true);
0084:                assertEquals("2005-06-25", f.print(new Partial(fields, values)));
0085:                assertEquals(0, types.size());
0086:
0087:                types = new ArrayList(Arrays.asList(fields));
0088:                f = ISODateTimeFormat.forFields(types, true, false);
0089:                assertEquals("2005-06-25", f.print(new Partial(fields, values)));
0090:                assertEquals(0, types.size());
0091:
0092:                types = new ArrayList(Arrays.asList(fields));
0093:                f = ISODateTimeFormat.forFields(types, false, true);
0094:                assertEquals("20050625", f.print(new Partial(fields, values)));
0095:                assertEquals(0, types.size());
0096:
0097:                types = new ArrayList(Arrays.asList(fields));
0098:                f = ISODateTimeFormat.forFields(types, false, false);
0099:                assertEquals("20050625", f.print(new Partial(fields, values)));
0100:                assertEquals(0, types.size());
0101:            }
0102:
0103:            //-----------------------------------------------------------------------
0104:            public void testForFields_calBased_Y() {
0105:                DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType
0106:                        .year(), };
0107:                int[] values = new int[] { 2005 };
0108:                List types = new ArrayList(Arrays.asList(fields));
0109:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0110:                        true);
0111:                assertEquals("2005", f.print(new Partial(fields, values)));
0112:                assertEquals(0, types.size());
0113:
0114:                types = new ArrayList(Arrays.asList(fields));
0115:                f = ISODateTimeFormat.forFields(types, true, false);
0116:                assertEquals("2005", f.print(new Partial(fields, values)));
0117:                assertEquals(0, types.size());
0118:
0119:                types = new ArrayList(Arrays.asList(fields));
0120:                f = ISODateTimeFormat.forFields(types, false, true);
0121:                assertEquals("2005", f.print(new Partial(fields, values)));
0122:                assertEquals(0, types.size());
0123:
0124:                types = new ArrayList(Arrays.asList(fields));
0125:                f = ISODateTimeFormat.forFields(types, false, false);
0126:                assertEquals("2005", f.print(new Partial(fields, values)));
0127:                assertEquals(0, types.size());
0128:            }
0129:
0130:            //-----------------------------------------------------------------------
0131:            public void testForFields_calBased_M() {
0132:                DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType
0133:                        .monthOfYear(), };
0134:                int[] values = new int[] { 6 };
0135:                List types = new ArrayList(Arrays.asList(fields));
0136:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0137:                        true);
0138:                assertEquals("--06", f.print(new Partial(fields, values)));
0139:                assertEquals(0, types.size());
0140:
0141:                types = new ArrayList(Arrays.asList(fields));
0142:                f = ISODateTimeFormat.forFields(types, true, false);
0143:                assertEquals("--06", f.print(new Partial(fields, values)));
0144:                assertEquals(0, types.size());
0145:
0146:                types = new ArrayList(Arrays.asList(fields));
0147:                f = ISODateTimeFormat.forFields(types, false, true);
0148:                assertEquals("--06", f.print(new Partial(fields, values)));
0149:                assertEquals(0, types.size());
0150:
0151:                types = new ArrayList(Arrays.asList(fields));
0152:                f = ISODateTimeFormat.forFields(types, false, false);
0153:                assertEquals("--06", f.print(new Partial(fields, values)));
0154:                assertEquals(0, types.size());
0155:            }
0156:
0157:            //-----------------------------------------------------------------------
0158:            public void testForFields_calBased_D() {
0159:                DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType
0160:                        .dayOfMonth(), };
0161:                int[] values = new int[] { 25 };
0162:                List types = new ArrayList(Arrays.asList(fields));
0163:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0164:                        true);
0165:                assertEquals("---25", f.print(new Partial(fields, values)));
0166:                assertEquals(0, types.size());
0167:
0168:                types = new ArrayList(Arrays.asList(fields));
0169:                f = ISODateTimeFormat.forFields(types, true, false);
0170:                assertEquals("---25", f.print(new Partial(fields, values)));
0171:                assertEquals(0, types.size());
0172:
0173:                types = new ArrayList(Arrays.asList(fields));
0174:                f = ISODateTimeFormat.forFields(types, false, true);
0175:                assertEquals("---25", f.print(new Partial(fields, values)));
0176:                assertEquals(0, types.size());
0177:
0178:                types = new ArrayList(Arrays.asList(fields));
0179:                f = ISODateTimeFormat.forFields(types, false, false);
0180:                assertEquals("---25", f.print(new Partial(fields, values)));
0181:                assertEquals(0, types.size());
0182:            }
0183:
0184:            //-----------------------------------------------------------------------
0185:            public void testForFields_calBased_YM() {
0186:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0187:                        DateTimeFieldType.year(),
0188:                        DateTimeFieldType.monthOfYear(), };
0189:                int[] values = new int[] { 2005, 6 };
0190:                List types = new ArrayList(Arrays.asList(fields));
0191:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0192:                        true);
0193:                assertEquals("2005-06", f.print(new Partial(fields, values)));
0194:                assertEquals(0, types.size());
0195:
0196:                types = new ArrayList(Arrays.asList(fields));
0197:                f = ISODateTimeFormat.forFields(types, true, false);
0198:                assertEquals("2005-06", f.print(new Partial(fields, values)));
0199:                assertEquals(0, types.size());
0200:
0201:                types = new ArrayList(Arrays.asList(fields));
0202:                f = ISODateTimeFormat.forFields(types, false, true);
0203:                assertEquals("2005-06", f.print(new Partial(fields, values)));
0204:                assertEquals(0, types.size());
0205:
0206:                types = new ArrayList(Arrays.asList(fields));
0207:                f = ISODateTimeFormat.forFields(types, false, false);
0208:                assertEquals("2005-06", f.print(new Partial(fields, values)));
0209:                assertEquals(0, types.size());
0210:            }
0211:
0212:            //-----------------------------------------------------------------------
0213:            public void testForFields_calBased_MD() {
0214:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0215:                        DateTimeFieldType.monthOfYear(),
0216:                        DateTimeFieldType.dayOfMonth(), };
0217:                int[] values = new int[] { 6, 25 };
0218:                List types = new ArrayList(Arrays.asList(fields));
0219:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0220:                        true);
0221:                assertEquals("--06-25", f.print(new Partial(fields, values)));
0222:                assertEquals(0, types.size());
0223:
0224:                types = new ArrayList(Arrays.asList(fields));
0225:                f = ISODateTimeFormat.forFields(types, true, false);
0226:                assertEquals("--06-25", f.print(new Partial(fields, values)));
0227:                assertEquals(0, types.size());
0228:
0229:                types = new ArrayList(Arrays.asList(fields));
0230:                f = ISODateTimeFormat.forFields(types, false, true);
0231:                assertEquals("--0625", f.print(new Partial(fields, values)));
0232:                assertEquals(0, types.size());
0233:
0234:                types = new ArrayList(Arrays.asList(fields));
0235:                f = ISODateTimeFormat.forFields(types, false, false);
0236:                assertEquals("--0625", f.print(new Partial(fields, values)));
0237:                assertEquals(0, types.size());
0238:            }
0239:
0240:            //-----------------------------------------------------------------------
0241:            public void testForFields_calBased_YD() {
0242:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0243:                        DateTimeFieldType.year(),
0244:                        DateTimeFieldType.dayOfMonth(), };
0245:                int[] values = new int[] { 2005, 25 };
0246:                List types = new ArrayList(Arrays.asList(fields));
0247:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0248:                        false);
0249:                assertEquals("2005--25", f.print(new Partial(fields, values)));
0250:                assertEquals(0, types.size());
0251:
0252:                types = new ArrayList(Arrays.asList(fields));
0253:                f = ISODateTimeFormat.forFields(types, false, false);
0254:                assertEquals("2005--25", f.print(new Partial(fields, values)));
0255:                assertEquals(0, types.size());
0256:
0257:                types = new ArrayList(Arrays.asList(fields));
0258:                try {
0259:                    ISODateTimeFormat.forFields(types, true, true);
0260:                    fail();
0261:                } catch (IllegalArgumentException ex) {
0262:                }
0263:
0264:                types = new ArrayList(Arrays.asList(fields));
0265:                try {
0266:                    ISODateTimeFormat.forFields(types, false, true);
0267:                    fail();
0268:                } catch (IllegalArgumentException ex) {
0269:                }
0270:            }
0271:
0272:            //-----------------------------------------------------------------------
0273:            //-----------------------------------------------------------------------
0274:            //-----------------------------------------------------------------------
0275:            public void testForFields_weekBased_YWD() {
0276:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0277:                        DateTimeFieldType.weekyear(),
0278:                        DateTimeFieldType.weekOfWeekyear(),
0279:                        DateTimeFieldType.dayOfWeek(), };
0280:                int[] values = new int[] { 2005, 8, 5 };
0281:                List types = new ArrayList(Arrays.asList(fields));
0282:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0283:                        true);
0284:                assertEquals("2005-W08-5", f.print(new Partial(fields, values)));
0285:                assertEquals(0, types.size());
0286:
0287:                types = new ArrayList(Arrays.asList(fields));
0288:                f = ISODateTimeFormat.forFields(types, true, false);
0289:                assertEquals("2005-W08-5", f.print(new Partial(fields, values)));
0290:                assertEquals(0, types.size());
0291:
0292:                types = new ArrayList(Arrays.asList(fields));
0293:                f = ISODateTimeFormat.forFields(types, false, true);
0294:                assertEquals("2005W085", f.print(new Partial(fields, values)));
0295:                assertEquals(0, types.size());
0296:
0297:                types = new ArrayList(Arrays.asList(fields));
0298:                f = ISODateTimeFormat.forFields(types, false, false);
0299:                assertEquals("2005W085", f.print(new Partial(fields, values)));
0300:                assertEquals(0, types.size());
0301:            }
0302:
0303:            //-----------------------------------------------------------------------
0304:            public void testForFields_weekBased_Y() {
0305:                DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType
0306:                        .weekyear(), };
0307:                int[] values = new int[] { 2005 };
0308:                List types = new ArrayList(Arrays.asList(fields));
0309:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0310:                        true);
0311:                assertEquals("2005", f.print(new Partial(fields, values)));
0312:                assertEquals(0, types.size());
0313:
0314:                types = new ArrayList(Arrays.asList(fields));
0315:                f = ISODateTimeFormat.forFields(types, true, false);
0316:                assertEquals("2005", f.print(new Partial(fields, values)));
0317:                assertEquals(0, types.size());
0318:
0319:                types = new ArrayList(Arrays.asList(fields));
0320:                f = ISODateTimeFormat.forFields(types, false, true);
0321:                assertEquals("2005", f.print(new Partial(fields, values)));
0322:                assertEquals(0, types.size());
0323:
0324:                types = new ArrayList(Arrays.asList(fields));
0325:                f = ISODateTimeFormat.forFields(types, false, false);
0326:                assertEquals("2005", f.print(new Partial(fields, values)));
0327:                assertEquals(0, types.size());
0328:            }
0329:
0330:            //-----------------------------------------------------------------------
0331:            public void testForFields_weekBased_W() {
0332:                DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType
0333:                        .weekOfWeekyear(), };
0334:                int[] values = new int[] { 8 };
0335:                List types = new ArrayList(Arrays.asList(fields));
0336:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0337:                        true);
0338:                assertEquals("-W08", f.print(new Partial(fields, values)));
0339:                assertEquals(0, types.size());
0340:
0341:                types = new ArrayList(Arrays.asList(fields));
0342:                f = ISODateTimeFormat.forFields(types, true, false);
0343:                assertEquals("-W08", f.print(new Partial(fields, values)));
0344:                assertEquals(0, types.size());
0345:
0346:                types = new ArrayList(Arrays.asList(fields));
0347:                f = ISODateTimeFormat.forFields(types, false, true);
0348:                assertEquals("-W08", f.print(new Partial(fields, values)));
0349:                assertEquals(0, types.size());
0350:
0351:                types = new ArrayList(Arrays.asList(fields));
0352:                f = ISODateTimeFormat.forFields(types, false, false);
0353:                assertEquals("-W08", f.print(new Partial(fields, values)));
0354:                assertEquals(0, types.size());
0355:            }
0356:
0357:            //-----------------------------------------------------------------------
0358:            public void testForFields_weekBased_D() {
0359:                DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType
0360:                        .dayOfWeek(), };
0361:                int[] values = new int[] { 5 };
0362:                List types = new ArrayList(Arrays.asList(fields));
0363:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0364:                        true);
0365:                assertEquals("-W-5", f.print(new Partial(fields, values)));
0366:                assertEquals(0, types.size());
0367:
0368:                types = new ArrayList(Arrays.asList(fields));
0369:                f = ISODateTimeFormat.forFields(types, true, false);
0370:                assertEquals("-W-5", f.print(new Partial(fields, values)));
0371:                assertEquals(0, types.size());
0372:
0373:                types = new ArrayList(Arrays.asList(fields));
0374:                f = ISODateTimeFormat.forFields(types, false, true);
0375:                assertEquals("-W-5", f.print(new Partial(fields, values)));
0376:                assertEquals(0, types.size());
0377:
0378:                types = new ArrayList(Arrays.asList(fields));
0379:                f = ISODateTimeFormat.forFields(types, false, false);
0380:                assertEquals("-W-5", f.print(new Partial(fields, values)));
0381:                assertEquals(0, types.size());
0382:            }
0383:
0384:            //-----------------------------------------------------------------------
0385:            public void testForFields_weekBased_YW() {
0386:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0387:                        DateTimeFieldType.weekyear(),
0388:                        DateTimeFieldType.weekOfWeekyear(), };
0389:                int[] values = new int[] { 2005, 8 };
0390:                List types = new ArrayList(Arrays.asList(fields));
0391:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0392:                        true);
0393:                assertEquals("2005-W08", f.print(new Partial(fields, values)));
0394:                assertEquals(0, types.size());
0395:
0396:                types = new ArrayList(Arrays.asList(fields));
0397:                f = ISODateTimeFormat.forFields(types, true, false);
0398:                assertEquals("2005-W08", f.print(new Partial(fields, values)));
0399:                assertEquals(0, types.size());
0400:
0401:                types = new ArrayList(Arrays.asList(fields));
0402:                f = ISODateTimeFormat.forFields(types, false, true);
0403:                assertEquals("2005W08", f.print(new Partial(fields, values)));
0404:                assertEquals(0, types.size());
0405:
0406:                types = new ArrayList(Arrays.asList(fields));
0407:                f = ISODateTimeFormat.forFields(types, false, false);
0408:                assertEquals("2005W08", f.print(new Partial(fields, values)));
0409:                assertEquals(0, types.size());
0410:            }
0411:
0412:            //-----------------------------------------------------------------------
0413:            public void testForFields_weekBased_WD() {
0414:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0415:                        DateTimeFieldType.weekOfWeekyear(),
0416:                        DateTimeFieldType.dayOfWeek(), };
0417:                int[] values = new int[] { 8, 5 };
0418:                List types = new ArrayList(Arrays.asList(fields));
0419:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0420:                        true);
0421:                assertEquals("-W08-5", f.print(new Partial(fields, values)));
0422:                assertEquals(0, types.size());
0423:
0424:                types = new ArrayList(Arrays.asList(fields));
0425:                f = ISODateTimeFormat.forFields(types, true, false);
0426:                assertEquals("-W08-5", f.print(new Partial(fields, values)));
0427:                assertEquals(0, types.size());
0428:
0429:                types = new ArrayList(Arrays.asList(fields));
0430:                f = ISODateTimeFormat.forFields(types, false, true);
0431:                assertEquals("-W085", f.print(new Partial(fields, values)));
0432:                assertEquals(0, types.size());
0433:
0434:                types = new ArrayList(Arrays.asList(fields));
0435:                f = ISODateTimeFormat.forFields(types, false, false);
0436:                assertEquals("-W085", f.print(new Partial(fields, values)));
0437:                assertEquals(0, types.size());
0438:            }
0439:
0440:            //-----------------------------------------------------------------------
0441:            public void testForFields_weekBased_YD() {
0442:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0443:                        DateTimeFieldType.weekyear(),
0444:                        DateTimeFieldType.dayOfWeek(), };
0445:                int[] values = new int[] { 2005, 5 };
0446:                List types = new ArrayList(Arrays.asList(fields));
0447:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0448:                        false);
0449:                assertEquals("2005-W-5", f.print(new Partial(fields, values)));
0450:                assertEquals(0, types.size());
0451:
0452:                types = new ArrayList(Arrays.asList(fields));
0453:                f = ISODateTimeFormat.forFields(types, false, false);
0454:                assertEquals("2005W-5", f.print(new Partial(fields, values)));
0455:                assertEquals(0, types.size());
0456:
0457:                types = new ArrayList(Arrays.asList(fields));
0458:                try {
0459:                    ISODateTimeFormat.forFields(types, true, true);
0460:                    fail();
0461:                } catch (IllegalArgumentException ex) {
0462:                }
0463:
0464:                types = new ArrayList(Arrays.asList(fields));
0465:                try {
0466:                    ISODateTimeFormat.forFields(types, false, true);
0467:                    fail();
0468:                } catch (IllegalArgumentException ex) {
0469:                }
0470:            }
0471:
0472:            //-----------------------------------------------------------------------
0473:            //-----------------------------------------------------------------------
0474:            //-----------------------------------------------------------------------
0475:            public void testForFields_ordinalBased_YD() {
0476:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0477:                        DateTimeFieldType.year(),
0478:                        DateTimeFieldType.dayOfYear(), };
0479:                int[] values = new int[] { 2005, 177 };
0480:                List types = new ArrayList(Arrays.asList(fields));
0481:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0482:                        true);
0483:                assertEquals("2005-177", f.print(new Partial(fields, values)));
0484:                assertEquals(0, types.size());
0485:
0486:                types = new ArrayList(Arrays.asList(fields));
0487:                f = ISODateTimeFormat.forFields(types, true, false);
0488:                assertEquals("2005-177", f.print(new Partial(fields, values)));
0489:                assertEquals(0, types.size());
0490:
0491:                types = new ArrayList(Arrays.asList(fields));
0492:                f = ISODateTimeFormat.forFields(types, false, true);
0493:                assertEquals("2005177", f.print(new Partial(fields, values)));
0494:                assertEquals(0, types.size());
0495:
0496:                types = new ArrayList(Arrays.asList(fields));
0497:                f = ISODateTimeFormat.forFields(types, false, false);
0498:                assertEquals("2005177", f.print(new Partial(fields, values)));
0499:                assertEquals(0, types.size());
0500:            }
0501:
0502:            //-----------------------------------------------------------------------
0503:            public void testForFields_ordinalBased_Y() {
0504:                DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType
0505:                        .year(), };
0506:                int[] values = new int[] { 2005 };
0507:                List types = new ArrayList(Arrays.asList(fields));
0508:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0509:                        true);
0510:                assertEquals("2005", f.print(new Partial(fields, values)));
0511:                assertEquals(0, types.size());
0512:
0513:                types = new ArrayList(Arrays.asList(fields));
0514:                f = ISODateTimeFormat.forFields(types, true, false);
0515:                assertEquals("2005", f.print(new Partial(fields, values)));
0516:                assertEquals(0, types.size());
0517:
0518:                types = new ArrayList(Arrays.asList(fields));
0519:                f = ISODateTimeFormat.forFields(types, false, true);
0520:                assertEquals("2005", f.print(new Partial(fields, values)));
0521:                assertEquals(0, types.size());
0522:
0523:                types = new ArrayList(Arrays.asList(fields));
0524:                f = ISODateTimeFormat.forFields(types, false, false);
0525:                assertEquals("2005", f.print(new Partial(fields, values)));
0526:                assertEquals(0, types.size());
0527:            }
0528:
0529:            //-----------------------------------------------------------------------
0530:            public void testForFields_ordinalBased_D() {
0531:                DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType
0532:                        .dayOfYear(), };
0533:                int[] values = new int[] { 177 };
0534:                List types = new ArrayList(Arrays.asList(fields));
0535:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0536:                        true);
0537:                assertEquals("-177", f.print(new Partial(fields, values)));
0538:                assertEquals(0, types.size());
0539:
0540:                types = new ArrayList(Arrays.asList(fields));
0541:                f = ISODateTimeFormat.forFields(types, true, false);
0542:                assertEquals("-177", f.print(new Partial(fields, values)));
0543:                assertEquals(0, types.size());
0544:
0545:                types = new ArrayList(Arrays.asList(fields));
0546:                f = ISODateTimeFormat.forFields(types, false, true);
0547:                assertEquals("-177", f.print(new Partial(fields, values)));
0548:                assertEquals(0, types.size());
0549:
0550:                types = new ArrayList(Arrays.asList(fields));
0551:                f = ISODateTimeFormat.forFields(types, false, false);
0552:                assertEquals("-177", f.print(new Partial(fields, values)));
0553:                assertEquals(0, types.size());
0554:            }
0555:
0556:            //-----------------------------------------------------------------------
0557:            //-----------------------------------------------------------------------
0558:            //-----------------------------------------------------------------------
0559:            public void testForFields_time_HMSm() {
0560:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0561:                        DateTimeFieldType.hourOfDay(),
0562:                        DateTimeFieldType.minuteOfHour(),
0563:                        DateTimeFieldType.secondOfMinute(),
0564:                        DateTimeFieldType.millisOfSecond(), };
0565:                int[] values = new int[] { 10, 20, 30, 40 };
0566:                List types = new ArrayList(Arrays.asList(fields));
0567:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0568:                        true);
0569:                assertEquals("10:20:30.040", f
0570:                        .print(new Partial(fields, values)));
0571:                assertEquals(0, types.size());
0572:
0573:                types = new ArrayList(Arrays.asList(fields));
0574:                f = ISODateTimeFormat.forFields(types, true, false);
0575:                assertEquals("10:20:30.040", f
0576:                        .print(new Partial(fields, values)));
0577:                assertEquals(0, types.size());
0578:
0579:                types = new ArrayList(Arrays.asList(fields));
0580:                f = ISODateTimeFormat.forFields(types, false, true);
0581:                assertEquals("102030.040", f.print(new Partial(fields, values)));
0582:                assertEquals(0, types.size());
0583:
0584:                types = new ArrayList(Arrays.asList(fields));
0585:                f = ISODateTimeFormat.forFields(types, false, false);
0586:                assertEquals("102030.040", f.print(new Partial(fields, values)));
0587:                assertEquals(0, types.size());
0588:            }
0589:
0590:            //-----------------------------------------------------------------------
0591:            public void testForFields_time_HMS() {
0592:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0593:                        DateTimeFieldType.hourOfDay(),
0594:                        DateTimeFieldType.minuteOfHour(),
0595:                        DateTimeFieldType.secondOfMinute(), };
0596:                int[] values = new int[] { 10, 20, 30 };
0597:                List types = new ArrayList(Arrays.asList(fields));
0598:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0599:                        true);
0600:                assertEquals("10:20:30", f.print(new Partial(fields, values)));
0601:                assertEquals(0, types.size());
0602:
0603:                types = new ArrayList(Arrays.asList(fields));
0604:                f = ISODateTimeFormat.forFields(types, true, false);
0605:                assertEquals("10:20:30", f.print(new Partial(fields, values)));
0606:                assertEquals(0, types.size());
0607:
0608:                types = new ArrayList(Arrays.asList(fields));
0609:                f = ISODateTimeFormat.forFields(types, false, true);
0610:                assertEquals("102030", f.print(new Partial(fields, values)));
0611:                assertEquals(0, types.size());
0612:
0613:                types = new ArrayList(Arrays.asList(fields));
0614:                f = ISODateTimeFormat.forFields(types, false, false);
0615:                assertEquals("102030", f.print(new Partial(fields, values)));
0616:                assertEquals(0, types.size());
0617:            }
0618:
0619:            //-----------------------------------------------------------------------
0620:            public void testForFields_time_HM() {
0621:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0622:                        DateTimeFieldType.hourOfDay(),
0623:                        DateTimeFieldType.minuteOfHour(), };
0624:                int[] values = new int[] { 10, 20 };
0625:                List types = new ArrayList(Arrays.asList(fields));
0626:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0627:                        true);
0628:                assertEquals("10:20", f.print(new Partial(fields, values)));
0629:                assertEquals(0, types.size());
0630:
0631:                types = new ArrayList(Arrays.asList(fields));
0632:                f = ISODateTimeFormat.forFields(types, true, false);
0633:                assertEquals("10:20", f.print(new Partial(fields, values)));
0634:                assertEquals(0, types.size());
0635:
0636:                types = new ArrayList(Arrays.asList(fields));
0637:                f = ISODateTimeFormat.forFields(types, false, true);
0638:                assertEquals("1020", f.print(new Partial(fields, values)));
0639:                assertEquals(0, types.size());
0640:
0641:                types = new ArrayList(Arrays.asList(fields));
0642:                f = ISODateTimeFormat.forFields(types, false, false);
0643:                assertEquals("1020", f.print(new Partial(fields, values)));
0644:                assertEquals(0, types.size());
0645:            }
0646:
0647:            //-----------------------------------------------------------------------
0648:            public void testForFields_time_H() {
0649:                DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType
0650:                        .hourOfDay(), };
0651:                int[] values = new int[] { 10 };
0652:                List types = new ArrayList(Arrays.asList(fields));
0653:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0654:                        true);
0655:                assertEquals("10", f.print(new Partial(fields, values)));
0656:                assertEquals(0, types.size());
0657:
0658:                types = new ArrayList(Arrays.asList(fields));
0659:                f = ISODateTimeFormat.forFields(types, true, false);
0660:                assertEquals("10", f.print(new Partial(fields, values)));
0661:                assertEquals(0, types.size());
0662:
0663:                types = new ArrayList(Arrays.asList(fields));
0664:                f = ISODateTimeFormat.forFields(types, false, true);
0665:                assertEquals("10", f.print(new Partial(fields, values)));
0666:                assertEquals(0, types.size());
0667:
0668:                types = new ArrayList(Arrays.asList(fields));
0669:                f = ISODateTimeFormat.forFields(types, false, false);
0670:                assertEquals("10", f.print(new Partial(fields, values)));
0671:                assertEquals(0, types.size());
0672:            }
0673:
0674:            //-----------------------------------------------------------------------
0675:            public void testForFields_time_MSm() {
0676:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0677:                        DateTimeFieldType.minuteOfHour(),
0678:                        DateTimeFieldType.secondOfMinute(),
0679:                        DateTimeFieldType.millisOfSecond(), };
0680:                int[] values = new int[] { 20, 30, 40 };
0681:                List types = new ArrayList(Arrays.asList(fields));
0682:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0683:                        true);
0684:                assertEquals("-20:30.040", f.print(new Partial(fields, values)));
0685:                assertEquals(0, types.size());
0686:
0687:                types = new ArrayList(Arrays.asList(fields));
0688:                f = ISODateTimeFormat.forFields(types, true, false);
0689:                assertEquals("-20:30.040", f.print(new Partial(fields, values)));
0690:                assertEquals(0, types.size());
0691:
0692:                types = new ArrayList(Arrays.asList(fields));
0693:                f = ISODateTimeFormat.forFields(types, false, true);
0694:                assertEquals("-2030.040", f.print(new Partial(fields, values)));
0695:                assertEquals(0, types.size());
0696:
0697:                types = new ArrayList(Arrays.asList(fields));
0698:                f = ISODateTimeFormat.forFields(types, false, false);
0699:                assertEquals("-2030.040", f.print(new Partial(fields, values)));
0700:                assertEquals(0, types.size());
0701:            }
0702:
0703:            //-----------------------------------------------------------------------
0704:            public void testForFields_time_MS() {
0705:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0706:                        DateTimeFieldType.minuteOfHour(),
0707:                        DateTimeFieldType.secondOfMinute(), };
0708:                int[] values = new int[] { 20, 30 };
0709:                List types = new ArrayList(Arrays.asList(fields));
0710:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0711:                        true);
0712:                assertEquals("-20:30", f.print(new Partial(fields, values)));
0713:                assertEquals(0, types.size());
0714:
0715:                types = new ArrayList(Arrays.asList(fields));
0716:                f = ISODateTimeFormat.forFields(types, true, false);
0717:                assertEquals("-20:30", f.print(new Partial(fields, values)));
0718:                assertEquals(0, types.size());
0719:
0720:                types = new ArrayList(Arrays.asList(fields));
0721:                f = ISODateTimeFormat.forFields(types, false, true);
0722:                assertEquals("-2030", f.print(new Partial(fields, values)));
0723:                assertEquals(0, types.size());
0724:
0725:                types = new ArrayList(Arrays.asList(fields));
0726:                f = ISODateTimeFormat.forFields(types, false, false);
0727:                assertEquals("-2030", f.print(new Partial(fields, values)));
0728:                assertEquals(0, types.size());
0729:            }
0730:
0731:            //-----------------------------------------------------------------------
0732:            public void testForFields_time_M() {
0733:                DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType
0734:                        .minuteOfHour(), };
0735:                int[] values = new int[] { 20 };
0736:                List types = new ArrayList(Arrays.asList(fields));
0737:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0738:                        true);
0739:                assertEquals("-20", f.print(new Partial(fields, values)));
0740:                assertEquals(0, types.size());
0741:
0742:                types = new ArrayList(Arrays.asList(fields));
0743:                f = ISODateTimeFormat.forFields(types, true, false);
0744:                assertEquals("-20", f.print(new Partial(fields, values)));
0745:                assertEquals(0, types.size());
0746:
0747:                types = new ArrayList(Arrays.asList(fields));
0748:                f = ISODateTimeFormat.forFields(types, false, true);
0749:                assertEquals("-20", f.print(new Partial(fields, values)));
0750:                assertEquals(0, types.size());
0751:
0752:                types = new ArrayList(Arrays.asList(fields));
0753:                f = ISODateTimeFormat.forFields(types, false, false);
0754:                assertEquals("-20", f.print(new Partial(fields, values)));
0755:                assertEquals(0, types.size());
0756:            }
0757:
0758:            //-----------------------------------------------------------------------
0759:            public void testForFields_time_Sm() {
0760:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0761:                        DateTimeFieldType.secondOfMinute(),
0762:                        DateTimeFieldType.millisOfSecond(), };
0763:                int[] values = new int[] { 30, 40 };
0764:                List types = new ArrayList(Arrays.asList(fields));
0765:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0766:                        true);
0767:                assertEquals("--30.040", f.print(new Partial(fields, values)));
0768:                assertEquals(0, types.size());
0769:
0770:                types = new ArrayList(Arrays.asList(fields));
0771:                f = ISODateTimeFormat.forFields(types, true, false);
0772:                assertEquals("--30.040", f.print(new Partial(fields, values)));
0773:                assertEquals(0, types.size());
0774:
0775:                types = new ArrayList(Arrays.asList(fields));
0776:                f = ISODateTimeFormat.forFields(types, false, true);
0777:                assertEquals("--30.040", f.print(new Partial(fields, values)));
0778:                assertEquals(0, types.size());
0779:
0780:                types = new ArrayList(Arrays.asList(fields));
0781:                f = ISODateTimeFormat.forFields(types, false, false);
0782:                assertEquals("--30.040", f.print(new Partial(fields, values)));
0783:                assertEquals(0, types.size());
0784:            }
0785:
0786:            //-----------------------------------------------------------------------
0787:            public void testForFields_time_S() {
0788:                DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType
0789:                        .secondOfMinute(), };
0790:                int[] values = new int[] { 30 };
0791:                List types = new ArrayList(Arrays.asList(fields));
0792:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0793:                        true);
0794:                assertEquals("--30", f.print(new Partial(fields, values)));
0795:                assertEquals(0, types.size());
0796:
0797:                types = new ArrayList(Arrays.asList(fields));
0798:                f = ISODateTimeFormat.forFields(types, true, false);
0799:                assertEquals("--30", f.print(new Partial(fields, values)));
0800:                assertEquals(0, types.size());
0801:
0802:                types = new ArrayList(Arrays.asList(fields));
0803:                f = ISODateTimeFormat.forFields(types, false, true);
0804:                assertEquals("--30", f.print(new Partial(fields, values)));
0805:                assertEquals(0, types.size());
0806:
0807:                types = new ArrayList(Arrays.asList(fields));
0808:                f = ISODateTimeFormat.forFields(types, false, false);
0809:                assertEquals("--30", f.print(new Partial(fields, values)));
0810:                assertEquals(0, types.size());
0811:            }
0812:
0813:            //-----------------------------------------------------------------------
0814:            public void testForFields_time_m() {
0815:                DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType
0816:                        .millisOfSecond(), };
0817:                int[] values = new int[] { 40 };
0818:                List types = new ArrayList(Arrays.asList(fields));
0819:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0820:                        false);
0821:                assertEquals("---.040", f.print(new Partial(fields, values)));
0822:                assertEquals(0, types.size());
0823:
0824:                types = new ArrayList(Arrays.asList(fields));
0825:                f = ISODateTimeFormat.forFields(types, false, false);
0826:                assertEquals("---.040", f.print(new Partial(fields, values)));
0827:                assertEquals(0, types.size());
0828:
0829:                types = new ArrayList(Arrays.asList(fields));
0830:                try {
0831:                    ISODateTimeFormat.forFields(types, true, true);
0832:                    fail();
0833:                } catch (IllegalArgumentException ex) {
0834:                }
0835:
0836:                types = new ArrayList(Arrays.asList(fields));
0837:                try {
0838:                    ISODateTimeFormat.forFields(types, false, true);
0839:                    fail();
0840:                } catch (IllegalArgumentException ex) {
0841:                }
0842:            }
0843:
0844:            //-----------------------------------------------------------------------
0845:            public void testForFields_time_Hm() {
0846:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0847:                        DateTimeFieldType.hourOfDay(),
0848:                        DateTimeFieldType.millisOfSecond(), };
0849:                int[] values = new int[] { 10, 40 };
0850:                List types = new ArrayList(Arrays.asList(fields));
0851:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0852:                        false);
0853:                assertEquals("10--.040", f.print(new Partial(fields, values)));
0854:                assertEquals(0, types.size());
0855:
0856:                types = new ArrayList(Arrays.asList(fields));
0857:                f = ISODateTimeFormat.forFields(types, false, false);
0858:                assertEquals("10--.040", f.print(new Partial(fields, values)));
0859:                assertEquals(0, types.size());
0860:
0861:                types = new ArrayList(Arrays.asList(fields));
0862:                try {
0863:                    ISODateTimeFormat.forFields(types, true, true);
0864:                    fail();
0865:                } catch (IllegalArgumentException ex) {
0866:                }
0867:
0868:                types = new ArrayList(Arrays.asList(fields));
0869:                try {
0870:                    ISODateTimeFormat.forFields(types, false, true);
0871:                    fail();
0872:                } catch (IllegalArgumentException ex) {
0873:                }
0874:            }
0875:
0876:            //-----------------------------------------------------------------------
0877:            public void testForFields_time_HS() {
0878:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0879:                        DateTimeFieldType.hourOfDay(),
0880:                        DateTimeFieldType.secondOfMinute(), };
0881:                int[] values = new int[] { 10, 30 };
0882:                List types = new ArrayList(Arrays.asList(fields));
0883:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0884:                        false);
0885:                assertEquals("10-30", f.print(new Partial(fields, values)));
0886:                assertEquals(0, types.size());
0887:
0888:                types = new ArrayList(Arrays.asList(fields));
0889:                f = ISODateTimeFormat.forFields(types, false, false);
0890:                assertEquals("10-30", f.print(new Partial(fields, values)));
0891:                assertEquals(0, types.size());
0892:
0893:                types = new ArrayList(Arrays.asList(fields));
0894:                try {
0895:                    ISODateTimeFormat.forFields(types, true, true);
0896:                    fail();
0897:                } catch (IllegalArgumentException ex) {
0898:                }
0899:
0900:                types = new ArrayList(Arrays.asList(fields));
0901:                try {
0902:                    ISODateTimeFormat.forFields(types, false, true);
0903:                    fail();
0904:                } catch (IllegalArgumentException ex) {
0905:                }
0906:            }
0907:
0908:            //-----------------------------------------------------------------------
0909:            public void testForFields_time_Mm() {
0910:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0911:                        DateTimeFieldType.minuteOfHour(),
0912:                        DateTimeFieldType.millisOfSecond(), };
0913:                int[] values = new int[] { 20, 40 };
0914:                List types = new ArrayList(Arrays.asList(fields));
0915:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0916:                        false);
0917:                assertEquals("-20-.040", f.print(new Partial(fields, values)));
0918:                assertEquals(0, types.size());
0919:
0920:                types = new ArrayList(Arrays.asList(fields));
0921:                f = ISODateTimeFormat.forFields(types, false, false);
0922:                assertEquals("-20-.040", f.print(new Partial(fields, values)));
0923:                assertEquals(0, types.size());
0924:
0925:                types = new ArrayList(Arrays.asList(fields));
0926:                try {
0927:                    ISODateTimeFormat.forFields(types, true, true);
0928:                    fail();
0929:                } catch (IllegalArgumentException ex) {
0930:                }
0931:
0932:                types = new ArrayList(Arrays.asList(fields));
0933:                try {
0934:                    ISODateTimeFormat.forFields(types, false, true);
0935:                    fail();
0936:                } catch (IllegalArgumentException ex) {
0937:                }
0938:            }
0939:
0940:            //-----------------------------------------------------------------------
0941:            public void testForFields_time_HSm() {
0942:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0943:                        DateTimeFieldType.hourOfDay(),
0944:                        DateTimeFieldType.secondOfMinute(),
0945:                        DateTimeFieldType.millisOfSecond(), };
0946:                int[] values = new int[] { 10, 30, 40 };
0947:                List types = new ArrayList(Arrays.asList(fields));
0948:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0949:                        false);
0950:                assertEquals("10-30.040", f.print(new Partial(fields, values)));
0951:                assertEquals(0, types.size());
0952:
0953:                types = new ArrayList(Arrays.asList(fields));
0954:                f = ISODateTimeFormat.forFields(types, false, false);
0955:                assertEquals("10-30.040", f.print(new Partial(fields, values)));
0956:                assertEquals(0, types.size());
0957:
0958:                types = new ArrayList(Arrays.asList(fields));
0959:                try {
0960:                    ISODateTimeFormat.forFields(types, true, true);
0961:                    fail();
0962:                } catch (IllegalArgumentException ex) {
0963:                }
0964:
0965:                types = new ArrayList(Arrays.asList(fields));
0966:                try {
0967:                    ISODateTimeFormat.forFields(types, false, true);
0968:                    fail();
0969:                } catch (IllegalArgumentException ex) {
0970:                }
0971:            }
0972:
0973:            //-----------------------------------------------------------------------
0974:            public void testForFields_time_HMm() {
0975:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
0976:                        DateTimeFieldType.hourOfDay(),
0977:                        DateTimeFieldType.minuteOfHour(),
0978:                        DateTimeFieldType.millisOfSecond(), };
0979:                int[] values = new int[] { 10, 20, 40 };
0980:                List types = new ArrayList(Arrays.asList(fields));
0981:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
0982:                        false);
0983:                assertEquals("10:20-.040", f.print(new Partial(fields, values)));
0984:                assertEquals(0, types.size());
0985:
0986:                types = new ArrayList(Arrays.asList(fields));
0987:                f = ISODateTimeFormat.forFields(types, false, false);
0988:                assertEquals("1020-.040", f.print(new Partial(fields, values)));
0989:                assertEquals(0, types.size());
0990:
0991:                types = new ArrayList(Arrays.asList(fields));
0992:                try {
0993:                    ISODateTimeFormat.forFields(types, true, true);
0994:                    fail();
0995:                } catch (IllegalArgumentException ex) {
0996:                }
0997:
0998:                types = new ArrayList(Arrays.asList(fields));
0999:                try {
1000:                    ISODateTimeFormat.forFields(types, false, true);
1001:                    fail();
1002:                } catch (IllegalArgumentException ex) {
1003:                }
1004:            }
1005:
1006:            //-----------------------------------------------------------------------
1007:            //-----------------------------------------------------------------------
1008:            //-----------------------------------------------------------------------
1009:            public void testForFields_datetime_YMDH() {
1010:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
1011:                        DateTimeFieldType.year(),
1012:                        DateTimeFieldType.monthOfYear(),
1013:                        DateTimeFieldType.dayOfMonth(),
1014:                        DateTimeFieldType.hourOfDay(), };
1015:                int[] values = new int[] { 2005, 6, 25, 12 };
1016:                List types = new ArrayList(Arrays.asList(fields));
1017:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
1018:                        true);
1019:                assertEquals("2005-06-25T12", f.print(new Partial(fields,
1020:                        values)));
1021:                assertEquals(0, types.size());
1022:
1023:                types = new ArrayList(Arrays.asList(fields));
1024:                f = ISODateTimeFormat.forFields(types, true, false);
1025:                assertEquals("2005-06-25T12", f.print(new Partial(fields,
1026:                        values)));
1027:                assertEquals(0, types.size());
1028:
1029:                types = new ArrayList(Arrays.asList(fields));
1030:                f = ISODateTimeFormat.forFields(types, false, true);
1031:                assertEquals("20050625T12", f
1032:                        .print(new Partial(fields, values)));
1033:                assertEquals(0, types.size());
1034:
1035:                types = new ArrayList(Arrays.asList(fields));
1036:                f = ISODateTimeFormat.forFields(types, false, false);
1037:                assertEquals("20050625T12", f
1038:                        .print(new Partial(fields, values)));
1039:                assertEquals(0, types.size());
1040:            }
1041:
1042:            //-----------------------------------------------------------------------
1043:            public void testForFields_datetime_DH() {
1044:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
1045:                        DateTimeFieldType.dayOfMonth(),
1046:                        DateTimeFieldType.hourOfDay(), };
1047:                int[] values = new int[] { 25, 12 };
1048:                List types = new ArrayList(Arrays.asList(fields));
1049:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
1050:                        true);
1051:                assertEquals("---25T12", f.print(new Partial(fields, values)));
1052:                assertEquals(0, types.size());
1053:
1054:                types = new ArrayList(Arrays.asList(fields));
1055:                f = ISODateTimeFormat.forFields(types, true, false);
1056:                assertEquals("---25T12", f.print(new Partial(fields, values)));
1057:                assertEquals(0, types.size());
1058:
1059:                types = new ArrayList(Arrays.asList(fields));
1060:                f = ISODateTimeFormat.forFields(types, false, true);
1061:                assertEquals("---25T12", f.print(new Partial(fields, values)));
1062:                assertEquals(0, types.size());
1063:
1064:                types = new ArrayList(Arrays.asList(fields));
1065:                f = ISODateTimeFormat.forFields(types, false, false);
1066:                assertEquals("---25T12", f.print(new Partial(fields, values)));
1067:                assertEquals(0, types.size());
1068:            }
1069:
1070:            //-----------------------------------------------------------------------
1071:            public void testForFields_datetime_YH() {
1072:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
1073:                        DateTimeFieldType.year(),
1074:                        DateTimeFieldType.hourOfDay(), };
1075:                int[] values = new int[] { 2005, 12 };
1076:                List types = new ArrayList(Arrays.asList(fields));
1077:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
1078:                        false);
1079:                assertEquals("2005T12", f.print(new Partial(fields, values)));
1080:                assertEquals(0, types.size());
1081:
1082:                types = new ArrayList(Arrays.asList(fields));
1083:                f = ISODateTimeFormat.forFields(types, false, false);
1084:                assertEquals("2005T12", f.print(new Partial(fields, values)));
1085:                assertEquals(0, types.size());
1086:
1087:                types = new ArrayList(Arrays.asList(fields));
1088:                try {
1089:                    ISODateTimeFormat.forFields(types, true, true);
1090:                    fail();
1091:                } catch (IllegalArgumentException ex) {
1092:                }
1093:
1094:                types = new ArrayList(Arrays.asList(fields));
1095:                try {
1096:                    ISODateTimeFormat.forFields(types, false, true);
1097:                    fail();
1098:                } catch (IllegalArgumentException ex) {
1099:                }
1100:            }
1101:
1102:            //-----------------------------------------------------------------------
1103:            public void testForFields_datetime_DM() {
1104:                DateTimeFieldType[] fields = new DateTimeFieldType[] {
1105:                        DateTimeFieldType.dayOfMonth(),
1106:                        DateTimeFieldType.minuteOfHour(), };
1107:                int[] values = new int[] { 25, 20 };
1108:                List types = new ArrayList(Arrays.asList(fields));
1109:                DateTimeFormatter f = ISODateTimeFormat.forFields(types, true,
1110:                        false);
1111:                assertEquals("---25T-20", f.print(new Partial(fields, values)));
1112:                assertEquals(0, types.size());
1113:
1114:                types = new ArrayList(Arrays.asList(fields));
1115:                f = ISODateTimeFormat.forFields(types, false, false);
1116:                assertEquals("---25T-20", f.print(new Partial(fields, values)));
1117:                assertEquals(0, types.size());
1118:
1119:                types = new ArrayList(Arrays.asList(fields));
1120:                try {
1121:                    ISODateTimeFormat.forFields(types, true, true);
1122:                    fail();
1123:                } catch (IllegalArgumentException ex) {
1124:                }
1125:
1126:                types = new ArrayList(Arrays.asList(fields));
1127:                try {
1128:                    ISODateTimeFormat.forFields(types, false, true);
1129:                    fail();
1130:                } catch (IllegalArgumentException ex) {
1131:                }
1132:            }
1133:
1134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.