commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r661378 - /commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/
Date Thu, 29 May 2008 16:11:49 GMT
Author: ebourg
Date: Thu May 29 09:11:48 2008
New Revision: 661378

URL: http://svn.apache.org/viewvc?rev=661378&view=rev
Log:
Simplified the test cases by removing the unnecessary fail() calls in the catch blocks

Modified:
    commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ApplicationTest.java
    commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ArgumentIsOptionTest.java
    commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/BugsTest.java
    commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/GnuParseTest.java
    commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionBuilderTest.java
    commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionGroupTest.java
    commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseRequiredTest.java
    commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseTest.java
    commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ValueTest.java

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ApplicationTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ApplicationTest.java?rev=661378&r1=661377&r2=661378&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ApplicationTest.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ApplicationTest.java Thu May 29 09:11:48 2008
@@ -36,10 +36,7 @@
  */
 public class ApplicationTest extends TestCase {
 
-    /**
-     *	
-     */
-    public void testLs() {
+    public void testLs() throws Exception {
         // create the command line parser
         CommandLineParser parser = new PosixParser();
         Options options = new Options();
@@ -57,20 +54,15 @@
 
         String[] args = new String[]{ "--block-size=10" };
 
-        try {
-            CommandLine line = parser.parse( options, args );
-            assertTrue( line.hasOption( "block-size" ) );
-            assertEquals( line.getOptionValue( "block-size" ), "10" );
-        }
-        catch( ParseException exp ) {
-            fail( "Unexpected exception:" + exp.getMessage() );
-        }
+        CommandLine line = parser.parse( options, args );
+        assertTrue( line.hasOption( "block-size" ) );
+        assertEquals( line.getOptionValue( "block-size" ), "10" );
     }
 
     /**
      * Ant test
      */
-    public void testAnt() {
+    public void testAnt() throws Exception {
         // use the GNU parser
         CommandLineParser parser = new GnuParser( );
         Options options = new Options();
@@ -95,26 +87,20 @@
             "-Dproperty=value", "-Dproperty1=value1",
             "-projecthelp" };
 
-        try {
-            CommandLine line = parser.parse( options, args );
+        CommandLine line = parser.parse( options, args );
+
+        // check multiple values
+        String[] opts = line.getOptionValues( "D" );
+        assertEquals( "property", opts[0] );
+        assertEquals( "value", opts[1] );
+        assertEquals( "property1", opts[2] );
+        assertEquals( "value1", opts[3] );
 
-            // check multiple values
-            String[] opts = line.getOptionValues( "D" );
-            assertEquals( "property", opts[0] );
-            assertEquals( "value", opts[1] );
-            assertEquals( "property1", opts[2] );
-            assertEquals( "value1", opts[3] );
-
-            // check single value
-            assertEquals( line.getOptionValue( "buildfile"), "mybuild.xml" );
-
-            // check option
-            assertTrue( line.hasOption( "projecthelp") );
-        }
-        catch( ParseException exp ) {
-            fail( "Unexpected exception:" + exp.getMessage() );
-        }
+        // check single value
+        assertEquals( line.getOptionValue( "buildfile"), "mybuild.xml" );
 
+        // check option
+        assertTrue( line.hasOption( "projecthelp") );
     }
 
 }

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ArgumentIsOptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ArgumentIsOptionTest.java?rev=661378&r1=661377&r2=661378&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ArgumentIsOptionTest.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ArgumentIsOptionTest.java Thu May 29 09:11:48 2008
@@ -19,69 +19,58 @@
 
 import junit.framework.TestCase;
 
-public class ArgumentIsOptionTest extends TestCase {
+public class ArgumentIsOptionTest extends TestCase
+{
     private Options options = null;
     private CommandLineParser parser = null;
 
-    public void setUp() {
-        options = new Options().addOption("p", false, "Option p").addOption("attr",
-                true, "Option accepts argument");
+    public void setUp()
+    {
+        options = new Options().addOption("p", false, "Option p").addOption("attr", true, "Option accepts argument");
 
         parser = new PosixParser();
     }
 
-    public void testOptionAndOptionWithArgument() {
-        String[] args = new String[] {
+    public void testOptionAndOptionWithArgument() throws Exception
+    {
+        String[] args = new String[]{
                 "-p",
                 "-attr",
                 "p"
-            };
+        };
 
-        try {
-            CommandLine cl = parser.parse(options, args);
-            assertTrue("Confirm -p is set", cl.hasOption("p"));
-            assertTrue("Confirm -attr is set", cl.hasOption("attr"));
-            assertTrue("Confirm arg of -attr",
+        CommandLine cl = parser.parse(options, args);
+        assertTrue("Confirm -p is set", cl.hasOption("p"));
+        assertTrue("Confirm -attr is set", cl.hasOption("attr"));
+        assertTrue("Confirm arg of -attr",
                 cl.getOptionValue("attr").equals("p"));
-            assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0);
-        }
-        catch (ParseException e) {
-            fail(e.toString());
-        }
+        assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0);
     }
 
-    public void testOptionWithArgument() {
-        String[] args = new String[] {
+    public void testOptionWithArgument() throws Exception
+    {
+        String[] args = new String[]{
                 "-attr",
                 "p"
-            };
+        };
 
-        try {
-            CommandLine cl = parser.parse(options, args);
-            assertFalse("Confirm -p is set", cl.hasOption("p"));
-            assertTrue("Confirm -attr is set", cl.hasOption("attr"));
-            assertTrue("Confirm arg of -attr",
+        CommandLine cl = parser.parse(options, args);
+        assertFalse("Confirm -p is set", cl.hasOption("p"));
+        assertTrue("Confirm -attr is set", cl.hasOption("attr"));
+        assertTrue("Confirm arg of -attr",
                 cl.getOptionValue("attr").equals("p"));
-            assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0);
-        }
-        catch (ParseException e) {
-            fail(e.toString());
-        }
+        assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0);
     }
 
-    public void testOption() {
-        String[] args = new String[] {
+    public void testOption() throws Exception
+    {
+        String[] args = new String[]{
                 "-p"
-            };
+        };
 
-        try {
-            CommandLine cl = parser.parse(options, args);
-            assertTrue("Confirm -p is set", cl.hasOption("p"));
-            assertFalse("Confirm -attr is not set", cl.hasOption("attr"));
-            assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0);
-        }
-        catch (ParseException e) {
-            fail(e.toString());
-        }
+        CommandLine cl = parser.parse(options, args);
+        assertTrue("Confirm -p is set", cl.hasOption("p"));
+        assertFalse("Confirm -attr is not set", cl.hasOption("attr"));
+        assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0);
     }
 }

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/BugsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/BugsTest.java?rev=661378&r1=661377&r2=661378&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/BugsTest.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/BugsTest.java Thu May 29 09:11:48 2008
@@ -21,31 +21,27 @@
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.util.Iterator;
 import java.util.Properties;
 
 import junit.framework.TestCase;
 
 public class BugsTest extends TestCase
 {
-    public void test11457() {
+    public void test11457() throws Exception
+    {
         Options options = new Options();
-        options.addOption( OptionBuilder.withLongOpt( "verbose" )
-                           .create() );
-        String[] args = new String[] { "--verbose" };
+        options.addOption(OptionBuilder.withLongOpt("verbose")
+                .create());
+        String[] args = new String[]{"--verbose"};
 
         CommandLineParser parser = new PosixParser();
 
-        try {
-            CommandLine cmd = parser.parse( options, args );
-            assertTrue( cmd.hasOption( "verbose" ) );
-        }        
-        catch( ParseException exp ) {
-            exp.printStackTrace();
-            fail( "Unexpected Exception: " + exp.getMessage() );
-        }
+        CommandLine cmd = parser.parse(options, args);
+        assertTrue(cmd.hasOption("verbose"));
     }
 
-    public void test11458()
+    public void test11458() throws Exception
     {
         Options options = new Options();
         options.addOption( OptionBuilder.withValueSeparator( '=' )
@@ -54,75 +50,60 @@
         options.addOption( OptionBuilder.withValueSeparator( ':' )
                            .hasArgs()
                            .create( 'p' ) );
-        String[] args = new String[] { "-DJAVA_HOME=/opt/java" ,
-        "-pfile1:file2:file3" };
+        String[] args = new String[] { "-DJAVA_HOME=/opt/java" , "-pfile1:file2:file3" };
 
         CommandLineParser parser = new PosixParser();
 
-        try {
-            CommandLine cmd = parser.parse( options, args );
+        CommandLine cmd = parser.parse(options, args);
 
-            String[] values = cmd.getOptionValues( 'D' );
+        String[] values = cmd.getOptionValues('D');
 
-            assertEquals( values[0], "JAVA_HOME" );
-            assertEquals( values[1], "/opt/java" );
+        assertEquals(values[0], "JAVA_HOME");
+        assertEquals(values[1], "/opt/java");
 
-            values = cmd.getOptionValues( 'p' );
+        values = cmd.getOptionValues('p');
 
-            assertEquals( values[0], "file1" );
-            assertEquals( values[1], "file2" );
-            assertEquals( values[2], "file3" );
-
-            java.util.Iterator iter = cmd.iterator();
-            while( iter.hasNext() ) {
-                Option opt = (Option)iter.next();
-                switch( opt.getId() ) {
-                    case 'D':
-                        assertEquals( opt.getValue( 0 ), "JAVA_HOME" );
-                        assertEquals( opt.getValue( 1 ), "/opt/java" );
-                        break;
-                    case 'p':
-                        assertEquals( opt.getValue( 0 ), "file1" );
-                        assertEquals( opt.getValue( 1 ), "file2" );
-                        assertEquals( opt.getValue( 2 ), "file3" );
-                        break;
-                    default:
-                        fail( "-D option not found" );
-                }
+        assertEquals(values[0], "file1");
+        assertEquals(values[1], "file2");
+        assertEquals(values[2], "file3");
+
+        Iterator iter = cmd.iterator();
+        while (iter.hasNext())
+        {
+            Option opt = (Option) iter.next();
+            switch (opt.getId())
+            {
+                case 'D':
+                    assertEquals(opt.getValue(0), "JAVA_HOME");
+                    assertEquals(opt.getValue(1), "/opt/java");
+                    break;
+                case 'p':
+                    assertEquals(opt.getValue(0), "file1");
+                    assertEquals(opt.getValue(1), "file2");
+                    assertEquals(opt.getValue(2), "file3");
+                    break;
+                default:
+                    fail("-D option not found");
             }
         }
-        catch( ParseException exp ) {
-            fail( "Unexpected Exception:\nMessage:" + exp.getMessage() 
-                  + "Type: " + exp.getClass().getName() );
-        }
     }
 
-    public void test11680()
+    public void test11680() throws Exception
     {
         Options options = new Options();
         options.addOption("f", true, "foobar");
-	options.addOption("m", true, "missing");
-        String[] args = new String[] { "-f" , "foo" };
+        options.addOption("m", true, "missing");
+        String[] args = new String[]{"-f", "foo"};
 
         CommandLineParser parser = new PosixParser();
 
-        try {
-            CommandLine cmd = parser.parse( options, args );
+        CommandLine cmd = parser.parse(options, args);
 
-            try {
-                cmd.getOptionValue( "f", "default f");
-                cmd.getOptionValue( "m", "default m");
-            }
-            catch( NullPointerException exp ) {
-                fail( "NullPointer caught: " + exp.getMessage() );
-            }
-        }
-        catch( ParseException exp ) {
-            fail( "Unexpected Exception: " + exp.getMessage() );
-        }
+        cmd.getOptionValue("f", "default f");
+        cmd.getOptionValue("m", "default m");
     }
 
-    public void test11456()
+    public void test11456() throws Exception
     {
         // Posix 
         Options options = new Options();
@@ -134,13 +115,8 @@
 
         CommandLineParser parser = new PosixParser();
 
-        try {
-            CommandLine cmd = parser.parse( options, args );
-            assertEquals( cmd.getOptionValue( 'b' ), "value" );
-        }
-        catch( ParseException exp ) {
-            fail( "Unexpected Exception: " + exp.getMessage() );
-        }
+        CommandLine cmd = parser.parse( options, args );
+        assertEquals( cmd.getOptionValue( 'b' ), "value" );
 
         // GNU
         options = new Options();
@@ -152,17 +128,12 @@
 
         parser = new GnuParser();
 
-        try {
-            CommandLine cmd = parser.parse( options, args );
-            assertEquals( cmd.getOptionValue( 'b' ), "value" );
-        }
-        catch( ParseException exp ) {
-            fail( "Unexpected Exception: " + exp.getMessage() );
-        }
-
+        cmd = parser.parse( options, args );
+        assertEquals( cmd.getOptionValue( 'b' ), "value" );
     }
 
-    public void test12210() {
+    public void test12210() throws Exception
+    {
         // create the main options object which will handle the first parameter
         Options mainOptions = new Options();
         // There can be 2 main exclusive options:  -exec|-rep
@@ -180,13 +151,13 @@
 
         // for the exec option, there are 2 options...
         Options execOptions = new Options();
-        execOptions.addOption("exec_opt1",false," desc");
-        execOptions.addOption("exec_opt2",false," desc");
+        execOptions.addOption("exec_opt1", false, " desc");
+        execOptions.addOption("exec_opt2", false, " desc");
 
         // similarly, for rep there are 2 options...
         Options repOptions = new Options();
-        repOptions.addOption("repopto",false,"desc");
-        repOptions.addOption("repoptt",false,"desc");
+        repOptions.addOption("repopto", false, "desc");
+        repOptions.addOption("repoptt", false, "desc");
 
         // create the parser
         GnuParser parser = new GnuParser();
@@ -196,31 +167,29 @@
         // first parse the main options to see what the user has specified
         // We set stopAtNonOption to true so it does not touch the remaining
         // options
-        try {
-            CommandLine cmd = parser.parse(mainOptions,argv,true);
-            // get the remaining options...
-            argv = cmd.getArgs();
-
-            if(cmd.hasOption("exec")){
-                cmd = parser.parse(execOptions,argv,false);
-                // process the exec_op1 and exec_opt2...
-                assertTrue( cmd.hasOption("exec_opt1") );
-                assertTrue( cmd.hasOption("exec_opt2") );
-            }
-            else if(cmd.hasOption("rep")){
-                cmd = parser.parse(repOptions,argv,false);
-                // process the rep_op1 and rep_opt2...
-            }
-            else {
-                fail( "exec option not found" );
-            }
+        CommandLine cmd = parser.parse(mainOptions,argv,true);
+        // get the remaining options...
+        argv = cmd.getArgs();
+
+        if(cmd.hasOption("exec"))
+        {
+            cmd = parser.parse(execOptions,argv,false);
+            // process the exec_op1 and exec_opt2...
+            assertTrue( cmd.hasOption("exec_opt1") );
+            assertTrue( cmd.hasOption("exec_opt2") );
         }
-        catch( ParseException exp ) {
-            fail( "Unexpected exception: " + exp.getMessage() );
+        else if(cmd.hasOption("rep"))
+        {
+            cmd = parser.parse(repOptions,argv,false);
+            // process the rep_op1 and rep_opt2...
+        }
+        else {
+            fail( "exec option not found" );
         }
     }
 
-    public void test13425() {
+    public void test13425() throws Exception
+    {
         Options options = new Options();
         Option oldpass = OptionBuilder.withLongOpt( "old-password" )
             .withDescription( "Use this option to specify the old password" )
@@ -242,18 +211,21 @@
 
         Parser parser = new PosixParser();
 
-        try {
-            CommandLine line = parser.parse( options, args );
+        try
+        {
+            parser.parse( options, args );
         }
         // catch the exception and leave the method
-        catch( Exception exp ) {
+        catch( Exception exp )
+        {
             assertTrue( exp != null );
             return;
         }
         fail( "MissingArgumentException not caught." );
     }
 
-    public void test13666() {
+    public void test13666() throws Exception
+    {
         Options options = new Options();
         Option dir = OptionBuilder.withDescription( "dir" )
                                        .hasArg()
@@ -262,7 +234,8 @@
         
         
         final PrintStream oldSystemOut = System.out;
-        try{
+        try
+        {
             final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
             final PrintStream print = new PrintStream(bytes);
             
@@ -272,21 +245,20 @@
             bytes.reset();
             
             System.setOut(new PrintStream(bytes));
-            try {
-                HelpFormatter formatter = new HelpFormatter();
-                formatter.printHelp( "dir", options );
-            }
-            catch( Exception exp ) {
-                fail( "Unexpected Exception: " + exp.getMessage() );
-            }
+
+            HelpFormatter formatter = new HelpFormatter();
+            formatter.printHelp( "dir", options );
+
             assertEquals("usage: dir"+eol+" -d <arg>   dir"+eol,bytes.toString());
         }
-        finally {
+        finally
+        {
             System.setOut(oldSystemOut);
         }
     }
 
-    public void test13935() {
+    public void test13935() throws Exception
+    {
         OptionGroup directions = new OptionGroup();
 
         Option left = new Option( "l", "left", false, "go left" );
@@ -335,20 +307,24 @@
         exception = false;
 
         args = new String[] { "-s", "-l" };
-        try {
-            CommandLine line = parser.parse( opts, args );
-        }
-        catch( ParseException exp ) {
-            fail( "Unexpected exception: " + exp.getClass().getName() + ":" + exp.getMessage() );
+        try
+        {
+            parser.parse(opts, args);
+        }
+        catch (ParseException exp)
+        {
+            fail("Unexpected exception: " + exp.getClass().getName() + ":" + exp.getMessage());
         }
 
         opts.addOption( forward );
         args = new String[] { "-s", "-l", "-f" };
-        try {
-            CommandLine line = parser.parse( opts, args );
-        }
-        catch( ParseException exp ) {
-            fail( "Unexpected exception: " + exp.getClass().getName() + ":" + exp.getMessage() );
+        try
+        {
+            parser.parse(opts, args);
+        }
+        catch (ParseException exp)
+        {
+            fail("Unexpected exception: " + exp.getClass().getName() + ":" + exp.getMessage());
         }
     }
 

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/GnuParseTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/GnuParseTest.java?rev=661378&r1=661377&r2=661378&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/GnuParseTest.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/GnuParseTest.java Thu May 29 09:11:48 2008
@@ -42,49 +42,35 @@
         _parser = new GnuParser( );
     }
 
-    public void testSimpleShort()
+    public void testSimpleShort() throws Exception
     {
         String[] args = new String[] { "-a",
                                        "-b", "toast",
                                        "foo", "bar" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options, args);
-            
-            assertTrue( "Confirm -a is set", cl.hasOption("a") );
-            assertTrue( "Confirm -b is set", cl.hasOption("b") );
-            assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
-            assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        CommandLine cl = _parser.parse(_options, args);
+
+        assertTrue( "Confirm -a is set", cl.hasOption("a") );
+        assertTrue( "Confirm -b is set", cl.hasOption("b") );
+        assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
+        assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
     }
 
-    public void testSimpleLong()
+    public void testSimpleLong() throws Exception
     {
         String[] args = new String[] { "--enable-a",
                                        "--bfile", "toast",
                                        "foo", "bar" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options, args);
-            
-            assertTrue( "Confirm -a is set", cl.hasOption("a") );
-            assertTrue( "Confirm -b is set", cl.hasOption("b") );
-            assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
-            assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
-        } 
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        CommandLine cl = _parser.parse(_options, args);
+
+        assertTrue( "Confirm -a is set", cl.hasOption("a") );
+        assertTrue( "Confirm -b is set", cl.hasOption("b") );
+        assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
+        assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
     }
 
-    public void testExtraOption()
+    public void testExtraOption() throws Exception
     {
         String[] args = new String[] { "-a", "-d", "-b", "toast",
                                        "foo", "bar" };
@@ -104,14 +90,11 @@
         {
             caught = true;
         }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+
         assertTrue( "Confirm UnrecognizedOptionException caught", caught );
     }
 
-    public void testMissingArg()
+    public void testMissingArg() throws Exception
     {
         String[] args = new String[] { "-b" };
 
@@ -125,129 +108,88 @@
         {
             caught = true;
         }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
 
         assertTrue( "Confirm MissingArgumentException caught", caught );
     }
 
-    public void testStop()
+    public void testStop() throws Exception
     {
         String[] args = new String[] { "-c",
                                        "foober",
                                        "-b",
                                        "toast" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options, args, true);
-            assertTrue( "Confirm -c is set", cl.hasOption("c") );
-            assertTrue( "Confirm  3 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 3);
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        CommandLine cl = _parser.parse(_options, args, true);
+        assertTrue( "Confirm -c is set", cl.hasOption("c") );
+        assertTrue( "Confirm  3 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 3);
     }
 
-    public void testMultiple()
+    public void testMultiple() throws Exception
     {
         String[] args = new String[] { "-c",
                                        "foobar",
                                        "-b",
                                        "toast" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options, args, true);
-            assertTrue( "Confirm -c is set", cl.hasOption("c") );
-            assertTrue( "Confirm  3 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 3);
+        CommandLine cl = _parser.parse(_options, args, true);
+        assertTrue( "Confirm -c is set", cl.hasOption("c") );
+        assertTrue( "Confirm  3 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 3);
 
-            cl = _parser.parse(_options, cl.getArgs() );
+        cl = _parser.parse(_options, cl.getArgs() );
 
-            assertTrue( "Confirm -c is not set", ! cl.hasOption("c") );
-            assertTrue( "Confirm -b is set", cl.hasOption("b") );
-            assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
-            assertTrue( "Confirm  1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
-            assertTrue( "Confirm  value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("foobar") );
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        assertTrue( "Confirm -c is not set", ! cl.hasOption("c") );
+        assertTrue( "Confirm -b is set", cl.hasOption("b") );
+        assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
+        assertTrue( "Confirm  1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
+        assertTrue( "Confirm  value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("foobar") );
     }
 
-    public void testMultipleWithLong()
+    public void testMultipleWithLong() throws Exception
     {
         String[] args = new String[] { "--copt",
                                        "foobar",
                                        "--bfile", "toast" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options,args,
-                                            true);
-            assertTrue( "Confirm -c is set", cl.hasOption("c") );
-            assertTrue( "Confirm  3 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 3);
+        CommandLine cl = _parser.parse(_options,args,
+                                        true);
+        assertTrue( "Confirm -c is set", cl.hasOption("c") );
+        assertTrue( "Confirm  3 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 3);
 
-            cl = _parser.parse(_options, cl.getArgs() );
+        cl = _parser.parse(_options, cl.getArgs() );
 
-            assertTrue( "Confirm -c is not set", ! cl.hasOption("c") );
-            assertTrue( "Confirm -b is set", cl.hasOption("b") );
-            assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
-            assertTrue( "Confirm  1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
-            assertTrue( "Confirm  value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("foobar") );
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        assertTrue( "Confirm -c is not set", ! cl.hasOption("c") );
+        assertTrue( "Confirm -b is set", cl.hasOption("b") );
+        assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
+        assertTrue( "Confirm  1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
+        assertTrue( "Confirm  value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("foobar") );
     }
 
-    public void testDoubleDash()
+    public void testDoubleDash() throws Exception
     {
         String[] args = new String[] { "--copt",
                                        "--",
                                        "-b", "toast" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options, args);
-
-            assertTrue( "Confirm -c is set", cl.hasOption("c") );
-            assertTrue( "Confirm -b is not set", ! cl.hasOption("b") );
-            assertTrue( "Confirm 2 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 2);
+        CommandLine cl = _parser.parse(_options, args);
 
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        assertTrue( "Confirm -c is set", cl.hasOption("c") );
+        assertTrue( "Confirm -b is not set", ! cl.hasOption("b") );
+        assertTrue( "Confirm 2 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 2);
     }
 
-    public void testSingleDash()
+    public void testSingleDash() throws Exception
     {
         String[] args = new String[] { "--copt",
                                        "-b", "-",
                                        "-a",
                                        "-" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options, args);
+        CommandLine cl = _parser.parse(_options, args);
 
-            assertTrue( "Confirm -a is set", cl.hasOption("a") );
-            assertTrue( "Confirm -b is set", cl.hasOption("b") );
-            assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("-") );
-            assertTrue( "Confirm 1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
-            assertTrue( "Confirm value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("-") );
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
-        
+        assertTrue( "Confirm -a is set", cl.hasOption("a") );
+        assertTrue( "Confirm -b is set", cl.hasOption("b") );
+        assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("-") );
+        assertTrue( "Confirm 1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
+        assertTrue( "Confirm value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("-") );
     }
 }

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionBuilderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionBuilderTest.java?rev=661378&r1=661377&r2=661378&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionBuilderTest.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionBuilderTest.java Thu May 29 09:11:48 2008
@@ -88,30 +88,19 @@
         assertTrue( !base.hasArg() );
     }
 
-    public void testSpecialOptChars() {
-
+    public void testSpecialOptChars() throws Exception
+    {
         // '?'
-        try {
-            Option opt = OptionBuilder.withDescription( "help options" )
-                                      .create( '?' );
-            assertEquals( "?", opt.getOpt() );
-        }
-        catch( IllegalArgumentException arg ) {
-            fail( "IllegalArgumentException caught" );
-        }
+        Option opt1 = OptionBuilder.withDescription("help options").create('?');
+        assertEquals("?", opt1.getOpt());
 
         // '@'
-        try {
-            Option opt = OptionBuilder.withDescription( "read from stdin" )
-                                      .create( '@' );
-            assertEquals( "@", opt.getOpt() );
-        }
-        catch( IllegalArgumentException arg ) {
-            fail( "IllegalArgumentException caught" );
-        }
+        Option opt2 = OptionBuilder.withDescription("read from stdin").create('@');
+        assertEquals("@", opt2.getOpt());
     }
 
-    public void testOptionArgNumbers() {
+    public void testOptionArgNumbers()
+    {
         Option opt = OptionBuilder.withDescription( "option description" )
                                   .hasArgs( 2 )
                                   .create( 'o' );
@@ -121,8 +110,7 @@
     public void testIllegalOptions() {
         // bad single character option
         try {
-            Option opt = OptionBuilder.withDescription( "option description" )
-                                      .create( '"' );
+            OptionBuilder.withDescription( "option description" ).create( '"' );
             fail( "IllegalArgumentException not caught" );
         }
         catch( IllegalArgumentException exp ) {

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionGroupTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionGroupTest.java?rev=661378&r1=661377&r2=661378&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionGroupTest.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionGroupTest.java Thu May 29 09:11:48 2008
@@ -55,130 +55,88 @@
         _options.addOption( "r", "revision", false, "revision number" );
     }
 
-    public void testSingleOptionFromGroup()
+    public void testSingleOptionFromGroup() throws Exception
     {
         String[] args = new String[] { "-f" };
 
-        try
-        {
-            CommandLine cl = parser.parse( _options, args);
+        CommandLine cl = parser.parse( _options, args);
 
-            assertTrue( "Confirm -r is NOT set", !cl.hasOption("r") );
-            assertTrue( "Confirm -f is set", cl.hasOption("f") );
-            assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
-            assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
-            assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
-            assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        assertTrue( "Confirm -r is NOT set", !cl.hasOption("r") );
+        assertTrue( "Confirm -f is set", cl.hasOption("f") );
+        assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
+        assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
+        assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
+        assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
     }
 
-    public void testSingleOption()
+    public void testSingleOption() throws Exception
     {
         String[] args = new String[] { "-r" };
 
-        try
-        {
-            CommandLine cl = parser.parse( _options, args);
+        CommandLine cl = parser.parse( _options, args);
 
-            assertTrue( "Confirm -r is set", cl.hasOption("r") );
-            assertTrue( "Confirm -f is NOT set", !cl.hasOption("f") );
-            assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
-            assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
-            assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
-            assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        assertTrue( "Confirm -r is set", cl.hasOption("r") );
+        assertTrue( "Confirm -f is NOT set", !cl.hasOption("f") );
+        assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
+        assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
+        assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
+        assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
     }
 
-    public void testTwoValidOptions()
+    public void testTwoValidOptions() throws Exception
     {
         String[] args = new String[] { "-r", "-f" };
 
-        try
-        {
-            CommandLine cl = parser.parse( _options, args);
+        CommandLine cl = parser.parse( _options, args);
 
-            assertTrue( "Confirm -r is set", cl.hasOption("r") );
-            assertTrue( "Confirm -f is set", cl.hasOption("f") );
-            assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
-            assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
-            assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
-            assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        assertTrue( "Confirm -r is set", cl.hasOption("r") );
+        assertTrue( "Confirm -f is set", cl.hasOption("f") );
+        assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
+        assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
+        assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
+        assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
     }
 
-    public void testSingleLongOption()
+    public void testSingleLongOption() throws Exception
     {
         String[] args = new String[] { "--file" };
 
-        try
-        {
-            CommandLine cl = parser.parse( _options, args);
+        CommandLine cl = parser.parse( _options, args);
 
-            assertTrue( "Confirm -r is NOT set", !cl.hasOption("r") );
-            assertTrue( "Confirm -f is set", cl.hasOption("f") );
-            assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
-            assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
-            assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
-            assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        assertTrue( "Confirm -r is NOT set", !cl.hasOption("r") );
+        assertTrue( "Confirm -f is set", cl.hasOption("f") );
+        assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
+        assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
+        assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
+        assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
     }
 
-    public void testTwoValidLongOptions()
+    public void testTwoValidLongOptions() throws Exception
     {
         String[] args = new String[] { "--revision", "--file" };
 
-        try
-        {
-            CommandLine cl = parser.parse( _options, args);
+        CommandLine cl = parser.parse( _options, args);
 
-            assertTrue( "Confirm -r is set", cl.hasOption("r") );
-            assertTrue( "Confirm -f is set", cl.hasOption("f") );
-            assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
-            assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
-            assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
-            assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        assertTrue( "Confirm -r is set", cl.hasOption("r") );
+        assertTrue( "Confirm -f is set", cl.hasOption("f") );
+        assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
+        assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
+        assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
+        assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
     }
 
-    public void testNoOptionsExtraArgs()
+    public void testNoOptionsExtraArgs() throws Exception
     {
         String[] args = new String[] { "arg1", "arg2" };
 
-        try
-        {
-            CommandLine cl = parser.parse( _options, args);
+        CommandLine cl = parser.parse( _options, args);
 
-            assertTrue( "Confirm -r is NOT set", !cl.hasOption("r") );
-            assertTrue( "Confirm -f is NOT set", !cl.hasOption("f") );
-            assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
-            assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
-            assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
-            assertTrue( "Confirm TWO extra args", cl.getArgList().size() == 2);
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        assertTrue( "Confirm -r is NOT set", !cl.hasOption("r") );
+        assertTrue( "Confirm -f is NOT set", !cl.hasOption("f") );
+        assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
+        assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
+        assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
+        assertTrue( "Confirm TWO extra args", cl.getArgList().size() == 2);
     }
 
     public void testTwoOptionsFromGroup()
@@ -217,47 +175,26 @@
         }
     }
 
-    public void testTwoOptionsFromDifferentGroup()
+    public void testTwoOptionsFromDifferentGroup() throws Exception
     {
         String[] args = new String[] { "-f", "-s" };
 
-        try
-        {
-            CommandLine cl = parser.parse( _options, args);
-            assertTrue( "Confirm -r is NOT set", !cl.hasOption("r") );
-            assertTrue( "Confirm -f is set", cl.hasOption("f") );
-            assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
-            assertTrue( "Confirm -s is set", cl.hasOption("s") );
-            assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
-            assertTrue( "Confirm NO extra args", cl.getArgList().size() == 0);
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        CommandLine cl = parser.parse( _options, args);
+        assertTrue( "Confirm -r is NOT set", !cl.hasOption("r") );
+        assertTrue( "Confirm -f is set", cl.hasOption("f") );
+        assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
+        assertTrue( "Confirm -s is set", cl.hasOption("s") );
+        assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
+        assertTrue( "Confirm NO extra args", cl.getArgList().size() == 0);
     }
 
-    public void testValidLongOnlyOptions()
+    public void testValidLongOnlyOptions() throws Exception
     {
-        try
-        {
-            CommandLine cl = parser.parse( _options, new String[]{"--export"});
-            assertTrue( "Confirm --export is set", cl.hasOption("export") );
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
-                            
-        try
-        {
-            CommandLine cl = parser.parse( _options, new String[]{"--import"});
-            assertTrue( "Confirm --import is set", cl.hasOption("import") );
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        CommandLine cl1 = parser.parse(_options, new String[]{"--export"});
+        assertTrue("Confirm --export is set", cl1.hasOption("export"));
+
+        CommandLine cl2 = parser.parse(_options, new String[]{"--import"});
+        assertTrue("Confirm --import is set", cl2.hasOption("import"));
     }
 
 }

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseRequiredTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseRequiredTest.java?rev=661378&r1=661377&r2=661378&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseRequiredTest.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseRequiredTest.java Thu May 29 09:11:48 2008
@@ -42,42 +42,28 @@
                                      .create( 'b' ) );
     }
 
-    public void testWithRequiredOption()
+    public void testWithRequiredOption() throws Exception
     {
         String[] args = new String[] {  "-b", "file" };
 
-        try
-        {
-            CommandLine cl = parser.parse(_options,args);
-            
-            assertTrue( "Confirm -a is NOT set", !cl.hasOption("a") );
-            assertTrue( "Confirm -b is set", cl.hasOption("b") );
-            assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("file") );
-            assertTrue( "Confirm NO of extra args", cl.getArgList().size() == 0);
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        CommandLine cl = parser.parse(_options,args);
+
+        assertTrue( "Confirm -a is NOT set", !cl.hasOption("a") );
+        assertTrue( "Confirm -b is set", cl.hasOption("b") );
+        assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("file") );
+        assertTrue( "Confirm NO of extra args", cl.getArgList().size() == 0);
     }
 
-    public void testOptionAndRequiredOption()
+    public void testOptionAndRequiredOption() throws Exception
     {
         String[] args = new String[] {  "-a", "-b", "file" };
 
-        try
-        {
-            CommandLine cl = parser.parse(_options,args);
+        CommandLine cl = parser.parse(_options,args);
 
-            assertTrue( "Confirm -a is set", cl.hasOption("a") );
-            assertTrue( "Confirm -b is set", cl.hasOption("b") );
-            assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("file") );
-            assertTrue( "Confirm NO of extra args", cl.getArgList().size() == 0);
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        assertTrue( "Confirm -a is set", cl.hasOption("a") );
+        assertTrue( "Confirm -b is set", cl.hasOption("b") );
+        assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("file") );
+        assertTrue( "Confirm NO of extra args", cl.getArgList().size() == 0);
     }
 
     public void testMissingRequiredOption()

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseTest.java?rev=661378&r1=661377&r2=661378&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseTest.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseTest.java Thu May 29 09:11:48 2008
@@ -43,71 +43,50 @@
         _parser = new PosixParser();
     }
 
-    public void testSimpleShort()
+    public void testSimpleShort() throws Exception
     {
         String[] args = new String[] { "-a",
                                        "-b", "toast",
                                        "foo", "bar" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options, args);
-            
-            assertTrue( "Confirm -a is set", cl.hasOption("a") );
-            assertTrue( "Confirm -b is set", cl.hasOption("b") );
-            assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
-            assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        CommandLine cl = _parser.parse(_options, args);
+
+        assertTrue( "Confirm -a is set", cl.hasOption("a") );
+        assertTrue( "Confirm -b is set", cl.hasOption("b") );
+        assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
+        assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
     }
 
-    public void testSimpleLong()
+    public void testSimpleLong() throws Exception
     {
         String[] args = new String[] { "--enable-a",
                                        "--bfile", "toast",
                                        "foo", "bar" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options, args);
-            
-            assertTrue( "Confirm -a is set", cl.hasOption("a") );
-            assertTrue( "Confirm -b is set", cl.hasOption("b") );
-            assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
-            assertTrue( "Confirm arg of --bfile", cl.getOptionValue( "bfile" ).equals( "toast" ) );
-            assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
-        } 
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        CommandLine cl = _parser.parse(_options, args);
+
+        assertTrue( "Confirm -a is set", cl.hasOption("a") );
+        assertTrue( "Confirm -b is set", cl.hasOption("b") );
+        assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
+        assertTrue( "Confirm arg of --bfile", cl.getOptionValue( "bfile" ).equals( "toast" ) );
+        assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
     }
 
-    public void testComplexShort()
+    public void testComplexShort() throws Exception
     {
         String[] args = new String[] { "-acbtoast",
                                        "foo", "bar" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options, args);
-            
-            assertTrue( "Confirm -a is set", cl.hasOption("a") );
-            assertTrue( "Confirm -b is set", cl.hasOption("b") );
-            assertTrue( "Confirm -c is set", cl.hasOption("c") );
-            assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
-            assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        CommandLine cl = _parser.parse(_options, args);
+
+        assertTrue( "Confirm -a is set", cl.hasOption("a") );
+        assertTrue( "Confirm -b is set", cl.hasOption("b") );
+        assertTrue( "Confirm -c is set", cl.hasOption("c") );
+        assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
+        assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
     }
 
-    public void testExtraOption()
+    public void testExtraOption() throws Exception
     {
         String[] args = new String[] { "-adbtoast",
                                        "foo", "bar" };
@@ -127,14 +106,11 @@
         {
             caught = true;
         }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+
         assertTrue( "Confirm UnrecognizedOptionException caught", caught );
     }
 
-    public void testMissingArg()
+    public void testMissingArg() throws Exception
     {
 
         String[] args = new String[] { "-acb" };
@@ -143,133 +119,92 @@
 
         try
         {
-            CommandLine cl = _parser.parse(_options, args);
+            _parser.parse(_options, args);
         }
         catch (MissingArgumentException e)
         {
             caught = true;
         }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
 
         assertTrue( "Confirm MissingArgumentException caught", caught );
     }
 
-    public void testStop()
+    public void testStop() throws Exception
     {
         String[] args = new String[] { "-c",
                                        "foober",
                                        "-btoast" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options, args, true);
-            assertTrue( "Confirm -c is set", cl.hasOption("c") );
-            assertTrue( "Confirm  2 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 2);
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        CommandLine cl = _parser.parse(_options, args, true);
+        assertTrue( "Confirm -c is set", cl.hasOption("c") );
+        assertTrue( "Confirm  2 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 2);
     }
 
-    public void testMultiple()
+    public void testMultiple() throws Exception
     {
         String[] args = new String[] { "-c",
                                        "foobar",
                                        "-btoast" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options, args, true);
-            assertTrue( "Confirm -c is set", cl.hasOption("c") );
-            assertTrue( "Confirm  2 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 2);
+        CommandLine cl = _parser.parse(_options, args, true);
+        assertTrue( "Confirm -c is set", cl.hasOption("c") );
+        assertTrue( "Confirm  2 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 2);
 
-            cl = _parser.parse(_options, cl.getArgs() );
+        cl = _parser.parse(_options, cl.getArgs() );
 
-            assertTrue( "Confirm -c is not set", ! cl.hasOption("c") );
-            assertTrue( "Confirm -b is set", cl.hasOption("b") );
-            assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
-            assertTrue( "Confirm  1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
-            assertTrue( "Confirm  value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("foobar") );
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        assertTrue( "Confirm -c is not set", ! cl.hasOption("c") );
+        assertTrue( "Confirm -b is set", cl.hasOption("b") );
+        assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
+        assertTrue( "Confirm  1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
+        assertTrue( "Confirm  value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("foobar") );
     }
 
-    public void testMultipleWithLong()
+    public void testMultipleWithLong() throws Exception
     {
         String[] args = new String[] { "--copt",
                                        "foobar",
                                        "--bfile", "toast" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options,args,
-                                            true);
-            assertTrue( "Confirm -c is set", cl.hasOption("c") );
-            assertTrue( "Confirm  3 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 3);
+        CommandLine cl = _parser.parse(_options,args,
+                                        true);
+        assertTrue( "Confirm -c is set", cl.hasOption("c") );
+        assertTrue( "Confirm  3 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 3);
 
-            cl = _parser.parse(_options, cl.getArgs() );
+        cl = _parser.parse(_options, cl.getArgs() );
 
-            assertTrue( "Confirm -c is not set", ! cl.hasOption("c") );
-            assertTrue( "Confirm -b is set", cl.hasOption("b") );
-            assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
-            assertTrue( "Confirm  1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
-            assertTrue( "Confirm  value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("foobar") );
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        assertTrue( "Confirm -c is not set", ! cl.hasOption("c") );
+        assertTrue( "Confirm -b is set", cl.hasOption("b") );
+        assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
+        assertTrue( "Confirm  1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
+        assertTrue( "Confirm  value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("foobar") );
     }
 
-    public void testDoubleDash()
+    public void testDoubleDash() throws Exception
     {
         String[] args = new String[] { "--copt",
                                        "--",
                                        "-b", "toast" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options, args);
-
-            assertTrue( "Confirm -c is set", cl.hasOption("c") );
-            assertTrue( "Confirm -b is not set", ! cl.hasOption("b") );
-            assertTrue( "Confirm 2 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 2);
+        CommandLine cl = _parser.parse(_options, args);
 
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
+        assertTrue( "Confirm -c is set", cl.hasOption("c") );
+        assertTrue( "Confirm -b is not set", ! cl.hasOption("b") );
+        assertTrue( "Confirm 2 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 2);
     }
 
-    public void testSingleDash()
+    public void testSingleDash() throws Exception
     {
         String[] args = new String[] { "--copt",
                                        "-b", "-",
                                        "-a",
                                        "-" };
 
-        try
-        {
-            CommandLine cl = _parser.parse(_options, args);
+        CommandLine cl = _parser.parse(_options, args);
 
-            assertTrue( "Confirm -a is set", cl.hasOption("a") );
-            assertTrue( "Confirm -b is set", cl.hasOption("b") );
-            assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("-") );
-            assertTrue( "Confirm 1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
-            assertTrue( "Confirm value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("-") );
-        }
-        catch (ParseException e)
-        {
-            fail( e.toString() );
-        }
-        
+        assertTrue( "Confirm -a is set", cl.hasOption("a") );
+        assertTrue( "Confirm -b is set", cl.hasOption("b") );
+        assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("-") );
+        assertTrue( "Confirm 1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
+        assertTrue( "Confirm value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("-") );
     }
 }

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ValueTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ValueTest.java?rev=661378&r1=661377&r2=661378&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ValueTest.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ValueTest.java Thu May 29 09:11:48 2008
@@ -114,137 +114,88 @@
         assertEquals( _cl.getOptionValue("d"), "bar");
     }
 
-    public void testShortOptionalArgNoValue()
+    public void testShortOptionalArgNoValue() throws Exception
     {
-        String[] args = new String[] { "-e"
-        };
-        try
-        {
-            Parser parser = new PosixParser();
-            CommandLine cmd = parser.parse(opts,args);
-            assertTrue( cmd.hasOption("e") );
-            assertNull( cmd.getOptionValue("e") );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
+        String[] args = new String[] { "-e" };
+
+        Parser parser = new PosixParser();
+        CommandLine cmd = parser.parse(opts,args);
+        assertTrue( cmd.hasOption("e") );
+        assertNull( cmd.getOptionValue("e") );
     }
 
-    public void testShortOptionalArgValue()
+    public void testShortOptionalArgValue() throws Exception
     {
-        String[] args = new String[] { "-e", "everything"
-        };
-        try
-        {
-            Parser parser = new PosixParser();
-            CommandLine cmd = parser.parse(opts,args);
-            assertTrue( cmd.hasOption("e") );
-            assertEquals( "everything", cmd.getOptionValue("e") );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
+        String[] args = new String[] { "-e", "everything" };
+
+        Parser parser = new PosixParser();
+        CommandLine cmd = parser.parse(opts,args);
+        assertTrue( cmd.hasOption("e") );
+        assertEquals( "everything", cmd.getOptionValue("e") );
     }
 
-    public void testLongOptionalNoValue()
+    public void testLongOptionalNoValue() throws Exception
     {
-        String[] args = new String[] { "--fish"
-        };
-        try
-        {
-            Parser parser = new PosixParser();
-            CommandLine cmd = parser.parse(opts,args);
-            assertTrue( cmd.hasOption("fish") );
-            assertNull( cmd.getOptionValue("fish") );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
+        String[] args = new String[] { "--fish" };
+
+        Parser parser = new PosixParser();
+        CommandLine cmd = parser.parse(opts,args);
+        assertTrue( cmd.hasOption("fish") );
+        assertNull( cmd.getOptionValue("fish") );
     }
 
-    public void testLongOptionalArgValue()
+    public void testLongOptionalArgValue() throws Exception
     {
-        String[] args = new String[] { "--fish", "face"
-        };
-        try
-        {
-            Parser parser = new PosixParser();
-            CommandLine cmd = parser.parse(opts,args);
-            assertTrue( cmd.hasOption("fish") );
-            assertEquals( "face", cmd.getOptionValue("fish") );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
+        String[] args = new String[] { "--fish", "face" };
+
+        Parser parser = new PosixParser();
+        CommandLine cmd = parser.parse(opts,args);
+        assertTrue( cmd.hasOption("fish") );
+        assertEquals( "face", cmd.getOptionValue("fish") );
     }
 
-    public void testShortOptionalArgValues()
+    public void testShortOptionalArgValues() throws Exception
     {
-        String[] args = new String[] { "-j", "ink", "idea"
-        };
-        try
-        {
-            Parser parser = new PosixParser();
-            CommandLine cmd = parser.parse(opts,args);
-            assertTrue( cmd.hasOption("j") );
-            assertEquals( "ink", cmd.getOptionValue("j") );
-            assertEquals( "ink", cmd.getOptionValues("j")[0] );
-            assertEquals( "idea", cmd.getOptionValues("j")[1] );
-            assertEquals( cmd.getArgs().length, 0 );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
+        String[] args = new String[] { "-j", "ink", "idea" };
+
+        Parser parser = new PosixParser();
+        CommandLine cmd = parser.parse(opts,args);
+        assertTrue( cmd.hasOption("j") );
+        assertEquals( "ink", cmd.getOptionValue("j") );
+        assertEquals( "ink", cmd.getOptionValues("j")[0] );
+        assertEquals( "idea", cmd.getOptionValues("j")[1] );
+        assertEquals( cmd.getArgs().length, 0 );
     }
 
-    public void testLongOptionalArgValues()
+    public void testLongOptionalArgValues() throws Exception
     {
-        String[] args = new String[] { "--gravy", "gold", "garden"
-        };
-        try
-        {
-            Parser parser = new PosixParser();
-            CommandLine cmd = parser.parse(opts,args);
-            assertTrue( cmd.hasOption("gravy") );
-            assertEquals( "gold", cmd.getOptionValue("gravy") );
-            assertEquals( "gold", cmd.getOptionValues("gravy")[0] );
-            assertEquals( "garden", cmd.getOptionValues("gravy")[1] );
-            assertEquals( cmd.getArgs().length, 0 );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
+        String[] args = new String[] { "--gravy", "gold", "garden" };
+
+        Parser parser = new PosixParser();
+        CommandLine cmd = parser.parse(opts,args);
+        assertTrue( cmd.hasOption("gravy") );
+        assertEquals( "gold", cmd.getOptionValue("gravy") );
+        assertEquals( "gold", cmd.getOptionValues("gravy")[0] );
+        assertEquals( "garden", cmd.getOptionValues("gravy")[1] );
+        assertEquals( cmd.getArgs().length, 0 );
     }
 
-    public void testShortOptionalNArgValues()
+    public void testShortOptionalNArgValues() throws Exception
     {
-        String[] args = new String[] { "-i", "ink", "idea", "isotope", "ice"
-        };
-        try
-        {
-            Parser parser = new PosixParser();
-            CommandLine cmd = parser.parse(opts,args);
-            assertTrue( cmd.hasOption("i") );
-            assertEquals( "ink", cmd.getOptionValue("i") );
-            assertEquals( "ink", cmd.getOptionValues("i")[0] );
-            assertEquals( "idea", cmd.getOptionValues("i")[1] );
-            assertEquals( cmd.getArgs().length, 2 );
-            assertEquals( "isotope", cmd.getArgs()[0] );
-            assertEquals( "ice", cmd.getArgs()[1] );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
+        String[] args = new String[] { "-i", "ink", "idea", "isotope", "ice" };
+
+        Parser parser = new PosixParser();
+        CommandLine cmd = parser.parse(opts,args);
+        assertTrue( cmd.hasOption("i") );
+        assertEquals( "ink", cmd.getOptionValue("i") );
+        assertEquals( "ink", cmd.getOptionValues("i")[0] );
+        assertEquals( "idea", cmd.getOptionValues("i")[1] );
+        assertEquals( cmd.getArgs().length, 2 );
+        assertEquals( "isotope", cmd.getArgs()[0] );
+        assertEquals( "ice", cmd.getArgs()[1] );
     }
 
-    public void testLongOptionalNArgValues()
+    public void testLongOptionalNArgValues() throws Exception
     {
         String[] args = new String[] { 
             "--hide", "house", "hair", "head"
@@ -252,43 +203,29 @@
 
         Parser parser = new PosixParser();
 
-        try
-        {
-            CommandLine cmd = parser.parse(opts,args);
-            assertTrue( cmd.hasOption("hide") );
-            assertEquals( "house", cmd.getOptionValue("hide") );
-            assertEquals( "house", cmd.getOptionValues("hide")[0] );
-            assertEquals( "hair", cmd.getOptionValues("hide")[1] );
-            assertEquals( cmd.getArgs().length, 1 );
-            assertEquals( "head", cmd.getArgs()[0] );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
+        CommandLine cmd = parser.parse(opts,args);
+        assertTrue( cmd.hasOption("hide") );
+        assertEquals( "house", cmd.getOptionValue("hide") );
+        assertEquals( "house", cmd.getOptionValues("hide")[0] );
+        assertEquals( "hair", cmd.getOptionValues("hide")[1] );
+        assertEquals( cmd.getArgs().length, 1 );
+        assertEquals( "head", cmd.getArgs()[0] );
     }
 
-    public void testPropertyOptionSingularValue()
+    public void testPropertyOptionSingularValue() throws Exception
     {
         Properties properties = new Properties();
         properties.setProperty( "hide", "seek" );
 
         Parser parser = new PosixParser();
         
-        try
-        {
-            CommandLine cmd = parser.parse(opts, null, properties);
-            assertTrue( cmd.hasOption("hide") );
-            assertEquals( "seek", cmd.getOptionValue("hide") );
-            assertTrue( !cmd.hasOption("fake") );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
+        CommandLine cmd = parser.parse(opts, null, properties);
+        assertTrue( cmd.hasOption("hide") );
+        assertEquals( "seek", cmd.getOptionValue("hide") );
+        assertTrue( !cmd.hasOption("fake") );
     }
 
-    public void testPropertyOptionFlags()
+    public void testPropertyOptionFlags() throws Exception
     {
         Properties properties = new Properties();
         properties.setProperty( "a", "true" );
@@ -296,69 +233,46 @@
         properties.setProperty( "e", "1" );
 
         Parser parser = new PosixParser();
-        
-        try
-        {
-            CommandLine cmd = parser.parse(opts, null, properties);
-            assertTrue( cmd.hasOption("a") );
-            assertTrue( cmd.hasOption("c") );
-            assertTrue( cmd.hasOption("e") );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
+
+        CommandLine cmd = parser.parse(opts, null, properties);
+        assertTrue( cmd.hasOption("a") );
+        assertTrue( cmd.hasOption("c") );
+        assertTrue( cmd.hasOption("e") );
+
 
         properties = new Properties();
         properties.setProperty( "a", "false" );
         properties.setProperty( "c", "no" );
         properties.setProperty( "e", "0" );
-        try
-        {
-            CommandLine cmd = parser.parse(opts, null, properties);
-            assertTrue( !cmd.hasOption("a") );
-            assertTrue( !cmd.hasOption("c") );
-            assertTrue( !cmd.hasOption("e") );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
+
+        cmd = parser.parse(opts, null, properties);
+        assertTrue( !cmd.hasOption("a") );
+        assertTrue( !cmd.hasOption("c") );
+        assertTrue( !cmd.hasOption("e") );
+
 
         properties = new Properties();
         properties.setProperty( "a", "TRUE" );
         properties.setProperty( "c", "nO" );
         properties.setProperty( "e", "TrUe" );
-        try
-        {
-            CommandLine cmd = parser.parse(opts, null, properties);
-            assertTrue( cmd.hasOption("a") );
-            assertTrue( !cmd.hasOption("c") );
-            assertTrue( cmd.hasOption("e") );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
 
+        cmd = parser.parse(opts, null, properties);
+        assertTrue( cmd.hasOption("a") );
+        assertTrue( !cmd.hasOption("c") );
+        assertTrue( cmd.hasOption("e") );
+
+        
         properties = new Properties();
         properties.setProperty( "a", "just a string" );
         properties.setProperty( "e", "" );
-        try
-        {
-            CommandLine cmd = parser.parse(opts, null, properties);
-            assertTrue( !cmd.hasOption("a") );
-            assertTrue( !cmd.hasOption("c") );
-            assertTrue( !cmd.hasOption("e") );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
 
+        cmd = parser.parse(opts, null, properties);
+        assertTrue( !cmd.hasOption("a") );
+        assertTrue( !cmd.hasOption("c") );
+        assertTrue( !cmd.hasOption("e") );
     } 
 
-    public void testPropertyOptionMultipleValues()
+    public void testPropertyOptionMultipleValues() throws Exception
     {
         Properties properties = new Properties();
         properties.setProperty( "k", "one,two" );
@@ -368,19 +282,13 @@
         String[] values = new String[] {
             "one", "two"
         };
-        try
-        {
-            CommandLine cmd = parser.parse(opts, null, properties);
-            assertTrue( cmd.hasOption("k") );
-            assertTrue( Arrays.equals( values, cmd.getOptionValues('k') ) );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
+
+        CommandLine cmd = parser.parse(opts, null, properties);
+        assertTrue( cmd.hasOption("k") );
+        assertTrue( Arrays.equals( values, cmd.getOptionValues('k') ) );
     }
 
-    public void testPropertyOverrideValues()
+    public void testPropertyOverrideValues() throws Exception
     {
         String[] args = new String[] { 
             "-j",
@@ -391,20 +299,14 @@
 
         Properties properties = new Properties();
         properties.setProperty( "j", "seek" );
-        try
-        {
-            Parser parser = new PosixParser();
-            CommandLine cmd = parser.parse(opts, args, properties);
-            assertTrue( cmd.hasOption("j") );
-            assertEquals( "found", cmd.getOptionValue("j") );
-            assertTrue( cmd.hasOption("i") );
-            assertEquals( "ink", cmd.getOptionValue("i") );
-            assertTrue( !cmd.hasOption("fake") );
-        }
-        catch (ParseException e)
-        {
-            fail("Cannot setUp() CommandLine: " + e.toString());
-        }
+
+        Parser parser = new PosixParser();
+        CommandLine cmd = parser.parse(opts, args, properties);
+        assertTrue( cmd.hasOption("j") );
+        assertEquals( "found", cmd.getOptionValue("j") );
+        assertTrue( cmd.hasOption("i") );
+        assertEquals( "ink", cmd.getOptionValue("i") );
+        assertTrue( !cmd.hasOption("fake") );
     }
 
 }



Mime
View raw message