You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2013/01/30 18:33:39 UTC

svn commit: r1440541 - /commons/proper/cli/trunk/src/test/java/org/apache/commons/cli/BugsTest.java

Author: sebb
Date: Wed Jan 30 17:33:38 2013
New Revision: 1440541

URL: http://svn.apache.org/viewvc?rev=1440541&view=rev
Log:
Simplify exception testing

Modified:
    commons/proper/cli/trunk/src/test/java/org/apache/commons/cli/BugsTest.java

Modified: commons/proper/cli/trunk/src/test/java/org/apache/commons/cli/BugsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/java/org/apache/commons/cli/BugsTest.java?rev=1440541&r1=1440540&r2=1440541&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/java/org/apache/commons/cli/BugsTest.java (original)
+++ commons/proper/cli/trunk/src/test/java/org/apache/commons/cli/BugsTest.java Wed Jan 30 17:33:38 2013
@@ -201,17 +201,11 @@ public class BugsTest extends TestCase
 
         Parser parser = new PosixParser();
 
-        try
-        {
+        try {
             parser.parse( options, args );
+            fail( "MissingArgumentException not caught." );
+        } catch( MissingArgumentException expected ) {
         }
-        // catch the exception and leave the method
-        catch( Exception exp )
-        {
-            assertTrue( exp != null );
-            return;
-        }
-        fail( "MissingArgumentException not caught." );
     }
 
     public void test13666() throws Exception
@@ -263,62 +257,31 @@ public class BugsTest extends TestCase
         opts.addOption( straight );
 
         CommandLineParser parser = new PosixParser();
-        boolean exception = false;
 
         String[] args = new String[] {  };
-        try
-        {
+        try {
             parser.parse(opts, args);
+            fail("Expected ParseException");
         }
-        catch (ParseException exp)
-        {
-            exception = true;
+        catch (ParseException expected) {
         }
 
-        if (!exception)
-        {
-            fail("Expected exception not caught.");
-        }
-
-        exception = false;
-
         args = new String[] { "-s" };
-        try
-        {
+        try {
             parser.parse(opts, args);
+            fail("Expected ParseException");
         }
-        catch (ParseException exp)
-        {
-            exception = true;
-        }
-
-        if (!exception)
-        {
-            fail("Expected exception not caught.");
+        catch (ParseException expected) {
         }
 
-        exception = false;
-
         args = new String[] { "-s", "-l" };
-        try
-        {
-            parser.parse(opts, args);
-        }
-        catch (ParseException exp)
-        {
-            fail("Unexpected exception: " + exp.getClass().getName() + ":" + exp.getMessage());
-        }
+        CommandLine line = parser.parse(opts, args);
+        assertNotNull(line);
 
         opts.addOption( forward );
         args = new String[] { "-s", "-l", "-f" };
-        try
-        {
-            parser.parse(opts, args);
-        }
-        catch (ParseException exp)
-        {
-            fail("Unexpected exception: " + exp.getClass().getName() + ":" + exp.getMessage());
-        }
+        line = parser.parse(opts, args);
+        assertNotNull(line);
     }
 
     public void test14786() throws Exception