|
17 | 17 |
|
18 | 18 | package org.apache.commons.cli.bug; |
19 | 19 |
|
| 20 | +import junit.framework.TestCase; |
20 | 21 | import org.apache.commons.cli.CommandLine; |
21 | 22 | import org.apache.commons.cli.CommandLineParser; |
22 | | -import org.apache.commons.cli.Option; |
23 | 23 | import org.apache.commons.cli.OptionBuilder; |
24 | 24 | import org.apache.commons.cli.Options; |
25 | 25 | import org.apache.commons.cli.PosixParser; |
26 | 26 |
|
27 | | -import junit.framework.TestCase; |
28 | | - |
29 | 27 | /** |
30 | 28 | * http://issues.apache.org/jira/browse/CLI-148 |
31 | 29 | * |
32 | 30 | * @author brianegge |
33 | 31 | */ |
34 | | -public class BugCLI148Test extends TestCase { |
| 32 | +public class BugCLI148Test extends TestCase |
| 33 | +{ |
| 34 | + private Options options; |
| 35 | + |
| 36 | + protected void setUp() throws Exception |
| 37 | + { |
| 38 | + options = new Options(); |
| 39 | + options.addOption(OptionBuilder.hasArg().create('t')); |
| 40 | + options.addOption(OptionBuilder.hasArg().create('s')); |
| 41 | + } |
35 | 42 |
|
36 | 43 | public void testWorkaround1() throws Exception |
37 | 44 | { |
38 | | - Options options = buildCommandLineOptions(); |
39 | 45 | CommandLineParser parser = new PosixParser(); |
40 | | - String[] args = new String[] {"-t-something" }; |
41 | | - CommandLine commandLine; |
42 | | - commandLine = parser.parse( options, args ); |
43 | | - assertEquals("-something", commandLine.getOptionValue( 't')); |
| 46 | + String[] args = new String[]{ "-t-something" }; |
| 47 | + |
| 48 | + CommandLine commandLine = parser.parse(options, args); |
| 49 | + assertEquals("-something", commandLine.getOptionValue('t')); |
44 | 50 | } |
45 | 51 |
|
46 | 52 | public void testWorkaround2() throws Exception |
47 | 53 | { |
48 | | - Options options = buildCommandLineOptions(); |
49 | 54 | CommandLineParser parser = new PosixParser(); |
50 | | - String[] args = new String[] {"-t", "\"-something\"" }; |
51 | | - CommandLine commandLine; |
52 | | - commandLine = parser.parse( options, args ); |
53 | | - assertEquals("-something", commandLine.getOptionValue( 't')); |
54 | | - } |
| 55 | + String[] args = new String[]{ "-t", "\"-something\"" }; |
55 | 56 |
|
56 | | - private Options buildCommandLineOptions() |
57 | | - { |
58 | | - Option t = OptionBuilder.withArgName( "t").hasArg().create('t'); |
59 | | - Option s = OptionBuilder.withArgName( "s").hasArg().create('s'); |
60 | | - Options options = new Options(); |
61 | | - options.addOption( t); |
62 | | - options.addOption( s); |
63 | | - return options; |
| 57 | + CommandLine commandLine = parser.parse(options, args); |
| 58 | + assertEquals("-something", commandLine.getOptionValue('t')); |
64 | 59 | } |
65 | | - |
66 | 60 | } |
0 commit comments