http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/OptionsTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli/OptionsTest.java b/src/test/org/apache/commons/cli/OptionsTest.java deleted file mode 100644 index 1cdae68..0000000 --- a/src/test/org/apache/commons/cli/OptionsTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * Copyright 2001-2004 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.cli; - -import java.util.ArrayList; -import java.util.Collection; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * @author Rob Oxspring [email protected] - * @version $Revision$ - */ -public class OptionsTest extends TestCase -{ - - public static Test suite() - { - return new TestSuite ( OptionsTest.class ); - } - - public OptionsTest( String name ) - { - super( name ); - } - - public void setUp() - { - } - - public void tearDown() - { - } - - public void testHelpOptions(){ - - Option longOnly1 = OptionBuilder - .withLongOpt("long-only1") - .create(); - - Option longOnly2 = OptionBuilder - .withLongOpt("long-only2") - .create(); - - Option shortOnly1 = OptionBuilder - .create("1"); - - Option shortOnly2 = OptionBuilder - .create("2"); - - Option bothA = OptionBuilder - .withLongOpt("bothA") - .create("a"); - - Option bothB = OptionBuilder - .withLongOpt("bothB") - .create("b"); - - Options options = new Options(); - options.addOption(longOnly1); - options.addOption(longOnly2); - options.addOption(shortOnly1); - options.addOption(shortOnly2); - options.addOption(bothA); - options.addOption(bothB); - - Collection allOptions = new ArrayList(); - allOptions.add(longOnly1); - allOptions.add(longOnly2); - allOptions.add(shortOnly1); - allOptions.add(shortOnly2); - allOptions.add(bothA); - allOptions.add(bothB); - - Collection helpOptions = options.helpOptions(); - - assertTrue("Everything in all should be in help",helpOptions.containsAll(allOptions)); - assertTrue("Everything in help should be in all",allOptions.containsAll(helpOptions)); - } - - - -} -
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/ParseRequiredTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli/ParseRequiredTest.java b/src/test/org/apache/commons/cli/ParseRequiredTest.java deleted file mode 100644 index 104da93..0000000 --- a/src/test/org/apache/commons/cli/ParseRequiredTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Copyright 2001-2004 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.cli; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * @author John Keyes (john at integralsource.com) - * @version $Revision$ - */ -public class ParseRequiredTest extends TestCase -{ - - private Options _options = null; - private CommandLineParser parser = new PosixParser(); - - public static Test suite() { - return new TestSuite(ParseRequiredTest.class); - } - - public ParseRequiredTest(String name) - { - super(name); - } - - public void setUp() - { - _options = new Options() - .addOption("a", - "enable-a", - false, - "turn [a] on or off") - .addOption( OptionBuilder.withLongOpt( "bfile" ) - .hasArg() - .isRequired() - .withDescription( "set the value of [b]" ) - .create( 'b' ) ); - } - - public void tearDown() - { - - } - - public void testWithRequiredOption() - { - 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() ); - } - } - - public void testOptionAndRequiredOption() - { - String[] args = new String[] { "-a", "-b", "file" }; - - 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("file") ); - assertTrue( "Confirm NO of extra args", cl.getArgList().size() == 0); - } - catch (ParseException e) - { - fail( e.toString() ); - } - } - - public void testMissingRequiredOption() - { - String[] args = new String[] { "-a" }; - - try - { - CommandLine cl = parser.parse(_options,args); - fail( "exception should have been thrown" ); - } - catch (ParseException e) - { - if( !( e instanceof MissingOptionException ) ) - { - fail( "expected to catch MissingOptionException" ); - } - } - } - -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/ParseTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli/ParseTest.java b/src/test/org/apache/commons/cli/ParseTest.java deleted file mode 100644 index 96ce866..0000000 --- a/src/test/org/apache/commons/cli/ParseTest.java +++ /dev/null @@ -1,290 +0,0 @@ -/** - * Copyright 2001-2004 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.cli; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class ParseTest extends TestCase -{ - - private Options _options = null; - private CommandLineParser _parser = null; - - public static Test suite() { - return new TestSuite(ParseTest.class); - } - - public ParseTest(String name) - { - super(name); - } - - public void setUp() - { - _options = new Options() - .addOption("a", - "enable-a", - false, - "turn [a] on or off") - .addOption("b", - "bfile", - true, - "set the value of [b]") - .addOption("c", - "copt", - false, - "turn [c] on or off"); - - _parser = new PosixParser(); - } - - public void tearDown() - { - - } - - public void testSimpleShort() - { - 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() ); - } - } - - public void testSimpleLong() - { - 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() ); - } - } - - public void testComplexShort() - { - 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() ); - } - } - - public void testExtraOption() - { - String[] args = new String[] { "-adbtoast", - "foo", "bar" }; - - boolean caught = false; - - 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() == 3); - } - catch (UnrecognizedOptionException e) - { - caught = true; - } - catch (ParseException e) - { - fail( e.toString() ); - } - assertTrue( "Confirm UnrecognizedOptionException caught", caught ); - } - - public void testMissingArg() - { - - String[] args = new String[] { "-acb" }; - - boolean caught = false; - - try - { - CommandLine cl = _parser.parse(_options, args); - } - catch (MissingArgumentException e) - { - caught = true; - } - catch (ParseException e) - { - fail( e.toString() ); - } - - assertTrue( "Confirm MissingArgumentException caught", caught ); - } - - public void testStop() - { - 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() ); - } - } - - public void testMultiple() - { - 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); - - 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() ); - } - } - - public void testMultipleWithLong() - { - 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); - - 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() ); - } - } - - public void testDoubleDash() - { - 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); - - } - catch (ParseException e) - { - fail( e.toString() ); - } - } - - public void testSingleDash() - { - String[] args = new String[] { "--copt", - "-b", "-", - "-a", - "-" }; - - 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("-") ); - 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() ); - } - - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/PatternOptionBuilderTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli/PatternOptionBuilderTest.java b/src/test/org/apache/commons/cli/PatternOptionBuilderTest.java deleted file mode 100644 index 805ff6b..0000000 --- a/src/test/org/apache/commons/cli/PatternOptionBuilderTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Copyright 2001-2004 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.cli; - -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Test case for the PatternOptionBuilder class - * - * @author Henri Yandell - **/ -public class PatternOptionBuilderTest -extends TestCase -{ - public static void main( String[] args ) - { - String[] testName = { PatternOptionBuilderTest.class.getName() }; - junit.textui.TestRunner.main(testName); - } - - public static TestSuite suite() - { - return new TestSuite(PatternOptionBuilderTest.class); - } - - public PatternOptionBuilderTest( String s ) - { - super( s ); - } - - public void testSimplePattern() - { - try { - Options options = PatternOptionBuilder.parsePattern("a:b@cde>f+n%t/"); - String[] args = new String[] { "-c", "-a", "foo", "-b", "java.util.Vector", "-e", "build.xml", "-f", "java.util.Calendar", "-n", "4.5", "-t", "http://jakarta.apache.org/" }; - - CommandLineParser parser = new PosixParser(); - CommandLine line = parser.parse(options,args); - - // tests the char methods of CommandLine that delegate to - // the String methods - assertEquals("flag a", "foo", line.getOptionValue("a")); - assertEquals("flag a", "foo", line.getOptionValue('a')); - assertEquals("string flag a", "foo", line.getOptionObject("a")); - assertEquals("string flag a", "foo", line.getOptionObject('a')); - assertEquals("object flag b", new java.util.Vector(), line.getOptionObject("b")); - assertEquals("object flag b", new java.util.Vector(), line.getOptionObject('b')); - assertEquals("boolean true flag c", true, line.hasOption("c")); - assertEquals("boolean true flag c", true, line.hasOption('c')); - assertEquals("boolean false flag d", false, line.hasOption("d")); - assertEquals("boolean false flag d", false, line.hasOption('d')); - assertEquals("file flag e", new java.io.File("build.xml"), line.getOptionObject("e")); - assertEquals("file flag e", new java.io.File("build.xml"), line.getOptionObject('e')); - assertEquals("class flag f", java.util.Calendar.class, line.getOptionObject("f")); - assertEquals("class flag f", java.util.Calendar.class, line.getOptionObject('f')); - assertEquals("number flag n", new Float(4.5), line.getOptionObject("n")); - assertEquals("number flag n", new Float(4.5), line.getOptionObject('n')); - assertEquals("url flag t", new java.net.URL("http://jakarta.apache.org/"), line.getOptionObject("t")); - assertEquals("url flag t", new java.net.URL("http://jakarta.apache.org/"), line.getOptionObject('t')); - /// DATES NOT SUPPORTED YET. - // assertEquals("number flag t", new java.util.Date(1023400137276L), line.getOptionObject('z')); - // input is: "Thu Jun 06 17:48:57 EDT 2002" - } - catch( ParseException exp ) { - fail( exp.getMessage() ); - } - catch( java.net.MalformedURLException exp ) { - fail( exp.getMessage() ); - } - } - -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/TestHelpFormatter.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli/TestHelpFormatter.java b/src/test/org/apache/commons/cli/TestHelpFormatter.java deleted file mode 100644 index 039efd9..0000000 --- a/src/test/org/apache/commons/cli/TestHelpFormatter.java +++ /dev/null @@ -1,176 +0,0 @@ -/** - * Copyright 2001-2004 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.cli; - -import java.io.ByteArrayOutputStream; -import java.io.PrintWriter; - -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Test case for the HelpFormatter class - * - * @author Slawek Zachcial - * @author John Keyes ( john at integralsource.com ) - **/ -public class TestHelpFormatter extends TestCase -{ - public static void main( String[] args ) - { - String[] testName = { TestHelpFormatter.class.getName() }; - junit.textui.TestRunner.main(testName); - } - - public static TestSuite suite() - { - return new TestSuite(TestHelpFormatter.class); - } - - public TestHelpFormatter( String s ) - { - super( s ); - } - - public void testFindWrapPos() - throws Exception - { - HelpFormatter hf = new HelpFormatter(); - - String text = "This is a test."; - //text width should be max 8; the wrap postition is 7 - assertEquals("wrap position", 7, hf.findWrapPos(text, 8, 0)); - //starting from 8 must give -1 - the wrap pos is after end - assertEquals("wrap position 2", -1, hf.findWrapPos(text, 8, 8)); - //if there is no a good position before width to make a wrapping look for the next one - text = "aaaa aa"; - assertEquals("wrap position 3", 4, hf.findWrapPos(text, 3, 0)); - } - - public void testPrintWrapped() - throws Exception - { - StringBuffer sb = new StringBuffer(); - HelpFormatter hf = new HelpFormatter(); - - String text = "This is a test."; - String expected; - - expected = "This is a" + hf.getNewLine() + "test."; - hf.renderWrappedText(sb, 12, 0, text); - assertEquals("single line text", expected, sb.toString()); - - sb.setLength(0); - expected = "This is a" + hf.getNewLine() + " test."; - hf.renderWrappedText(sb, 12, 4, text); - assertEquals("single line padded text", expected, sb.toString()); - - text = - "aaaa aaaa aaaa" + hf.getNewLine() + - "aaaaaa" + hf.getNewLine() + - "aaaaa"; - - expected = text; - sb.setLength(0); - hf.renderWrappedText(sb, 16, 0, text); - assertEquals("multi line text", expected, sb.toString()); - - expected = - "aaaa aaaa aaaa" + hf.getNewLine() + - " aaaaaa" + hf.getNewLine() + - " aaaaa"; - sb.setLength(0); - hf.renderWrappedText(sb, 16, 4, text); - assertEquals("multi-line padded text", expected, sb.toString()); - } - - public void testPrintOptions() - throws Exception - { - StringBuffer sb = new StringBuffer(); - HelpFormatter hf = new HelpFormatter(); - final int leftPad = 1; - final int descPad = 3; - final String lpad = hf.createPadding(leftPad); - final String dpad = hf.createPadding(descPad); - Options options = null; - String expected = null; - - options = new Options().addOption("a", false, "aaaa aaaa aaaa aaaa aaaa"); - expected = lpad + "-a" + dpad + "aaaa aaaa aaaa aaaa aaaa"; - hf.renderOptions(sb, 60, options, leftPad, descPad); - assertEquals("simple non-wrapped option", expected, sb.toString()); - - int nextLineTabStop = leftPad+descPad+"-a".length(); - expected = - lpad + "-a" + dpad + "aaaa aaaa aaaa" + hf.getNewLine() + - hf.createPadding(nextLineTabStop) + "aaaa aaaa"; - sb.setLength(0); - hf.renderOptions(sb, nextLineTabStop+17, options, leftPad, descPad); - assertEquals("simple wrapped option", expected, sb.toString()); - - - options = new Options().addOption("a", "aaa", false, "dddd dddd dddd dddd"); - expected = lpad + "-a,--aaa" + dpad + "dddd dddd dddd dddd"; - sb.setLength(0); - hf.renderOptions(sb, 60, options, leftPad, descPad); - assertEquals("long non-wrapped option", expected, sb.toString()); - - nextLineTabStop = leftPad+descPad+"-a,--aaa".length(); - expected = - lpad + "-a,--aaa" + dpad + "dddd dddd" + hf.getNewLine() + - hf.createPadding(nextLineTabStop) + "dddd dddd"; - sb.setLength(0); - hf.renderOptions(sb, 25, options, leftPad, descPad); - assertEquals("long wrapped option", expected, sb.toString()); - - options = new Options(). - addOption("a", "aaa", false, "dddd dddd dddd dddd"). - addOption("b", false, "feeee eeee eeee eeee"); - expected = - lpad + "-a,--aaa" + dpad + "dddd dddd" + hf.getNewLine() + - hf.createPadding(nextLineTabStop) + "dddd dddd" + hf.getNewLine() + - lpad + "-b " + dpad + "feeee eeee" + hf.getNewLine() + - hf.createPadding(nextLineTabStop) + "eeee eeee"; - sb.setLength(0); - hf.renderOptions(sb, 25, options, leftPad, descPad); - assertEquals("multiple wrapped options", expected, sb.toString()); - } - - public void testAutomaticUsage() - throws Exception - { - HelpFormatter hf = new HelpFormatter(); - Options options = null; - String expected = "usage: app [-a]"; - ByteArrayOutputStream out = new ByteArrayOutputStream( ); - PrintWriter pw = new PrintWriter( out ); - - options = new Options().addOption("a", false, "aaaa aaaa aaaa aaaa aaaa"); - hf.printUsage( pw, 60, "app", options ); - pw.flush(); - assertEquals("simple auto usage", expected, out.toString().trim()); - out.reset(); - - expected = "usage: app [-a] [-b]"; - options = new Options().addOption("a", false, "aaaa aaaa aaaa aaaa aaaa") - .addOption("b", false, "bbb" ); - hf.printUsage( pw, 60, "app", options ); - pw.flush(); - assertEquals("simple auto usage", expected, out.toString().trim()); - out.reset(); - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/ValueTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli/ValueTest.java b/src/test/org/apache/commons/cli/ValueTest.java deleted file mode 100644 index 98bf2bf..0000000 --- a/src/test/org/apache/commons/cli/ValueTest.java +++ /dev/null @@ -1,426 +0,0 @@ -/** - * Copyright 2001-2004 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.cli; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import java.util.Arrays; -import java.util.Properties; - -public class ValueTest extends TestCase -{ - - public static Test suite() { - return new TestSuite(ValueTest.class); - } - - private CommandLine _cl = null; - private CommandLine _clOptional = null; - private Options opts = new Options(); - - public ValueTest(String name) - { - super(name); - } - - public void setUp() - { - opts.addOption("a", - false, - "toggle -a"); - - opts.addOption("b", - true, - "set -b"); - - opts.addOption("c", - "c", - false, - "toggle -c"); - - opts.addOption("d", - "d", - true, - "set -d"); - - opts.addOption( OptionBuilder.hasOptionalArg() - .create( 'e') ); - - opts.addOption( OptionBuilder.hasOptionalArg() - .withLongOpt( "fish" ) - .create( ) ); - - opts.addOption( OptionBuilder.hasOptionalArgs() - .withLongOpt( "gravy" ) - .create( ) ); - - opts.addOption( OptionBuilder.hasOptionalArgs( 2 ) - .withLongOpt( "hide" ) - .create( ) ); - - opts.addOption( OptionBuilder.hasOptionalArgs( 2 ) - .create( 'i' ) ); - - opts.addOption( OptionBuilder.hasOptionalArgs( ) - .create( 'j' ) ); - - opts.addOption( OptionBuilder.hasArgs( ).withValueSeparator( ',' ) - .create( 'k' ) ); - - String[] args = new String[] { "-a", - "-b", "foo", - "--c", - "--d", "bar" - }; - - try - { - CommandLineParser parser = new PosixParser(); - _cl = parser.parse(opts,args); - } - catch (ParseException e) - { - fail("Cannot setUp() CommandLine: " + e.toString()); - } - } - - public void tearDown() - { - - } - - public void testShortNoArg() - { - assertTrue( _cl.hasOption("a") ); - assertNull( _cl.getOptionValue("a") ); - } - - public void testShortWithArg() - { - assertTrue( _cl.hasOption("b") ); - assertNotNull( _cl.getOptionValue("b") ); - assertEquals( _cl.getOptionValue("b"), "foo"); - } - - public void testLongNoArg() - { - assertTrue( _cl.hasOption("c") ); - assertNull( _cl.getOptionValue("c") ); - } - - public void testLongWithArg() - { - assertTrue( _cl.hasOption("d") ); - assertNotNull( _cl.getOptionValue("d") ); - assertEquals( _cl.getOptionValue("d"), "bar"); - } - - public void testShortOptionalArgNoValue() - { - String[] args = new String[] { "-e" - }; - try - { - CommandLineParser 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()); - } - } - - public void testShortOptionalArgValue() - { - String[] args = new String[] { "-e", "everything" - }; - try - { - CommandLineParser 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()); - } - } - - public void testLongOptionalNoValue() - { - String[] args = new String[] { "--fish" - }; - try - { - CommandLineParser 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()); - } - } - - public void testLongOptionalArgValue() - { - String[] args = new String[] { "--fish", "face" - }; - try - { - CommandLineParser 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()); - } - } - - public void testShortOptionalArgValues() - { - String[] args = new String[] { "-j", "ink", "idea" - }; - try - { - CommandLineParser 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()); - } - } - - public void testLongOptionalArgValues() - { - String[] args = new String[] { "--gravy", "gold", "garden" - }; - try - { - CommandLineParser 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()); - } - } - - public void testShortOptionalNArgValues() - { - String[] args = new String[] { "-i", "ink", "idea", "isotope", "ice" - }; - try - { - CommandLineParser 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()); - } - } - - public void testLongOptionalNArgValues() - { - String[] args = new String[] { - "--hide", "house", "hair", "head" - }; - - CommandLineParser 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()); - } - } - - public void testPropertyOptionSingularValue() - { - Properties properties = new Properties(); - properties.setProperty( "hide", "seek" ); - - CommandLineParser 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()); - } - } - - public void testPropertyOptionFlags() - { - Properties properties = new Properties(); - properties.setProperty( "a", "true" ); - properties.setProperty( "c", "yes" ); - properties.setProperty( "e", "1" ); - - CommandLineParser 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()); - } - - 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()); - } - - 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()); - } - - 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()); - } - - } - - public void testPropertyOptionMultipleValues() - { - Properties properties = new Properties(); - properties.setProperty( "k", "one,two" ); - - CommandLineParser parser = new PosixParser(); - - 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()); - } - } - - public void testPropertyOverrideValues() - { - String[] args = new String[] { - "-j", - "found", - "-i", - "ink" - }; - - Properties properties = new Properties(); - properties.setProperty( "j", "seek" ); - try - { - CommandLineParser 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()); - } - } - -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/ValuesTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli/ValuesTest.java b/src/test/org/apache/commons/cli/ValuesTest.java deleted file mode 100644 index c493186..0000000 --- a/src/test/org/apache/commons/cli/ValuesTest.java +++ /dev/null @@ -1,253 +0,0 @@ -/** - * Copyright 2001-2004 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.cli; - -import java.util.Arrays; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class ValuesTest extends TestCase -{ - /** CommandLine instance */ - private CommandLine _cmdline = null; - private Option _option = null; - - public static Test suite() { - return new TestSuite( ValuesTest.class ); - } - - public ValuesTest( String name ) - { - super( name ); - } - - public void setUp() - { - Options opts = new Options(); - - opts.addOption("a", - false, - "toggle -a"); - - opts.addOption("b", - true, - "set -b"); - - opts.addOption("c", - "c", - false, - "toggle -c"); - - opts.addOption("d", - "d", - true, - "set -d"); - - opts.addOption( OptionBuilder.withLongOpt( "e" ) - .hasArgs() - .withDescription( "set -e ") - .create( 'e' ) ); - - opts.addOption("f", - "f", - false, - "jk"); - - opts.addOption( OptionBuilder.withLongOpt( "g" ) - .hasArgs( 2 ) - .withDescription( "set -g") - .create( 'g' ) ); - - opts.addOption( OptionBuilder.withLongOpt( "h" ) - .hasArgs( 2 ) - .withDescription( "set -h") - .create( 'h' ) ); - - opts.addOption( OptionBuilder.withLongOpt( "i" ) - .withDescription( "set -i") - .create( 'i' ) ); - - opts.addOption( OptionBuilder.withLongOpt( "j" ) - .hasArgs( ) - .withDescription( "set -j") - .withValueSeparator( '=' ) - .create( 'j' ) ); - - opts.addOption( OptionBuilder.withLongOpt( "k" ) - .hasArgs( ) - .withDescription( "set -k") - .withValueSeparator( '=' ) - .create( 'k' ) ); - - _option = OptionBuilder.withLongOpt( "m" ) - .hasArgs( ) - .withDescription( "set -m") - .withValueSeparator( ) - .create( 'm' ); - - opts.addOption( _option ); - - String[] args = new String[] { "-a", - "-b", "foo", - "--c", - "--d", "bar", - "-e", "one", "two", - "-f", - "arg1", "arg2", - "-g", "val1", "val2" , "arg3", - "-h", "val1", "-i", - "-h", "val2", - "-jkey=value", - "-j", "key=value", - "-kkey1=value1", - "-kkey2=value2", - "-mkey=value"}; - - CommandLineParser parser = new PosixParser(); - - try - { - _cmdline = parser.parse(opts,args); - } - catch (ParseException e) - { - fail("Cannot setUp() CommandLine: " + e.toString()); - } - } - - public void tearDown() - { - - } - - public void testShortArgs() - { - assertTrue( _cmdline.hasOption("a") ); - assertTrue( _cmdline.hasOption("c") ); - - assertNull( _cmdline.getOptionValues("a") ); - assertNull( _cmdline.getOptionValues("c") ); - } - - public void testShortArgsWithValue() - { - assertTrue( _cmdline.hasOption("b") ); - assertTrue( _cmdline.getOptionValue("b").equals("foo")); - assertTrue( _cmdline.getOptionValues("b").length == 1); - - assertTrue( _cmdline.hasOption("d") ); - assertTrue( _cmdline.getOptionValue("d").equals("bar")); - assertTrue( _cmdline.getOptionValues("d").length == 1); - } - - public void testMultipleArgValues() - { - String[] result = _cmdline.getOptionValues("e"); - String[] values = new String[] { "one", "two" }; - assertTrue( _cmdline.hasOption("e") ); - assertTrue( _cmdline.getOptionValues("e").length == 2); - assertTrue( Arrays.equals( values, _cmdline.getOptionValues("e") ) ); - } - - public void testTwoArgValues() - { - String[] result = _cmdline.getOptionValues("g"); - String[] values = new String[] { "val1", "val2" }; - assertTrue( _cmdline.hasOption("g") ); - assertTrue( _cmdline.getOptionValues("g").length == 2); - assertTrue( Arrays.equals( values, _cmdline.getOptionValues("g") ) ); - } - - public void testComplexValues() - { - String[] result = _cmdline.getOptionValues("h"); - String[] values = new String[] { "val1", "val2" }; - assertTrue( _cmdline.hasOption("i") ); - assertTrue( _cmdline.hasOption("h") ); - assertTrue( _cmdline.getOptionValues("h").length == 2); - assertTrue( Arrays.equals( values, _cmdline.getOptionValues("h") ) ); - } - - public void testExtraArgs() - { - String[] args = new String[] { "arg1", "arg2", "arg3" }; - assertTrue( _cmdline.getArgs().length == 3 ); - assertTrue( Arrays.equals( args, _cmdline.getArgs() ) ); - } - - public void testCharSeparator() - { - // tests the char methods of CommandLine that delegate to - // the String methods - String[] values = new String[] { "key", "value", "key", "value" }; - assertTrue( _cmdline.hasOption( "j" ) ); - assertTrue( _cmdline.hasOption( 'j' ) ); - assertEquals( 4, _cmdline.getOptionValues( "j" ).length ); - assertEquals( 4, _cmdline.getOptionValues( 'j' ).length ); - assertTrue( Arrays.equals( values, _cmdline.getOptionValues( "j" ) ) ); - assertTrue( Arrays.equals( values, _cmdline.getOptionValues( 'j' ) ) ); - - values = new String[] { "key1", "value1", "key2", "value2" }; - assertTrue( _cmdline.hasOption( "k" ) ); - assertTrue( _cmdline.hasOption( 'k' ) ); - assertTrue( _cmdline.getOptionValues( "k" ).length == 4 ); - assertTrue( _cmdline.getOptionValues( 'k' ).length == 4 ); - assertTrue( Arrays.equals( values, _cmdline.getOptionValues( "k" ) ) ); - assertTrue( Arrays.equals( values, _cmdline.getOptionValues( 'k' ) ) ); - - values = new String[] { "key", "value" }; - assertTrue( _cmdline.hasOption( "m" ) ); - assertTrue( _cmdline.hasOption( 'm' ) ); - assertTrue( _cmdline.getOptionValues( "m" ).length == 2); - assertTrue( _cmdline.getOptionValues( 'm' ).length == 2); - assertTrue( Arrays.equals( values, _cmdline.getOptionValues( "m" ) ) ); - assertTrue( Arrays.equals( values, _cmdline.getOptionValues( 'm' ) ) ); - } - - /** - * jkeyes - commented out this test as the new architecture - * breaks this type of functionality. I have left the test - * here in case I get a brainwave on how to resolve this. - */ - /* - public void testGetValue() - { - // the 'm' option - assertTrue( _option.getValues().length == 2 ); - assertEquals( _option.getValue(), "key" ); - assertEquals( _option.getValue( 0 ), "key" ); - assertEquals( _option.getValue( 1 ), "value" ); - - try { - assertEquals( _option.getValue( 2 ), "key" ); - fail( "IndexOutOfBounds not caught" ); - } - catch( IndexOutOfBoundsException exp ) { - - } - - try { - assertEquals( _option.getValue( -1 ), "key" ); - fail( "IndexOutOfBounds not caught" ); - } - catch( IndexOutOfBoundsException exp ) { - - } - } - */ -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/bug/BugCLI18Test.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli/bug/BugCLI18Test.java b/src/test/org/apache/commons/cli/bug/BugCLI18Test.java deleted file mode 100644 index a17d745..0000000 --- a/src/test/org/apache/commons/cli/bug/BugCLI18Test.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2004 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.cli.bug; - -import org.apache.commons.cli.*; - -import java.io.PrintWriter; -import java.io.StringWriter; - -import junit.framework.TestCase; - -/** - * http://issues.apache.org/jira/browse/CLI-18 - */ -public class BugCLI18Test extends TestCase { - - public void testCLI18() { - Options options = new Options(); - options.addOption(new Option("a","aaa",false,"aaaaaaa")); - options.addOption(new Option(null,"bbb",false,"bbbbbbb dksh fkshd fkhs dkfhsdk fhskd hksdks dhfowehfsdhfkjshf skfhkshf sf jkshfk sfh skfh skf f")); - options.addOption(new Option("c",null,false,"ccccccc")); - - HelpFormatter formatter = new HelpFormatter(); - StringWriter out = new StringWriter(); - - formatter.printHelp(new PrintWriter(out),80, "foobar", "dsfkfsh kdh hsd hsdh fkshdf ksdh fskdh fsdh fkshfk sfdkjhskjh fkjh fkjsh khsdkj hfskdhf skjdfh ksf khf s", options, 2, 2, "blort j jgj j jg jhghjghjgjhgjhg jgjhgj jhg jhg hjg jgjhghjg jhg hjg jhgjg jgjhghjg jg jgjhgjgjg jhg jhgjh" + '\r' + '\n' + "rarrr", true); - } -} - http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/CLITestCase.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/CLITestCase.java b/src/test/org/apache/commons/cli2/CLITestCase.java deleted file mode 100644 index a16d15a..0000000 --- a/src/test/org/apache/commons/cli2/CLITestCase.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright 2004 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.cli2; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import junit.framework.TestCase; - -public abstract class CLITestCase extends TestCase { - - public static List list() { - return Collections.EMPTY_LIST; - } - - public static List list(final Object args[]) { - return new LinkedList(Arrays.asList(args)); - } - - public static List list(final Object arg0) { - return list(new Object[] { arg0 }); - } - - public static List list(final Object arg0, final Object arg1) { - return list(new Object[] { arg0, arg1 }); - } - - public static List list(final Object arg0, final Object arg1, final Object arg2) { - return list(new Object[] { arg0, arg1, arg2 }); - } - - public static List list(final Object arg0, final Object arg1, final Object arg2, final Object arg3) { - return list(new Object[] { arg0, arg1, arg2, arg3 }); - } - - public static List list(final Object arg0, final Object arg1, final Object arg2, final Object arg3, final Object arg4) { - return list(new Object[] { arg0, arg1, arg2, arg3, arg4 }); - } - - public static List list(final Object arg0, final Object arg1, final Object arg2, final Object arg3, final Object arg4, final Object arg5) { - return list(new Object[] { arg0, arg1, arg2, arg3, arg4, arg5 }); - } - - public static void assertListContentsEqual(final List expected, final List found) { - - final Iterator e = expected.iterator(); - final Iterator f = found.iterator(); - - while (e.hasNext() && f.hasNext()) { - assertEquals(e.next(), f.next()); - } - - if (e.hasNext()) { - fail("Expected more elements"); - } - - if (f.hasNext()) { - fail("Found more elements"); - } - } - - public static void assertContentsEqual(final Collection expected, final Collection found) { - assertTrue(expected.containsAll(found)); - assertTrue(found.containsAll(expected)); - assertEquals(expected.size(), found.size()); - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/CommandLineDefaultsTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/CommandLineDefaultsTest.java b/src/test/org/apache/commons/cli2/CommandLineDefaultsTest.java deleted file mode 100644 index a05e8d3..0000000 --- a/src/test/org/apache/commons/cli2/CommandLineDefaultsTest.java +++ /dev/null @@ -1,250 +0,0 @@ -/** - * Copyright 2004 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.cli2; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.commons.cli2.builder.ArgumentBuilder; -import org.apache.commons.cli2.builder.SwitchBuilder; -import org.apache.commons.cli2.commandline.WriteableCommandLineImpl; - -/** - * Tests the interaction of command line values and defaults supplied in different ways. - * - * Tests marked _Parsed involve values parsed from a command line. - * - * Tests marked _Method involve defaults supplied in the query method. - * - * Tests marked _Option involce defaults specified in the model. - * - * @author Rob Oxspring - */ -public class CommandLineDefaultsTest extends TestCase { - - /* - * utils to grab the default from the method - */ - - private Object methodSwitch(WriteableCommandLine cl, Option o, Boolean bool) { - return cl.getSwitch(o, bool); - } - - private Object methodSwitchNull(WriteableCommandLine cl, Option o) { - return methodSwitch(cl, o, null); - } - - private Object methodSwitchOff(WriteableCommandLine cl, Option o) { - return methodSwitch(cl, o, Boolean.FALSE); - } - - private Object methodSwitchOn(WriteableCommandLine cl, Option o) { - return methodSwitch(cl, o, Boolean.TRUE); - } - - private Object methodValueMissing(WriteableCommandLine cl, Option o) { - return cl.getValue(o); - } - - private Object methodValuePresent(WriteableCommandLine cl, Option o) { - return cl.getValue(o, "method"); - } - - /* - * utils to grab the default from the option model - */ - - private Option optionSwitch(Boolean bool) { - return new SwitchBuilder().withName("switch").withSwitchDefault(bool) - .create(); - } - - private Option optionSwitchNull() { - return optionSwitch(null); - } - - private Option optionSwitchOff() { - return optionSwitch(Boolean.FALSE); - } - - private Option optionSwitchOn() { - return optionSwitch(Boolean.TRUE); - } - - private Option optionValueMissing() { - return new ArgumentBuilder().create(); - } - - private Option optionValuePresent() { - return new ArgumentBuilder().withDefaults( - Arrays.asList(new String[] { "option" })).create(); - } - - /* - * utils to grab the input from the command line - */ - - private WriteableCommandLine parsedSwitch(Option o, Boolean bool) { - final List args; - if (bool == null) { - args = Collections.EMPTY_LIST; - } else { - args = Collections - .singletonList(String.valueOf(bool).toLowerCase()); - } - WriteableCommandLine cl = new WriteableCommandLineImpl(o, args); - o.defaults(cl); - if (bool != null) { - cl.addSwitch(o, bool.booleanValue()); - } - return cl; - } - - private WriteableCommandLine parsedSwitchNull(Option o) { - return parsedSwitch(o, null); - } - - private WriteableCommandLine parsedSwitchOn(Option o) { - return parsedSwitch(o, Boolean.TRUE); - } - - private WriteableCommandLine parsedValueMissing(Option o) { - WriteableCommandLine cl = new WriteableCommandLineImpl(o, - Collections.EMPTY_LIST); - o.defaults(cl); - return cl; - } - - private WriteableCommandLine parsedValuePresent(Option o) { - WriteableCommandLine cl = new WriteableCommandLineImpl(o, Arrays - .asList(new String[] { "parsed" })); - o.defaults(cl); - cl.addValue(o, "parsed"); - return cl; - } - - /* - * tests - */ - - public void testSwitch_Method() { - final Option o = optionSwitchNull(); - final WriteableCommandLine cl = parsedSwitchNull(o); - final Object v = methodSwitchOn(cl, o); - assertEquals(Boolean.TRUE, v); - } - - public void testSwitch_Method_Option() { - final Option o = optionSwitchOff(); - final WriteableCommandLine cl = parsedSwitchNull(o); - final Object v = methodSwitchOn(cl, o); - assertEquals(Boolean.TRUE, v); - } - - public void testSwitch_Option() { - final Option o = optionSwitchOn(); - final WriteableCommandLine cl = parsedSwitchNull(o); - final Object v = methodSwitchNull(cl, o); - assertEquals(Boolean.TRUE, v); - } - - public void testSwitch_Parsed() { - final Option o = optionSwitchNull(); - final WriteableCommandLine cl = parsedSwitchOn(o); - final Object v = methodSwitchNull(cl, o); - assertEquals(Boolean.TRUE, v); - } - - public void testSwitch_Parsed_Method() { - final Option o = optionSwitchOff(); - final WriteableCommandLine cl = parsedSwitchOn(o); - final Object v = methodSwitchNull(cl, o); - assertEquals(Boolean.TRUE, v); - } - - public void testSwitch_Parsed_Method_Option() { - final Option o = optionSwitchOff(); - final WriteableCommandLine cl = parsedSwitchOn(o); - final Object v = methodSwitchOff(cl, o); - assertEquals(Boolean.TRUE, v); - } - - public void testSwitch_Parsed_Option() { - final Option o = optionSwitchOff(); - final WriteableCommandLine cl = parsedSwitchOn(o); - final Object v = methodSwitchNull(cl, o); - assertEquals(Boolean.TRUE, v); - } - - public void testValues() { - final Option o = optionValueMissing(); - final WriteableCommandLine cl = parsedValueMissing(o); - final Object v = methodValueMissing(cl, o); - assertNull(v); - } - - public void testValues_Method() { - final Option o = optionValueMissing(); - final WriteableCommandLine cl = parsedValueMissing(o); - final Object v = methodValuePresent(cl, o); - assertEquals("method", v); - } - - public void testValues_Method_Option() { - final Option o = optionValuePresent(); - final WriteableCommandLine cl = parsedValueMissing(o); - final Object v = methodValuePresent(cl, o); - assertEquals("method", v); - } - - public void testValues_Option() { - final Option o = optionValuePresent(); - final WriteableCommandLine cl = parsedValueMissing(o); - final Object v = methodValueMissing(cl, o); - assertEquals("option", v); - } - - public void testValues_Parsed() { - final Option o = optionValueMissing(); - final WriteableCommandLine cl = parsedValuePresent(o); - final Object v = methodValueMissing(cl, o); - assertEquals("parsed", v); - } - - public void testValues_Parsed_Method() { - final Option o = optionValueMissing(); - final WriteableCommandLine cl = parsedValuePresent(o); - final Object v = methodValuePresent(cl, o); - assertEquals("parsed", v); - } - - public void testValues_Parsed_Method_Option() { - final Option o = optionValuePresent(); - final WriteableCommandLine cl = parsedValuePresent(o); - final Object v = methodValuePresent(cl, o); - assertEquals("parsed", v); - } - - public void testValues_Parsed_Option() { - final Option o = optionValuePresent(); - final WriteableCommandLine cl = parsedValuePresent(o); - final Object v = methodValueMissing(cl, o); - assertEquals("parsed", v); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/CommandLineTestCase.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/CommandLineTestCase.java b/src/test/org/apache/commons/cli2/CommandLineTestCase.java deleted file mode 100644 index 38349dc..0000000 --- a/src/test/org/apache/commons/cli2/CommandLineTestCase.java +++ /dev/null @@ -1,511 +0,0 @@ -/* - * Copyright 2003-2005 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.cli2; - -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.apache.commons.cli2.builder.ArgumentBuilder; -import org.apache.commons.cli2.builder.DefaultOptionBuilder; -import org.apache.commons.cli2.builder.GroupBuilder; -import org.apache.commons.cli2.commandline.Parser; -import org.apache.commons.cli2.option.ArgumentTest; -import org.apache.commons.cli2.option.CommandTest; -import org.apache.commons.cli2.option.DefaultOptionTest; -import org.apache.commons.cli2.option.OptionTestCase; -import org.apache.commons.cli2.option.PropertyOption; -import org.apache.commons.cli2.option.SwitchTest; -import org.apache.commons.cli2.resource.ResourceConstants; -import org.apache.commons.cli2.resource.ResourceHelper; - -public abstract class CommandLineTestCase - extends CLITestCase { - private static final ResourceHelper resources = ResourceHelper.getResourceHelper(); - public final Option present = - new DefaultOptionBuilder().withLongName("present").withLongName("alsopresent").create(); - public final Option missing = new DefaultOptionBuilder().withLongName("missing").create(); - public final Option multiple = new DefaultOptionBuilder().withLongName("multiple").create(); - public final Option bool = new DefaultOptionBuilder().withLongName("bool").create(); - public final Option root = - new GroupBuilder().withOption(present).withOption(missing).withOption(multiple) - .withOption(bool).create(); - private CommandLine commandLine; - - protected abstract CommandLine createCommandLine(); - - /* - * @see TestCase#setUp() - */ - public void setUp() - throws Exception { - super.setUp(); - commandLine = createCommandLine(); - } - - /* - * Class to test for boolean hasOption(String) - */ - public final void testHasOptionString() { - assertTrue(commandLine.hasOption("--present")); - assertTrue(commandLine.hasOption("--alsopresent")); - assertFalse(commandLine.hasOption("--missing")); - } - - /* - * Class to test for boolean hasOption(Option) - */ - public final void testHasOptionOption() { - assertTrue(commandLine.hasOption(present)); - assertFalse(commandLine.hasOption(missing)); - } - - public final void testGetOption() { - assertSame(present, commandLine.getOption("--present")); - assertSame(present, commandLine.getOption("--alsopresent")); - - //TODO decide whether the following assertion is valid - //assertSame(missing,commandLine.getOption("--missing")); - } - - /* - * Class to test for List getValues(String) - */ - public final void testGetValuesString() { - assertListContentsEqual(list("present value"), commandLine.getValues("--present")); - assertListContentsEqual(list("value 1", "value 2", "value 3"), - commandLine.getValues("--multiple")); - assertTrue(commandLine.getValues("--missing").isEmpty()); - } - - /* - * Class to test for List getValues(String, List) - */ - public final void testGetValuesStringList() { - assertListContentsEqual(list("present value"), commandLine.getValues("--present", null)); - assertListContentsEqual(list("present value"), commandLine.getValues("--alsopresent", null)); - assertSame(commandLine.getValues("--missing", Collections.EMPTY_LIST), - Collections.EMPTY_LIST); - - final List def = Collections.singletonList("default value"); - assertSame(def, commandLine.getValues("--missing", def)); - } - - /* - * Class to test for List getValues(Option) - */ - public final void testGetValuesOption() { - assertListContentsEqual(list("present value"), commandLine.getValues(present)); - assertTrue(commandLine.getValues(missing).isEmpty()); - } - - /* - * Class to test for List getValues(Option, List) - */ - public final void testGetValuesOptionList() { - assertListContentsEqual(list("present value"), commandLine.getValues(present)); - assertSame(commandLine.getValues(missing, Collections.EMPTY_LIST), Collections.EMPTY_LIST); - - final List defs = Collections.singletonList("custom default"); - assertSame(defs, commandLine.getValues(missing, defs)); - } - - /* - * Class to test for Object getValue(String) - */ - public final void testGetValueString() { - assertEquals("present value", commandLine.getValue("--present")); - assertEquals("present value", commandLine.getValue("--alsopresent")); - assertNull(commandLine.getValue("--missing")); - - try { - commandLine.getValue("--multiple"); - fail("expected IllegalStateException"); - } catch (IllegalStateException e) { - assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES), - e.getMessage()); - } - } - - /* - * Class to test for Object getValue(String, Object) - */ - public final void testGetValueStringObject() { - assertEquals("present value", commandLine.getValue("--present", "default value")); - assertEquals("present value", commandLine.getValue("--alsopresent", "default value")); - assertEquals("default value", commandLine.getValue("--missing", "default value")); - - try { - commandLine.getValue("--multiple"); - fail("expected IllegalStateException"); - } catch (IllegalStateException e) { - assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES), - e.getMessage()); - } - } - - /* - * Class to test for Object getValue(Option) - */ - public final void testGetValueOption() { - assertEquals("present value", commandLine.getValue(present)); - assertNull(commandLine.getValue(missing)); - - try { - commandLine.getValue(multiple); - fail("expected IllegalStateException"); - } catch (IllegalStateException e) { - assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES), - e.getMessage()); - } - } - - /* - * Class to test for Object getValue(Option, Object) - */ - public final void testGetValueOptionObject() { - assertEquals("present value", commandLine.getValue(present, "default value")); - assertEquals("default value", commandLine.getValue(missing, "default value")); - - try { - commandLine.getValue(multiple); - fail("expected IllegalStateException"); - } catch (IllegalStateException e) { - assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES), - e.getMessage()); - } - } - - /* - * Class to test for Boolean getSwitch(String) - */ - public final void testGetSwitchString() { - assertEquals(Boolean.TRUE, commandLine.getSwitch("--bool")); - assertNull(commandLine.getSwitch("--missing")); - } - - /* - * Class to test for Boolean getSwitch(String, Boolean) - */ - public final void testGetSwitchStringBoolean() { - assertEquals(Boolean.TRUE, commandLine.getSwitch("--bool", Boolean.FALSE)); - assertEquals(Boolean.FALSE, commandLine.getSwitch("--missing", Boolean.FALSE)); - } - - /* - * Class to test for Boolean getSwitch(Option) - */ - public final void testGetSwitchOption() { - assertEquals(Boolean.TRUE, commandLine.getSwitch(bool)); - assertNull(commandLine.getSwitch(missing)); - } - - /* - * Class to test for Boolean getSwitch(Option, Boolean) - */ - public final void testGetSwitchOptionBoolean() { - assertEquals(Boolean.TRUE, commandLine.getSwitch(bool, Boolean.FALSE)); - assertEquals(Boolean.FALSE, commandLine.getSwitch(missing, Boolean.FALSE)); - } - - /* - * Class to test for String getProperty(String) - */ - public final void testGetPropertyString() { - assertEquals("present property", commandLine.getProperty("present")); - assertNull(commandLine.getProperty("missing")); - } - - /* - * Class to test for String getProperty(String, String) - */ - public final void testGetPropertyStringString() { - assertEquals("present property", commandLine.getProperty("present", "default property")); - assertEquals("default property", commandLine.getProperty("missing", "default property")); - } - - public final void testGetProperties() { - assertTrue(commandLine.getProperties().containsAll(list("present"))); - } - - /* - * Class to test for int getOptionCount(String) - */ - public final void testGetOptionCountString() { - // one option, one switch - assertTrue(1 <= commandLine.getOptionCount("--present")); - assertTrue(1 <= commandLine.getOptionCount("--bool")); - assertEquals(0, commandLine.getOptionCount("--missing")); - } - - /* - * Class to test for int getOptionCount(Option) - */ - public final void testGetOptionCountOption() { - // one option, one switch - assertTrue(1 <= commandLine.getOptionCount(present)); - assertTrue(1 <= commandLine.getOptionCount(bool)); - assertEquals(0, commandLine.getOptionCount(missing)); - } - - public final void testGetOptions() { - //TODO Implement getOptions(). - } - - public final void testGetOptionTriggers() { - //TODO Implement getOptionTriggers(). - } - - // OLD TESTS FOLLOW - public final void testProperties() { - final Option option = new PropertyOption(); - final List args = CLITestCase.list(); - final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args); - - assertTrue(writeable.getProperties().isEmpty()); - - writeable.addProperty("myprop", "myval"); - assertEquals(1, writeable.getProperties().size()); - assertEquals("myval", writeable.getProperty("myprop")); - - writeable.addProperty("myprop", "myval2"); - assertEquals(1, writeable.getProperties().size()); - assertEquals("myval2", writeable.getProperty("myprop")); - - writeable.addProperty("myprop2", "myval3"); - assertEquals(2, writeable.getProperties().size()); - assertEquals("myval3", writeable.getProperty("myprop2")); - } - - public final void testOptions() { - final Option option = new PropertyOption(); - final List args = CLITestCase.list(); - final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args); - - final Option start = CommandTest.buildStartCommand(); - - assertFalse(writeable.hasOption(start)); - assertFalse(writeable.hasOption("start")); - assertFalse(writeable.hasOption("go")); - - writeable.addOption(start); - - assertTrue(writeable.hasOption(start)); - assertTrue(writeable.hasOption("start")); - assertTrue(writeable.hasOption("go")); - } - - public final void testValues() { - final Option option = new PropertyOption(); - final List args = CLITestCase.list(); - final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args); - - final Option start = CommandTest.buildStartCommand(); - - assertNull(writeable.getValue(start)); - assertTrue(writeable.getValues(start).isEmpty()); - - writeable.addOption(start); - - assertTrue(writeable.getValues(start).isEmpty()); - - writeable.addValue(start, "file1"); - - assertEquals("file1", writeable.getValue(start)); - assertEquals("file1", writeable.getValue("start")); - assertEquals("file1", writeable.getValue("go")); - assertEquals(1, writeable.getValues(start).size()); - assertEquals(1, writeable.getValues("start").size()); - assertEquals(1, writeable.getValues("go").size()); - assertTrue(writeable.getValues(start).contains("file1")); - assertTrue(writeable.getValues("start").contains("file1")); - assertTrue(writeable.getValues("go").contains("file1")); - - writeable.addValue(start, "file2"); - - try { - writeable.getValue(start); - fail("Cannot get single value if multiple are present"); - } catch (IllegalStateException ise) { - assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES), - ise.getMessage()); - } - - try { - writeable.getValue("start"); - fail("Cannot get single value if multiple are present"); - } catch (IllegalStateException ise) { - assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES), - ise.getMessage()); - } - - writeable.getValues(start).add("file3"); - } - - public final void testSwitches() { - final Option option = new PropertyOption(); - final List args = CLITestCase.list(); - final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args); - - final Option start = CommandTest.buildStartCommand(); - - assertNull(writeable.getSwitch(start)); - assertNull(writeable.getSwitch("start")); - assertNull(writeable.getSwitch("go")); - - writeable.addSwitch(start, true); - - try { - writeable.addSwitch(start, false); - fail("Switch cannot be changed"); - } catch (IllegalStateException ise) { - assertEquals(resources.getMessage(ResourceConstants.SWITCH_ALREADY_SET), - ise.getMessage()); - } - } - - public final void testSwitches_True() { - final Option option = new PropertyOption(); - final List args = CLITestCase.list(); - final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args); - - final Option start = CommandTest.buildStartCommand(); - - writeable.addSwitch(start, true); - assertSame(Boolean.TRUE, writeable.getSwitch(start)); - } - - public final void testSwitches_False() { - final Option option = new PropertyOption(); - final List args = CLITestCase.list(); - final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args); - - final Option start = CommandTest.buildStartCommand(); - - writeable.addSwitch(start, false); - assertSame(Boolean.FALSE, writeable.getSwitch(start)); - } - - // public final void testLooksLikeOption() { - // final Option option = new PropertyOption(); - // final List args = OptionTestCase.list(); - // final WriteableCommandLine commandLine = - // OptionTestCase.commandLine(option, args); - // - // assertTrue(commandLine.looksLikeOption("-D")); - // assertFalse(commandLine.looksLikeOption("--help")); - // assertFalse(commandLine.looksLikeOption("+display")); - // assertFalse(commandLine.looksLikeOption("myprefix")); - // assertFalse(commandLine.looksLikeOption("myprefix2")); - // assertFalse(commandLine.looksLikeOption("myprefference")); - // assertFalse(commandLine.looksLikeOption("/SCANDISK")); - // assertFalse(commandLine.looksLikeOption("update")); - // } - public final void testGetOptions_Order() - throws OptionException { - final Option help = DefaultOptionTest.buildHelpOption(); - final Option login = CommandTest.buildLoginCommand(); - final Option targets = ArgumentTest.buildTargetsArgument(); - - final Group group = - new GroupBuilder().withOption(help).withOption(login).withOption(targets).create(); - - final Parser parser = new Parser(); - parser.setGroup(group); - - final CommandLine cl = - parser.parse(new String[] { "login", "rob", "--help", "target1", "target2" }); - - final Iterator i = cl.getOptions().iterator(); - - assertSame(login, i.next()); - assertSame(help, i.next()); - assertSame(targets, i.next()); - assertSame(targets, i.next()); - assertFalse(i.hasNext()); - } - - public final void testGetOptionCount() - throws OptionException { - final Option help = DefaultOptionTest.buildHelpOption(); - final Option login = CommandTest.buildLoginCommand(); - final Option targets = ArgumentTest.buildTargetsArgument(); - final Option display = SwitchTest.buildDisplaySwitch(); - - final Group group = - new GroupBuilder().withOption(help).withOption(login).withOption(targets) - .withOption(display).create(); - - final Parser parser = new Parser(); - parser.setGroup(group); - - final CommandLine cl = - parser.parse(new String[] { - "--help", "login", "rob", "+display", "--help", "--help", "target1", - "target2" - }); - - assertEquals(1, cl.getOptionCount(login)); - assertEquals(3, cl.getOptionCount(help)); - assertEquals(2, cl.getOptionCount(targets)); - assertEquals(1, cl.getOptionCount(display)); - } - - public final void testGetOptionCount_Strings() - throws OptionException { - final Option help = DefaultOptionTest.buildHelpOption(); - final Option login = CommandTest.buildLoginCommand(); - final Option targets = ArgumentTest.buildTargetsArgument(); - final Option display = SwitchTest.buildDisplaySwitch(); - - final Group group = - new GroupBuilder().withOption(help).withOption(login).withOption(targets) - .withOption(display).create(); - - final Parser parser = new Parser(); - parser.setGroup(group); - - final CommandLine cl = - parser.parse(new String[] { - "--help", "login", "rob", "+display", "--help", "--help", "target1", - "target2" - }); - - assertEquals(1, cl.getOptionCount("login")); - assertEquals(3, cl.getOptionCount("-?")); - assertEquals(1, cl.getOptionCount("+display")); - } - - public final void testOptionAsArgument() - throws OptionException { - final Option p = new DefaultOptionBuilder().withShortName("p").create(); - final Argument argument = new ArgumentBuilder().create(); - final Option withArgument = - new DefaultOptionBuilder().withShortName("attr").withArgument(argument).create(); - - final Group group = new GroupBuilder().withOption(p).withOption(withArgument).create(); - - final Parser parser = new Parser(); - parser.setGroup(group); - - final CommandLine cl = parser.parse(new String[] { "-p", "-attr", "p" }); - - assertEquals(1, cl.getOptionCount("-p")); - assertTrue(cl.hasOption("-p")); - assertTrue(cl.hasOption("-attr")); - assertTrue(cl.getValue("-attr").equals("p")); - } -}
