Source Code Cross Referenced for OptionsTest.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) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */package org.apache.commons.cli;
017:
018:        import java.util.ArrayList;
019:        import java.util.Collection;
020:
021:        import junit.framework.Test;
022:        import junit.framework.TestCase;
023:        import junit.framework.TestSuite;
024:
025:        /**
026:         * @author Rob Oxspring [email protected]
027:         * @version $Revision: 544360 $
028:         */
029:        public class OptionsTest extends TestCase {
030:
031:            public static Test suite() {
032:                return new TestSuite(OptionsTest.class);
033:            }
034:
035:            public OptionsTest(String name) {
036:                super (name);
037:            }
038:
039:            public void setUp() {
040:            }
041:
042:            public void tearDown() {
043:            }
044:
045:            public void testHelpOptions() {
046:
047:                Option longOnly1 = OptionBuilder.withLongOpt("long-only1")
048:                        .create();
049:
050:                Option longOnly2 = OptionBuilder.withLongOpt("long-only2")
051:                        .create();
052:
053:                Option shortOnly1 = OptionBuilder.create("1");
054:
055:                Option shortOnly2 = OptionBuilder.create("2");
056:
057:                Option bothA = OptionBuilder.withLongOpt("bothA").create("a");
058:
059:                Option bothB = OptionBuilder.withLongOpt("bothB").create("b");
060:
061:                Options options = new Options();
062:                options.addOption(longOnly1);
063:                options.addOption(longOnly2);
064:                options.addOption(shortOnly1);
065:                options.addOption(shortOnly2);
066:                options.addOption(bothA);
067:                options.addOption(bothB);
068:
069:                Collection allOptions = new ArrayList();
070:                allOptions.add(longOnly1);
071:                allOptions.add(longOnly2);
072:                allOptions.add(shortOnly1);
073:                allOptions.add(shortOnly2);
074:                allOptions.add(bothA);
075:                allOptions.add(bothB);
076:
077:                Collection helpOptions = options.helpOptions();
078:
079:                assertTrue("Everything in all should be in help", helpOptions
080:                        .containsAll(allOptions));
081:                assertTrue("Everything in help should be in all", allOptions
082:                        .containsAll(helpOptions));
083:            }
084:
085:            public void testMissingOptionException() throws ParseException {
086:                Options options = new Options();
087:                options.addOption(OptionBuilder.isRequired().create("f"));
088:                try {
089:                    new PosixParser().parse(options, new String[0]);
090:                    fail("Expected MissingOptionException to be thrown");
091:                } catch (MissingOptionException e) {
092:                    assertEquals("Missing required option: f", e.getMessage());
093:                }
094:            }
095:
096:            public void testMissingOptionsException() throws ParseException {
097:                Options options = new Options();
098:                options.addOption(OptionBuilder.isRequired().create("f"));
099:                options.addOption(OptionBuilder.isRequired().create("x"));
100:                try {
101:                    new PosixParser().parse(options, new String[0]);
102:                    fail("Expected MissingOptionException to be thrown");
103:                } catch (MissingOptionException e) {
104:                    assertEquals("Missing required options: fx", e.getMessage());
105:                }
106:            }
107:
108:        }
ww___w___.__j_a___va__2s__.c___om | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.