Skip to content

Commit 60835e2

Browse files
committed
[CLI-227] Convert unit tests to junit 4, upgrade junit to 4.11, move authors to pom.xml.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/trunk@1442904 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5018b05 commit 60835e2

25 files changed

Lines changed: 356 additions & 127 deletions

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@
121121
<role>lots of fixes for 1.1</role>
122122
</roles>
123123
</contributor>
124+
<contributor>
125+
<name>Slawek Zachcial</name>
126+
<roles>
127+
<role>unit tests</role>
128+
</roles>
129+
</contributor>
124130

125131
</contributors>
126132

@@ -129,7 +135,7 @@
129135
<dependency>
130136
<groupId>junit</groupId>
131137
<artifactId>junit</artifactId>
132-
<version>4.8.2</version>
138+
<version>4.11</version>
133139
<scope>test</scope>
134140
</dependency>
135141
<dependency>

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
package org.apache.commons.cli;
1919

20-
import junit.framework.TestCase;
20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertTrue;
22+
23+
import org.junit.Test;
2124

2225
/**
2326
* This is a collection of tests that test real world applications command lines.
@@ -31,12 +34,11 @@
3134
* <li>man</li>
3235
* </ul>
3336
* </p>
34-
*
35-
* @author John Keyes (john at integralsource.com)
3637
*/
3738
@SuppressWarnings("deprecation") // tests some deprecated classes
38-
public class ApplicationTest extends TestCase {
39-
39+
public class ApplicationTest
40+
{
41+
@Test
4042
public void testLs() throws Exception {
4143
// create the command line parser
4244
CommandLineParser parser = new PosixParser();
@@ -63,6 +65,7 @@ public void testLs() throws Exception {
6365
/**
6466
* Ant test
6567
*/
68+
@Test
6669
public void testAnt() throws Exception {
6770
// use the GNU parser
6871
CommandLineParser parser = new GnuParser( );
@@ -104,6 +107,7 @@ public void testAnt() throws Exception {
104107
assertTrue( line.hasOption( "projecthelp") );
105108
}
106109

110+
@Test
107111
public void testGroovy() throws Exception {
108112
Options options = new Options();
109113

@@ -174,6 +178,7 @@ public void testGroovy() throws Exception {
174178
/**
175179
* author Slawek Zachcial
176180
*/
181+
@Test
177182
public void testMan()
178183
{
179184
String cmdLine =
@@ -223,6 +228,7 @@ public void testMan()
223228
/**
224229
* Real world test with long and short options.
225230
*/
231+
@Test
226232
public void testNLT() throws Exception {
227233
Option help = new Option("h", "help", false, "print this message");
228234
Option version = new Option("v", "version", false, "print version information");

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@
1717

1818
package org.apache.commons.cli;
1919

20-
import junit.framework.TestCase;
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertTrue;
22+
23+
import org.junit.Before;
24+
import org.junit.Test;
2125

2226
@SuppressWarnings("deprecation") // tests some deprecated classes
23-
public class ArgumentIsOptionTest extends TestCase
27+
public class ArgumentIsOptionTest
2428
{
2529
private Options options = null;
2630
private CommandLineParser parser = null;
2731

28-
@Override
32+
@Before
2933
public void setUp()
3034
{
3135
options = new Options().addOption("p", false, "Option p").addOption("attr", true, "Option accepts argument");
3236

3337
parser = new PosixParser();
3438
}
3539

40+
@Test
3641
public void testOptionAndOptionWithArgument() throws Exception
3742
{
3843
String[] args = new String[]{
@@ -48,6 +53,7 @@ public void testOptionAndOptionWithArgument() throws Exception
4853
assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0);
4954
}
5055

56+
@Test
5157
public void testOptionWithArgument() throws Exception
5258
{
5359
String[] args = new String[]{
@@ -63,6 +69,7 @@ public void testOptionWithArgument() throws Exception
6369
assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0);
6470
}
6571

72+
@Test
6673
public void testOption() throws Exception
6774
{
6875
String[] args = new String[]{

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717

1818
package org.apache.commons.cli;
1919

20-
/**
21-
* @author Emmanuel Bourg
22-
* @version $Revision$, $Date$
23-
*/
20+
import org.junit.Before;
21+
2422
@SuppressWarnings("deprecation") // tests some deprecated classes
2523
public class BasicParserTest extends ParserTestCase
2624
{
27-
@Override
25+
@Before
2826
public void setUp()
2927
{
3028
super.setUp();

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,22 @@
1717

1818
package org.apache.commons.cli;
1919

20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertTrue;
23+
import static org.junit.Assert.fail;
24+
2025
import java.io.ByteArrayOutputStream;
2126
import java.io.PrintStream;
2227
import java.util.Iterator;
2328
import java.util.Properties;
2429

25-
import junit.framework.TestCase;
30+
import org.junit.Test;
2631

2732
@SuppressWarnings("deprecation") // tests some deprecated classes
28-
public class BugsTest extends TestCase
33+
public class BugsTest
2934
{
35+
@Test
3036
public void test11457() throws Exception
3137
{
3238
Options options = new Options();
@@ -39,6 +45,7 @@ public void test11457() throws Exception
3945
assertTrue(cmd.hasOption("verbose"));
4046
}
4147

48+
@Test
4249
public void test11458() throws Exception
4350
{
4451
Options options = new Options();
@@ -82,6 +89,7 @@ public void test11458() throws Exception
8289
}
8390
}
8491

92+
@Test
8593
public void test11680() throws Exception
8694
{
8795
Options options = new Options();
@@ -97,6 +105,7 @@ public void test11680() throws Exception
97105
cmd.getOptionValue("m", "default m");
98106
}
99107

108+
@Test
100109
public void test11456() throws Exception
101110
{
102111
// Posix
@@ -122,6 +131,7 @@ public void test11456() throws Exception
122131
assertEquals( cmd.getOptionValue( 'b' ), "value" );
123132
}
124133

134+
@Test
125135
public void test12210() throws Exception
126136
{
127137
// create the main options object which will handle the first parameter
@@ -178,6 +188,7 @@ else if(cmd.hasOption("rep"))
178188
}
179189
}
180190

191+
@Test
181192
public void test13425() throws Exception
182193
{
183194
Options options = new Options();
@@ -208,6 +219,7 @@ public void test13425() throws Exception
208219
}
209220
}
210221

222+
@Test
211223
public void test13666() throws Exception
212224
{
213225
Options options = new Options();
@@ -238,6 +250,7 @@ public void test13666() throws Exception
238250
}
239251
}
240252

253+
@Test
241254
public void test13935() throws Exception
242255
{
243256
OptionGroup directions = new OptionGroup();
@@ -284,6 +297,7 @@ public void test13935() throws Exception
284297
assertNotNull(line);
285298
}
286299

300+
@Test
287301
public void test14786() throws Exception
288302
{
289303
Option o = OptionBuilder.isRequired().withDescription("test").create("test");
@@ -299,6 +313,7 @@ public void test14786() throws Exception
299313
assertTrue( line.hasOption( "test" ) );
300314
}
301315

316+
@Test
302317
public void test15046() throws Exception
303318
{
304319
CommandLineParser parser = new PosixParser();
@@ -316,6 +331,7 @@ public void test15046() throws Exception
316331
assertTrue( !line.hasOption("c") );
317332
}
318333

334+
@Test
319335
public void test15648() throws Exception
320336
{
321337
CommandLineParser parser = new PosixParser();
@@ -327,6 +343,7 @@ public void test15648() throws Exception
327343
assertEquals( "Two Words", line.getOptionValue( "m" ) );
328344
}
329345

346+
@Test
330347
public void test31148() throws ParseException
331348
{
332349
Option multiArgOption = new Option("o","option with multiple args");

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717

1818
package org.apache.commons.cli;
1919

20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertNotNull;
22+
2023
import java.util.Properties;
2124

22-
import junit.framework.TestCase;
25+
import org.junit.Test;
2326

24-
/**
25-
* @author Emmanuel Bourg
26-
* @version $Revision$, $Date$
27-
*/
2827
@SuppressWarnings("deprecation") // tests some deprecated classes
29-
public class CommandLineTest extends TestCase
28+
public class CommandLineTest
3029
{
30+
@Test
3131
public void testGetOptionProperties() throws Exception
3232
{
3333
String[] args = new String[] { "-Dparam1=value1", "-Dparam2=value2", "-Dparam3", "-Dparam4=value4", "-D", "--property", "foo=bar" };
@@ -50,6 +50,7 @@ public void testGetOptionProperties() throws Exception
5050
assertEquals("property with long format", "bar", cl.getOptionProperties("property").getProperty("foo"));
5151
}
5252

53+
@Test
5354
public void testGetOptions()
5455
{
5556
CommandLine cmd = new CommandLine();
@@ -63,6 +64,7 @@ public void testGetOptions()
6364
assertEquals(3, cmd.getOptions().length);
6465
}
6566

67+
@Test
6668
public void testGetParsedOptionValue() throws Exception {
6769
Options options = new Options();
6870
options.addOption(OptionBuilder.hasArg().withType(Number.class).create("i"));

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717

1818
package org.apache.commons.cli;
1919

20-
/**
21-
* @author Emmanuel Bourg
22-
* @version $Revision$, $Date$
23-
*/
20+
import org.junit.Before;
21+
2422
public class DefaultParserTest extends ParserTestCase {
2523

26-
@Override
24+
@Before
2725
public void setUp() {
2826
super.setUp();
2927
parser = new DefaultParser();

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
package org.apache.commons.cli;
1919

20+
import org.junit.Before;
21+
2022
@SuppressWarnings("deprecation") // tests some deprecated classes
2123
public class GnuParserTest extends ParserTestCase
2224
{
23-
@Override
25+
@Before
2426
public void setUp()
2527
{
2628
super.setUp();
@@ -105,8 +107,8 @@ public void testAmbiguousPartialLongOption2() throws Exception
105107
// not supported by the GnuParser
106108
}
107109

108-
@Override
109-
public void testAmbiguousPartialLongOption3() throws Exception
110+
@Override
111+
public void testAmbiguousPartialLongOption3() throws Exception
110112
{
111113
// not supported by the GnuParser
112114
}

0 commit comments

Comments
 (0)