Source Code Cross Referenced for OptionParserHelpTest.java in  » Development » JOpt-Simple » joptsimple » 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 » JOpt Simple » joptsimple 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         Copyright 2004-2007 Paul R. Holser, Jr.  All rights reserved.
003:         Licensed under the Academic Free License version 3.0
004:         */
005:
006:        package joptsimple;
007:
008:        import java.io.ByteArrayOutputStream;
009:        import java.io.StringWriter;
010:
011:        /**
012:         * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
013:         * @version $Id: OptionParserHelpTest.java,v 1.10 2007/04/10 20:06:26 pholser Exp $
014:         */
015:        public class OptionParserHelpTest extends AbstractOptionParserFixture {
016:            private StringWriter sink;
017:
018:            protected void setUp() throws Exception {
019:                super .setUp();
020:
021:                sink = new StringWriter();
022:            }
023:
024:            public void testUnconfiguredParser() throws Exception {
025:                parser.printHelpOn(sink);
026:
027:                assertEquals("No options specified", sink.toString());
028:            }
029:
030:            public void testOneOptionNoArgNoDescription() throws Exception {
031:                parser.accepts("apple");
032:
033:                parser.printHelpOn(sink);
034:
035:                String[] expectedLines = { "Option  Description ",
036:                        "------- ----------- ", "--apple             ", "" };
037:                assertEquals(Helpers
038:                        .join(expectedLines, Helpers.LINE_SEPARATOR), sink
039:                        .toString());
040:            }
041:
042:            public void testOneOptionNoArgWithDescription() throws Exception {
043:                parser.accepts("a", "some description");
044:
045:                parser.printHelpOn(sink);
046:
047:                String[] expectedLines = { "Option Description      ",
048:                        "------ ---------------- ", "-a     some description ",
049:                        "" };
050:                assertEquals(Helpers
051:                        .join(expectedLines, Helpers.LINE_SEPARATOR), sink
052:                        .toString());
053:            }
054:
055:            public void testTwoOptionsNoArgWithDescription() throws Exception {
056:                parser.accepts("a", "some description");
057:                parser.accepts("verbose", "even more description");
058:
059:                parser.printHelpOn(sink);
060:
061:                String[] expectedLines = { "Option    Description           ",
062:                        "--------- --------------------- ",
063:                        "-a        some description      ",
064:                        "--verbose even more description ", "" };
065:                assertEquals(Helpers
066:                        .join(expectedLines, Helpers.LINE_SEPARATOR), sink
067:                        .toString());
068:            }
069:
070:            public void testOneOptionRequiredArgNoDescription()
071:                    throws Exception {
072:                parser.accepts("a").withRequiredArg();
073:
074:                parser.printHelpOn(sink);
075:
076:                String[] expectedLines = { "Option Description ",
077:                        "------ ----------- ", "-a                 ", "" };
078:                assertEquals(Helpers
079:                        .join(expectedLines, Helpers.LINE_SEPARATOR), sink
080:                        .toString());
081:            }
082:
083:            public void testOneOptionRequiredArgNoDescriptionWithType()
084:                    throws Exception {
085:                parser.accepts("a").withRequiredArg().ofType(Integer.class);
086:
087:                parser.printHelpOn(sink);
088:
089:                String[] expectedLines = { "Option       Description ",
090:                        "------------ ----------- ",
091:                        "-a <Integer>             ", "" };
092:                assertEquals(Helpers
093:                        .join(expectedLines, Helpers.LINE_SEPARATOR), sink
094:                        .toString());
095:            }
096:
097:            public void testOneOptionRequiredArgWithDescription()
098:                    throws Exception {
099:                parser.accepts("a", "some value you need").withRequiredArg()
100:                        .describedAs("numerical");
101:
102:                parser.printHelpOn(sink);
103:
104:                String[] expectedLines = {
105:                        "Option         Description         ",
106:                        "-------------- ------------------- ",
107:                        "-a <numerical> some value you need ", "" };
108:                assertEquals(Helpers
109:                        .join(expectedLines, Helpers.LINE_SEPARATOR), sink
110:                        .toString());
111:            }
112:
113:            public void testOneOptionRequiredArgWithDescriptionAndType()
114:                    throws Exception {
115:                parser.accepts("a", "some value you need").withRequiredArg()
116:                        .describedAs("numerical").ofType(Integer.class);
117:
118:                parser.printHelpOn(sink);
119:
120:                String[] expectedLines = {
121:                        "Option                  Description         ",
122:                        "----------------------- ------------------- ",
123:                        "-a <Integer: numerical> some value you need ", "" };
124:                assertEquals(Helpers
125:                        .join(expectedLines, Helpers.LINE_SEPARATOR), sink
126:                        .toString());
127:            }
128:
129:            public void testOneOptionOptionalArgNoDescription()
130:                    throws Exception {
131:                parser.accepts("threshold").withOptionalArg();
132:
133:                parser.printHelpOn(sink);
134:
135:                String[] expectedLines = { "Option      Description ",
136:                        "----------- ----------- ", "--threshold             ",
137:                        "" };
138:                assertEquals(Helpers
139:                        .join(expectedLines, Helpers.LINE_SEPARATOR), sink
140:                        .toString());
141:            }
142:
143:            public void testOneOptionOptionalArgNoDescriptionWithType()
144:                    throws Exception {
145:                parser.accepts("a").withOptionalArg().ofType(Float.class);
146:
147:                parser.printHelpOn(sink);
148:
149:                String[] expectedLines = { "Option     Description ",
150:                        "---------- ----------- ", "-a [Float]             ",
151:                        "" };
152:                assertEquals(Helpers
153:                        .join(expectedLines, Helpers.LINE_SEPARATOR), sink
154:                        .toString());
155:            }
156:
157:            public void testOneOptionOptionalArgWithDescription()
158:                    throws Exception {
159:                parser.accepts("threshold", "some value you need")
160:                        .withOptionalArg().describedAs("positive integer");
161:
162:                parser.printHelpOn(sink);
163:
164:                String[] expectedLines = {
165:                        "Option                         Description         ",
166:                        "------------------------------ ------------------- ",
167:                        "--threshold [positive integer] some value you need ",
168:                        "" };
169:                assertEquals(Helpers
170:                        .join(expectedLines, Helpers.LINE_SEPARATOR), sink
171:                        .toString());
172:            }
173:
174:            public void testOneOptionOptionalArgWithDescriptionAndType()
175:                    throws Exception {
176:                parser.accepts("threshold", "some value you need")
177:                        .withOptionalArg().describedAs(
178:                                "positive decimal number").ofType(Double.class);
179:
180:                parser.printHelpOn(sink);
181:
182:                String[] expectedLines = {
183:                        "Option                                        Description         ",
184:                        "--------------------------------------------- ------------------- ",
185:                        "--threshold [Double: positive decimal number] some value you need ",
186:                        "" };
187:                assertEquals(Helpers
188:                        .join(expectedLines, Helpers.LINE_SEPARATOR), sink
189:                        .toString());
190:            }
191:
192:            public void testAlternativeLongOptions() throws Exception {
193:                parser.recognizeAlternativeLongOptions(true);
194:
195:                parser.printHelpOn(sink);
196:
197:                String[] expectedLines = {
198:                        "Option         Description                      ",
199:                        "-------------- -------------------------------- ",
200:                        "-W <opt=value> Alternative form of long options ", "" };
201:                assertEquals(Helpers
202:                        .join(expectedLines, Helpers.LINE_SEPARATOR), sink
203:                        .toString());
204:            }
205:
206:            public void testOnOutputStream() throws Exception {
207:                ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
208:
209:                parser.printHelpOn(bytesOut);
210:
211:                assertEquals("No options specified", bytesOut.toString());
212:            }
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.