Source Code Cross Referenced for PatternOptionBuilderTest.java in  » Open-Source-Library » Apache-command-line » org » apache » commons » cli » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. JDK Core
2. JDK Modules
3. JDK Modules com.sun
4. JDK Modules com.sun.java
5. JDK Modules Platform
6. JDK Modules sun
7. Open Source Build
8. Open Source Graphic Library
9. Open Source IDE Eclipse
10. Open Source J2EE
11. Open Source JDBC Driver
12. Open Source Library
13. Open Source Library Database
14. Open Source Net
15. Open Source Script
16. Science
17. Security
18. Sevlet Container
19. SUN GlassFish
20. Swing Library
21. Web Services apache cxf 2.0.1
22. Web Services AXIS2
23. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java Source Code / Java Documentation » Open Source Library » Apache command line » org.apache.commons.cli 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        /**
02:         * Licensed to the Apache Software Foundation (ASF) under one or more
03:         * contributor license agreements.  See the NOTICE file distributed with
04:         * this work for additional information regarding copyright ownership.
05:         * The ASF licenses this file to You under the Apache License, Version 2.0
06:         * (the "License"); you may not use this file except in compliance with
07:         * the License.  You may obtain a copy of the License at
08:         *
09:         *     http://www.apache.org/licenses/LICENSE-2.0
10:         *
11:         * Unless required by applicable law or agreed to in writing, software
12:         * distributed under the License is distributed on an "AS IS" BASIS,
13:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14:         * See the License for the specific language governing permissions and
15:         * limitations under the License.
16:         */package org.apache.commons.cli;
17:
18:        import junit.framework.TestCase;
19:        import junit.framework.TestSuite;
20:
21:        /** 
22:         * Test case for the PatternOptionBuilder class 
23:         *
24:         * @author Henri Yandell
25:         **/
26:        public class PatternOptionBuilderTest extends TestCase {
27:
28:            public static TestSuite suite() {
29:                return new TestSuite(PatternOptionBuilderTest.class);
30:            }
31:
32:            public void testSimplePattern() {
33:                try {
34:                    Options options = PatternOptionBuilder
35:                            .parsePattern("a:b@cde>f+n%t/");
36:                    String[] args = new String[] { "-c", "-a", "foo", "-b",
37:                            "java.util.Vector", "-e", "build.xml", "-f",
38:                            "java.util.Calendar", "-n", "4.5", "-t",
39:                            "http://jakarta.apache.org/" };
40:
41:                    CommandLineParser parser = new PosixParser();
42:                    CommandLine line = parser.parse(options, args);
43:
44:                    assertEquals("flag a", "foo", line.getOptionValue("a"));
45:                    assertEquals("string flag a", "foo", line
46:                            .getOptionObject("a"));
47:                    assertEquals("object flag b", new java.util.Vector(), line
48:                            .getOptionObject("b"));
49:                    assertTrue("boolean true flag c", line.hasOption("c"));
50:                    assertFalse("boolean false flag d", line.hasOption("d"));
51:                    assertEquals("file flag e", new java.io.File("build.xml"),
52:                            line.getOptionObject("e"));
53:                    assertEquals("class flag f", java.util.Calendar.class, line
54:                            .getOptionObject("f"));
55:                    assertEquals("number flag n", new Double(4.5), line
56:                            .getOptionObject("n"));
57:                    assertEquals("url flag t", new java.net.URL(
58:                            "http://jakarta.apache.org/"), line
59:                            .getOptionObject("t"));
60:
61:                    // tests the char methods of CommandLine that delegate to the String methods
62:                    assertEquals("flag a", "foo", line.getOptionValue('a'));
63:                    assertEquals("string flag a", "foo", line
64:                            .getOptionObject('a'));
65:                    assertEquals("object flag b", new java.util.Vector(), line
66:                            .getOptionObject('b'));
67:                    assertTrue("boolean true flag c", line.hasOption('c'));
68:                    assertFalse("boolean false flag d", line.hasOption('d'));
69:                    assertEquals("file flag e", new java.io.File("build.xml"),
70:                            line.getOptionObject('e'));
71:                    assertEquals("class flag f", java.util.Calendar.class, line
72:                            .getOptionObject('f'));
73:                    assertEquals("number flag n", new Double(4.5), line
74:                            .getOptionObject('n'));
75:                    assertEquals("url flag t", new java.net.URL(
76:                            "http://jakarta.apache.org/"), line
77:                            .getOptionObject('t'));
78:
79:                    /// DATES NOT SUPPORTED YET.
80:                    //      assertEquals("number flag t", new java.util.Date(1023400137276L), line.getOptionObject('z'));
81:                    //     input is:  "Thu Jun 06 17:48:57 EDT 2002"
82:                } catch (ParseException exp) {
83:                    fail(exp.getMessage());
84:                } catch (java.net.MalformedURLException exp) {
85:                    fail(exp.getMessage());
86:                }
87:            }
88:
89:        }
w_ww_.___j_a___va2s___.___c_om__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.