Skip to content

Commit 8fd05b5

Browse files
committed
Minor refactoring of BugCLI148Test
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/trunk@784813 13f79535-47bb-0310-9956-ffa450edef68
1 parent f436985 commit 8fd05b5

1 file changed

Lines changed: 18 additions & 24 deletions

File tree

src/test/org/apache/commons/cli/bug/BugCLI148Test.java

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,44 @@
1717

1818
package org.apache.commons.cli.bug;
1919

20+
import junit.framework.TestCase;
2021
import org.apache.commons.cli.CommandLine;
2122
import org.apache.commons.cli.CommandLineParser;
22-
import org.apache.commons.cli.Option;
2323
import org.apache.commons.cli.OptionBuilder;
2424
import org.apache.commons.cli.Options;
2525
import org.apache.commons.cli.PosixParser;
2626

27-
import junit.framework.TestCase;
28-
2927
/**
3028
* http://issues.apache.org/jira/browse/CLI-148
3129
*
3230
* @author brianegge
3331
*/
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+
}
3542

3643
public void testWorkaround1() throws Exception
3744
{
38-
Options options = buildCommandLineOptions();
3945
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'));
4450
}
4551

4652
public void testWorkaround2() throws Exception
4753
{
48-
Options options = buildCommandLineOptions();
4954
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\"" };
5556

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'));
6459
}
65-
6660
}

0 commit comments

Comments
 (0)