Skip to content

Commit 0947465

Browse files
author
John Keyes
committed
improved the testing of ant
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@129774 13f79535-47bb-0310-9956-ffa450edef68
1 parent 08a1eab commit 0947465

1 file changed

Lines changed: 37 additions & 18 deletions

File tree

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

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44
import junit.framework.TestCase;
55
import junit.framework.TestSuite;
66

7+
/**
8+
* <p>
9+
* This is a collection of tests that test real world
10+
* applications command lines.
11+
* </p>
12+
*
13+
* <p>
14+
* The following are the applications that are tested:
15+
* <ul>
16+
* <li>Ant</li>
17+
* </ul>
18+
* </p>
19+
*
20+
* @author John Keyes (jbjk at mac.com)
21+
*/
722
public class ApplicationTest extends TestCase {
823

9-
static {
10-
System.setProperty( "org.apache.commons.cli.parser",
11-
"org.apache.commons.cli.GnuParser");
12-
}
13-
1424
public static Test suite() {
1525
return new TestSuite(ApplicationTest.class);
1626
}
@@ -20,7 +30,14 @@ public ApplicationTest(String name)
2030
super(name);
2131
}
2232

33+
/**
34+
* Ant test
35+
*/
2336
public void testAnt() {
37+
// use the GNU parser
38+
System.setProperty( "org.apache.commons.cli.parser",
39+
"org.apache.commons.cli.GnuParser");
40+
2441
Options options = new Options();
2542
options.addOption( "help", false, "print this message" );
2643
options.addOption( "projecthelp", false, "print project help information" );
@@ -33,29 +50,31 @@ public void testAnt() {
3350
options.addOption( "logger", true, "the class which is to perform the logging" );
3451
options.addOption( "listener", true, "add an instance of a class as a project listener" );
3552
options.addOption( "buildfile", true, "use given buildfile" );
36-
options.addOption( "D", true, "use value for given property" );
53+
options.addOption( "D", null, true, "use value for given property", false, true );
3754
options.addOption( "find", true, "search for buildfile towards the root of the filesystem and use it" );
3855

39-
String[] args = new String[]{ "-buildfile", "mybuild.xml" };
56+
String[] args = new String[]{ "-buildfile", "mybuild.xml",
57+
"-Dproperty=value", "-Dproperty1=value1",
58+
"-projecthelp" };
4059

4160
try {
4261
CommandLine line = options.parse( args );
43-
assertTrue( "mybuild.xml" == line.getOptionValue( "buildfile" ) );
44-
}
45-
catch( ParseException exp ) {
46-
fail( "Unexpected exception:" + exp.getMessage() );
47-
}
4862

49-
args = new String[]{ "-buildfile", "mybuild.xml",
50-
"-Dproperty=value" };
51-
52-
try {
53-
CommandLine line = options.parse( args );
54-
assertEquals( line.getOptionValue( "D" ), "property=value" );
63+
// check multiple values
64+
String[] opts = line.getOptionValues( "D" );
65+
assertEquals( opts[0], "property=value" );
66+
assertEquals( opts[1], "property1=value1" );
67+
68+
// check single value
69+
assertEquals( line.getOptionValue( "buildfile"), "mybuild.xml" );
70+
71+
// check option
72+
assertTrue( line.hasOption( "projecthelp") );
5573
}
5674
catch( ParseException exp ) {
5775
fail( "Unexpected exception:" + exp.getMessage() );
5876
}
77+
5978
}
6079

6180
}

0 commit comments

Comments
 (0)