@@ -28,51 +28,21 @@ public class ValuesTest extends TestCase
2828
2929 public void setUp () throws Exception
3030 {
31- Options opts = new Options ();
32-
33- opts .addOption ("a" , false , "toggle -a" );
34- opts .addOption ("b" , true , "set -b" );
35- opts .addOption ("c" , "c" , false , "toggle -c" );
36- opts .addOption ("d" , "d" , true , "set -d" );
37-
38- opts .addOption ( OptionBuilder .withLongOpt ( "e" )
39- .hasArgs ()
40- .withDescription ( "set -e " )
41- .create ( 'e' ) );
42-
43- opts .addOption ("f" , "f" , false , "jk" );
44-
45- opts .addOption ( OptionBuilder .withLongOpt ( "g" )
46- .hasArgs ( 2 )
47- .withDescription ( "set -g" )
48- .create ( 'g' ) );
49-
50- opts .addOption ( OptionBuilder .withLongOpt ( "h" )
51- .hasArgs ( 2 )
52- .withDescription ( "set -h" )
53- .create ( 'h' ) );
54-
55- opts .addOption ( OptionBuilder .withLongOpt ( "i" )
56- .withDescription ( "set -i" )
57- .create ( 'i' ) );
58-
59- opts .addOption ( OptionBuilder .withLongOpt ( "j" )
60- .hasArgs ( )
61- .withDescription ( "set -j" )
62- .withValueSeparator ( '=' )
63- .create ( 'j' ) );
64-
65- opts .addOption ( OptionBuilder .withLongOpt ( "k" )
66- .hasArgs ( )
67- .withDescription ( "set -k" )
68- .withValueSeparator ( '=' )
69- .create ( 'k' ) );
70-
71- opts .addOption ( OptionBuilder .withLongOpt ( "m" )
72- .hasArgs ( )
73- .withDescription ( "set -m" )
74- .withValueSeparator ( )
75- .create ( 'm' ) );
31+ Options options = new Options ();
32+
33+ options .addOption ("a" , false , "toggle -a" );
34+ options .addOption ("b" , true , "set -b" );
35+ options .addOption ("c" , "c" , false , "toggle -c" );
36+ options .addOption ("d" , "d" , true , "set -d" );
37+
38+ options .addOption (OptionBuilder .withLongOpt ("e" ).hasArgs ().withDescription ("set -e " ).create ('e' ));
39+ options .addOption ("f" , "f" , false , "jk" );
40+ options .addOption (OptionBuilder .withLongOpt ("g" ).hasArgs (2 ).withDescription ("set -g" ).create ('g' ));
41+ options .addOption (OptionBuilder .withLongOpt ("h" ).hasArgs (2 ).withDescription ("set -h" ).create ('h' ));
42+ options .addOption (OptionBuilder .withLongOpt ("i" ).withDescription ("set -i" ).create ('i' ));
43+ options .addOption (OptionBuilder .withLongOpt ("j" ).hasArgs ().withDescription ("set -j" ).withValueSeparator ('=' ).create ('j' ));
44+ options .addOption (OptionBuilder .withLongOpt ("k" ).hasArgs ().withDescription ("set -k" ).withValueSeparator ('=' ).create ('k' ));
45+ options .addOption (OptionBuilder .withLongOpt ("m" ).hasArgs ().withDescription ("set -m" ).withValueSeparator ().create ('m' ));
7646
7747 String [] args = new String [] { "-a" ,
7848 "-b" , "foo" ,
@@ -92,7 +62,7 @@ public void setUp() throws Exception
9262
9363 CommandLineParser parser = new PosixParser ();
9464
95- _cmdline = parser .parse (opts ,args );
65+ _cmdline = parser .parse (options ,args );
9666 }
9767
9868 public void testShortArgs ()
@@ -108,19 +78,19 @@ public void testShortArgsWithValue()
10878 {
10979 assertTrue ( _cmdline .hasOption ("b" ) );
11080 assertTrue ( _cmdline .getOptionValue ("b" ).equals ("foo" ));
111- assertTrue ( _cmdline .getOptionValues ("b" ).length == 1 );
81+ assertEquals ( 1 , _cmdline .getOptionValues ("b" ).length );
11282
11383 assertTrue ( _cmdline .hasOption ("d" ) );
11484 assertTrue ( _cmdline .getOptionValue ("d" ).equals ("bar" ));
115- assertTrue ( _cmdline .getOptionValues ("d" ).length == 1 );
85+ assertEquals ( 1 , _cmdline .getOptionValues ("d" ).length );
11686 }
11787
11888 public void testMultipleArgValues ()
11989 {
12090 String [] result = _cmdline .getOptionValues ("e" );
12191 String [] values = new String [] { "one" , "two" };
12292 assertTrue ( _cmdline .hasOption ("e" ) );
123- assertTrue ( _cmdline .getOptionValues ("e" ).length == 2 );
93+ assertEquals ( 2 , _cmdline .getOptionValues ("e" ).length );
12494 assertTrue ( Arrays .equals ( values , _cmdline .getOptionValues ("e" ) ) );
12595 }
12696
@@ -129,7 +99,7 @@ public void testTwoArgValues()
12999 String [] result = _cmdline .getOptionValues ("g" );
130100 String [] values = new String [] { "val1" , "val2" };
131101 assertTrue ( _cmdline .hasOption ("g" ) );
132- assertTrue ( _cmdline .getOptionValues ("g" ).length == 2 );
102+ assertEquals ( 2 , _cmdline .getOptionValues ("g" ).length );
133103 assertTrue ( Arrays .equals ( values , _cmdline .getOptionValues ("g" ) ) );
134104 }
135105
@@ -139,14 +109,14 @@ public void testComplexValues()
139109 String [] values = new String [] { "val1" , "val2" };
140110 assertTrue ( _cmdline .hasOption ("i" ) );
141111 assertTrue ( _cmdline .hasOption ("h" ) );
142- assertTrue ( _cmdline .getOptionValues ("h" ).length == 2 );
112+ assertEquals ( 2 , _cmdline .getOptionValues ("h" ).length );
143113 assertTrue ( Arrays .equals ( values , _cmdline .getOptionValues ("h" ) ) );
144114 }
145115
146116 public void testExtraArgs ()
147117 {
148118 String [] args = new String [] { "arg1" , "arg2" , "arg3" };
149- assertTrue ( _cmdline .getArgs ().length == 3 );
119+ assertEquals ( 3 , _cmdline .getArgs ().length );
150120 assertTrue ( Arrays .equals ( args , _cmdline .getArgs () ) );
151121 }
152122
@@ -165,16 +135,16 @@ public void testCharSeparator()
165135 values = new String [] { "key1" , "value1" , "key2" , "value2" };
166136 assertTrue ( _cmdline .hasOption ( "k" ) );
167137 assertTrue ( _cmdline .hasOption ( 'k' ) );
168- assertTrue ( _cmdline .getOptionValues ( "k" ).length == 4 );
169- assertTrue ( _cmdline .getOptionValues ( 'k' ).length == 4 );
138+ assertEquals ( 4 , _cmdline .getOptionValues ( "k" ).length );
139+ assertEquals ( 4 , _cmdline .getOptionValues ( 'k' ).length );
170140 assertTrue ( Arrays .equals ( values , _cmdline .getOptionValues ( "k" ) ) );
171141 assertTrue ( Arrays .equals ( values , _cmdline .getOptionValues ( 'k' ) ) );
172142
173143 values = new String [] { "key" , "value" };
174144 assertTrue ( _cmdline .hasOption ( "m" ) );
175145 assertTrue ( _cmdline .hasOption ( 'm' ) );
176- assertTrue ( _cmdline .getOptionValues ( "m" ).length == 2 );
177- assertTrue ( _cmdline .getOptionValues ( 'm' ).length == 2 );
146+ assertEquals ( 2 , _cmdline .getOptionValues ( "m" ).length );
147+ assertEquals ( 2 , _cmdline .getOptionValues ( 'm' ).length );
178148 assertTrue ( Arrays .equals ( values , _cmdline .getOptionValues ( "m" ) ) );
179149 assertTrue ( Arrays .equals ( values , _cmdline .getOptionValues ( 'm' ) ) );
180150 }
0 commit comments