Author: bayard
Date: Wed May 7 23:56:36 2008
New Revision: 654431
URL: http://svn.apache.org/viewvc?rev=654431&view=rev
Log:
Adding comma delimited whitespace to the exception message that lists missing
required options as requested in CLI-149. I didn't add the requested -, as it
could be -- or some other prefix. Unit tests also added.
Modified:
commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Parser.java
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionsTest.java
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseRequiredTest.java
Modified:
commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Parser.java
URL:
http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Parser.java?rev=654431&r1=654430&r2=654431&view=diff
==============================================================================
---
commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Parser.java
(original)
+++
commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Parser.java
Wed May 7 23:56:36 2008
@@ -317,9 +317,10 @@
while (iter.hasNext())
{
buff.append(iter.next());
+ buff.append(", ");
}
- throw new MissingOptionException(buff.toString());
+ throw new MissingOptionException(buff.substring(0, buff.length() -
2));
}
}
Modified:
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionsTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionsTest.java?rev=654431&r1=654430&r2=654431&view=diff
==============================================================================
---
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionsTest.java
(original)
+++
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionsTest.java
Wed May 7 23:56:36 2008
@@ -113,7 +113,7 @@
new PosixParser().parse(options, new String[0]);
fail("Expected MissingOptionException to be thrown");
} catch (MissingOptionException e) {
- assertEquals("Missing required options: fx", e.getMessage());
+ assertEquals("Missing required options: f, x", e.getMessage());
}
}
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=654431&r1=654430&r2=654431&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
Wed May 7 23:56:36 2008
@@ -105,12 +105,38 @@
CommandLine cl = parser.parse(_options,args);
fail( "exception should have been thrown" );
}
+ catch (MissingOptionException e)
+ {
+ assertEquals( "Incorrect exception message", "Missing required
option: b", e.getMessage() );
+ }
+ catch (ParseException e)
+ {
+ fail( "expected to catch MissingOptionException" );
+ }
+ }
+
+ public void testMissingRequiredOptions()
+ {
+ String[] args = new String[] { "-a" };
+
+ _options.addOption( OptionBuilder.withLongOpt( "cfile" )
+ .hasArg()
+ .isRequired()
+ .withDescription( "set the value of [c]" )
+ .create( 'c' ) );
+
+ try
+ {
+ CommandLine cl = parser.parse(_options,args);
+ fail( "exception should have been thrown" );
+ }
+ catch (MissingOptionException e)
+ {
+ assertEquals( "Incorrect exception message", "Missing required
options: b, c", e.getMessage() );
+ }
catch (ParseException e)
{
- if( !( e instanceof MissingOptionException ) )
- {
- fail( "expected to catch MissingOptionException" );
- }
+ fail( "expected to catch MissingOptionException" );
}
}