Skip to content

Commit 3972aca

Browse files
committed
Moved the real world test from PosixParserTest to ApplicationTest
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/trunk@779616 13f79535-47bb-0310-9956-ffa450edef68
1 parent ce3a962 commit 3972aca

2 files changed

Lines changed: 67 additions & 67 deletions

File tree

src/test/org/apache/commons/cli/ApplicationTest.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,71 @@ public void testMan()
218218
hf.printHelp(60, cmdLine, null, options, null);
219219
}
220220

221+
222+
/**
223+
* Real world test with long and short options.
224+
*/
225+
public void testNLT() throws Exception {
226+
Option help = new Option("h", "help", false, "print this message");
227+
Option version = new Option("v", "version", false, "print version information");
228+
Option newRun = new Option("n", "new", false, "Create NLT cache entries only for new items");
229+
Option trackerRun = new Option("t", "tracker", false, "Create NLT cache entries only for tracker items");
230+
231+
Option timeLimit = OptionBuilder.withLongOpt("limit").hasArg()
232+
.withValueSeparator()
233+
.withDescription("Set time limit for execution, in minutes")
234+
.create("l");
235+
236+
Option age = OptionBuilder.withLongOpt("age").hasArg()
237+
.withValueSeparator()
238+
.withDescription("Age (in days) of cache item before being recomputed")
239+
.create("a");
240+
241+
Option server = OptionBuilder.withLongOpt("server").hasArg()
242+
.withValueSeparator()
243+
.withDescription("The NLT server address")
244+
.create("s");
245+
246+
Option numResults = OptionBuilder.withLongOpt("results").hasArg()
247+
.withValueSeparator()
248+
.withDescription("Number of results per item")
249+
.create("r");
250+
251+
Option configFile = OptionBuilder.withLongOpt("file").hasArg()
252+
.withValueSeparator()
253+
.withDescription("Use the specified configuration file")
254+
.create();
255+
256+
Options options = new Options();
257+
options.addOption(help);
258+
options.addOption(version);
259+
options.addOption(newRun);
260+
options.addOption(trackerRun);
261+
options.addOption(timeLimit);
262+
options.addOption(age);
263+
options.addOption(server);
264+
options.addOption(numResults);
265+
options.addOption(configFile);
266+
267+
// create the command line parser
268+
CommandLineParser parser = new PosixParser();
269+
270+
String[] args = new String[] {
271+
"-v",
272+
"-l",
273+
"10",
274+
"-age",
275+
"5",
276+
"-file",
277+
"filename"
278+
};
279+
280+
CommandLine line = parser.parse(options, args);
281+
assertTrue(line.hasOption("v"));
282+
assertEquals(line.getOptionValue("l"), "10");
283+
assertEquals(line.getOptionValue("limit"), "10");
284+
assertEquals(line.getOptionValue("a"), "5");
285+
assertEquals(line.getOptionValue("age"), "5");
286+
assertEquals(line.getOptionValue("file"), "filename");
287+
}
221288
}

src/test/org/apache/commons/cli/PosixParserTest.java

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -30,73 +30,6 @@ public void setUp()
3030
parser = new PosixParser();
3131
}
3232

33-
/**
34-
* Real world test with long and short options.
35-
*/
36-
public void testLongOptionWithShort() throws Exception {
37-
Option help = new Option("h", "help", false, "print this message");
38-
Option version = new Option("v", "version", false, "print version information");
39-
Option newRun = new Option("n", "new", false, "Create NLT cache entries only for new items");
40-
Option trackerRun = new Option("t", "tracker", false, "Create NLT cache entries only for tracker items");
41-
42-
Option timeLimit = OptionBuilder.withLongOpt("limit").hasArg()
43-
.withValueSeparator()
44-
.withDescription("Set time limit for execution, in minutes")
45-
.create("l");
46-
47-
Option age = OptionBuilder.withLongOpt("age").hasArg()
48-
.withValueSeparator()
49-
.withDescription("Age (in days) of cache item before being recomputed")
50-
.create("a");
51-
52-
Option server = OptionBuilder.withLongOpt("server").hasArg()
53-
.withValueSeparator()
54-
.withDescription("The NLT server address")
55-
.create("s");
56-
57-
Option numResults = OptionBuilder.withLongOpt("results").hasArg()
58-
.withValueSeparator()
59-
.withDescription("Number of results per item")
60-
.create("r");
61-
62-
Option configFile = OptionBuilder.withLongOpt("file").hasArg()
63-
.withValueSeparator()
64-
.withDescription("Use the specified configuration file")
65-
.create();
66-
67-
Options options = new Options();
68-
options.addOption(help);
69-
options.addOption(version);
70-
options.addOption(newRun);
71-
options.addOption(trackerRun);
72-
options.addOption(timeLimit);
73-
options.addOption(age);
74-
options.addOption(server);
75-
options.addOption(numResults);
76-
options.addOption(configFile);
77-
78-
// create the command line parser
79-
CommandLineParser parser = new PosixParser();
80-
81-
String[] args = new String[] {
82-
"-v",
83-
"-l",
84-
"10",
85-
"-age",
86-
"5",
87-
"-file",
88-
"filename"
89-
};
90-
91-
CommandLine line = parser.parse(options, args);
92-
assertTrue(line.hasOption("v"));
93-
assertEquals(line.getOptionValue("l"), "10");
94-
assertEquals(line.getOptionValue("limit"), "10");
95-
assertEquals(line.getOptionValue("a"), "5");
96-
assertEquals(line.getOptionValue("age"), "5");
97-
assertEquals(line.getOptionValue("file"), "filename");
98-
}
99-
10033
public void testLongWithEqualSingleDash() throws Exception
10134
{
10235
// not supported by the PosixParser

0 commit comments

Comments
 (0)