Author: ebourg
Date: Fri May 30 02:46:41 2008
New Revision: 661620
URL: http://svn.apache.org/viewvc?rev=661620&view=rev
Log:
Added tests for the formatting of option groups
Modified:
commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/HelpFormatterTest.java
Modified:
commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java
URL:
http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java?rev=661620&r1=661619&r2=661620&view=diff
==============================================================================
---
commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java
(original)
+++
commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java
Fri May 30 02:46:41 2008
@@ -14,10 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.cli;
import java.io.PrintWriter;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -30,7 +30,7 @@
*
* @author Slawek Zachcial
* @author John Keyes (john at integralsource.com)
- **/
+ */
public class HelpFormatter {
// ---------------------------------------------------------------
Constants
Modified:
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/HelpFormatterTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/HelpFormatterTest.java?rev=661620&r1=661619&r2=661620&view=diff
==============================================================================
---
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/HelpFormatterTest.java
(original)
+++
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/HelpFormatterTest.java
Fri May 30 02:46:41 2008
@@ -19,6 +19,7 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.Comparator;
import junit.framework.TestCase;
@@ -221,4 +222,39 @@
assertEquals("usage: app [-c] [-b] [-a]" + EOL, bytesOut.toString());
}
+ public void testPrintOptionGroupUsage() {
+ OptionGroup group = new OptionGroup();
+ group.addOption(OptionBuilder.create("a"));
+ group.addOption(OptionBuilder.create("b"));
+ group.addOption(OptionBuilder.create("c"));
+
+ Options options = new Options();
+ options.addOptionGroup(group);
+
+ StringWriter out = new StringWriter();
+
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printUsage(new PrintWriter(out), 80, "app", options);
+
+ assertEquals("usage: app [-a | -b | -c]" + EOL, out.toString());
+ }
+
+ public void testPrintRequiredOptionGroupUsage() {
+ OptionGroup group = new OptionGroup();
+ group.addOption(OptionBuilder.create("a"));
+ group.addOption(OptionBuilder.create("b"));
+ group.addOption(OptionBuilder.create("c"));
+ group.setRequired(true);
+
+ Options options = new Options();
+ options.addOptionGroup(group);
+
+ StringWriter out = new StringWriter();
+
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printUsage(new PrintWriter(out), 80, "app", options);
+
+ assertEquals("usage: app -a | -b | -c" + EOL, out.toString());
+ }
+
}