http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/bug/Bug13886Test.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/bug/Bug13886Test.java b/src/test/org/apache/commons/cli2/bug/Bug13886Test.java deleted file mode 100644 index 8742cf0..0000000 --- a/src/test/org/apache/commons/cli2/bug/Bug13886Test.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright 2003-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.bug; - -import junit.framework.TestCase; - -import org.apache.commons.cli2.Group; -import org.apache.commons.cli2.Option; -import org.apache.commons.cli2.OptionException; -import org.apache.commons.cli2.builder.DefaultOptionBuilder; -import org.apache.commons.cli2.builder.GroupBuilder; -import org.apache.commons.cli2.commandline.Parser; - -/** - * @author John Keyes - */ -public class Bug13886Test extends TestCase { - - public Bug13886Test(final String name) { - super(name); - } - - public void testMandatoryGroup() throws Exception { - final DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); - final GroupBuilder gbuilder = new GroupBuilder(); - - final Option a = obuilder.withShortName("a").create(); - - final Option b = obuilder.withShortName("b").create(); - - final Group options = - gbuilder - .withOption(a) - .withOption(b) - .withMaximum(1) - .withMinimum(1) - .create(); - - final Parser parser = new Parser(); - parser.setGroup(options); - - try { - parser.parse(new String[] { - }); - fail("Expected MissingOptionException not caught"); - } - catch (final OptionException exp) { - assertEquals("Missing option -a|-b", exp.getMessage()); - } - - try { - parser.parse(new String[] { "-a" }); - } - catch (final OptionException exp) { - fail("Unexpected MissingOptionException caught"); - } - - try { - parser.parse(new String[] { "-b" }); - } - catch (final OptionException exp) { - fail("Unexpected MissingOptionException caught"); - } - - try { - parser.parse(new String[] { "-a", "-b" }); - fail("Expected UnexpectedOptionException not caught"); - } - catch (final OptionException exp) { - assertEquals( - "Unexpected -b while processing -a|-b", - exp.getMessage()); - } - } -}
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/bug/Bug13935Test.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/bug/Bug13935Test.java b/src/test/org/apache/commons/cli2/bug/Bug13935Test.java deleted file mode 100644 index 6600ad4..0000000 --- a/src/test/org/apache/commons/cli2/bug/Bug13935Test.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2003-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.bug; - -import junit.framework.TestCase; - -import org.apache.commons.cli2.CommandLine; -import org.apache.commons.cli2.Group; -import org.apache.commons.cli2.Option; -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; - -/** - * @author John Keyes - */ -public class Bug13935Test extends TestCase { - - public Bug13935Test(final String name) { - super(name); - } - - public void testRequiredGroup() throws Exception { - final DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); - final ArgumentBuilder abuilder = new ArgumentBuilder(); - final GroupBuilder gbuilder = new GroupBuilder(); - - final Option testOption = - obuilder - .withShortName("a") - .withArgument(abuilder.withName("quoted string").create()) - .create(); - - final Group options = gbuilder.withOption(testOption).create(); - - final Parser parser = new Parser(); - parser.setGroup(options); - - final CommandLine cmdLine = - parser.parse(new String[] { "-a", "\"two tokens\"" }); - - assertTrue(cmdLine.hasOption("-a")); - assertEquals("two tokens", cmdLine.getValue("-a")); - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/bug/Bug15046Test.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/bug/Bug15046Test.java b/src/test/org/apache/commons/cli2/bug/Bug15046Test.java deleted file mode 100644 index 60a6dc3..0000000 --- a/src/test/org/apache/commons/cli2/bug/Bug15046Test.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright 2003-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.bug; - -import junit.framework.TestCase; - -import org.apache.commons.cli2.CommandLine; -import org.apache.commons.cli2.Group; -import org.apache.commons.cli2.Option; -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; - -/** - * @author John Keyes - */ -public class Bug15046Test extends TestCase { - - public Bug15046Test(String name) { - super(name); - } - - public void testParamNamedAsOption() throws Exception { - final String[] CLI_ARGS = new String[] { "-z", "c" }; - - DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); - ArgumentBuilder abuilder = new ArgumentBuilder(); - - Option option = - obuilder - .withShortName("z") - .withLongName("timezone") - .withDescription("affected option") - .withArgument(abuilder.withName("timezone").create()) - .create(); - - GroupBuilder gbuilder = new GroupBuilder(); - Group options = - gbuilder.withName("bug15046").withOption(option).create(); - - Parser parser = new Parser(); - parser.setGroup(options); - CommandLine line = parser.parse(CLI_ARGS); - - assertEquals("c", line.getValue("-z")); - - Option c = - obuilder - .withShortName("c") - .withLongName("conflict") - .withDescription("conflicting option") - .withArgument(abuilder.withName("conflict").create()) - .create(); - - options = - gbuilder - .withName("bug15046") - .withOption(option) - .withOption(c) - .create(); - - parser.setGroup(options); - line = parser.parse(CLI_ARGS); - - assertEquals("c", line.getValue("-z")); - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/bug/Bug15648Test.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/bug/Bug15648Test.java b/src/test/org/apache/commons/cli2/bug/Bug15648Test.java deleted file mode 100644 index 44f9157..0000000 --- a/src/test/org/apache/commons/cli2/bug/Bug15648Test.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2003-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.bug; - -import junit.framework.TestCase; - -import org.apache.commons.cli2.CommandLine; -import org.apache.commons.cli2.Group; -import org.apache.commons.cli2.Option; -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; - -/** - * @author John Keyes - */ -public class Bug15648Test extends TestCase { - - public Bug15648Test(final String name) { - super(name); - } - - public void testQuotedArgumentValue() throws Exception { - final DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); - final ArgumentBuilder abuilder = new ArgumentBuilder(); - final GroupBuilder gbuilder = new GroupBuilder(); - - final Option testOption = - obuilder - .withShortName("a") - .withArgument(abuilder.withName("quoted string").create()) - .create(); - - final Group options = gbuilder.withOption(testOption).create(); - - final Parser parser = new Parser(); - parser.setGroup(options); - - final CommandLine cmdLine = - parser.parse(new String[] { "-a", "\"two tokens\"" }); - - assertTrue(cmdLine.hasOption("-a")); - assertEquals("two tokens", cmdLine.getValue("-a")); - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/bug/Bug27575Test.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/bug/Bug27575Test.java b/src/test/org/apache/commons/cli2/bug/Bug27575Test.java deleted file mode 100644 index 4bc611b..0000000 --- a/src/test/org/apache/commons/cli2/bug/Bug27575Test.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright 2003-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.bug; - -import java.util.Iterator; - -import junit.framework.TestCase; - -import org.apache.commons.cli2.Option; -import org.apache.commons.cli2.builder.PatternBuilder; -import org.apache.commons.cli2.option.GroupImpl; - -public class Bug27575Test extends TestCase { - - public void testRequiredOptions(){ - PatternBuilder builder = new PatternBuilder(); - builder.withPattern("hc!<"); - Option option = builder.create(); - assertTrue(option instanceof GroupImpl); - - GroupImpl group = (GroupImpl)option; - Iterator i = group.getOptions().iterator(); - assertEquals("[-h]",i.next().toString()); - assertEquals("-c <arg>",i.next().toString()); - assertFalse(i.hasNext()); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/bug/Bug28005Test.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/bug/Bug28005Test.java b/src/test/org/apache/commons/cli2/bug/Bug28005Test.java deleted file mode 100644 index aecbf48..0000000 --- a/src/test/org/apache/commons/cli2/bug/Bug28005Test.java +++ /dev/null @@ -1,78 +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.bug; - -import org.apache.commons.cli2.Argument; -import org.apache.commons.cli2.Group; -import org.apache.commons.cli2.Option; -import org.apache.commons.cli2.OptionException; -import org.apache.commons.cli2.builder.ArgumentBuilder; -import org.apache.commons.cli2.builder.CommandBuilder; -import org.apache.commons.cli2.builder.DefaultOptionBuilder; -import org.apache.commons.cli2.builder.GroupBuilder; -import org.apache.commons.cli2.commandline.Parser; -import junit.framework.TestCase; - -public class Bug28005Test extends TestCase { - public void testInfiniteLoop() { - final DefaultOptionBuilder optionBuilder = new DefaultOptionBuilder(); - final ArgumentBuilder argumentBuilder = new ArgumentBuilder(); - final GroupBuilder groupBuilder = new GroupBuilder(); - final CommandBuilder commandBuilder = new CommandBuilder(); - - final Option inputFormatOption = - optionBuilder - .withLongName("input-format") - //.withArgument(argumentBuilder.create()) - .create(); - - final Argument argument = - argumentBuilder - .withName("file") - .create(); - - final Group children = - groupBuilder - .withName("options") - .withOption(inputFormatOption) - .create(); - - final Option command = - commandBuilder - .withName("convert") - .withChildren(children) - .withArgument(argument) - .create(); - - final Group root = - groupBuilder - .withName("commands") - .withOption(command) - .create(); - - final Parser parser = new Parser(); - parser.setGroup(root); - final String[] args = new String[]{"convert", "test.txt", - "--input-format", "a"}; - - try { - parser.parse(args); - fail("a isn't valid!!"); - } catch (OptionException e) { - assertEquals("Unexpected a while processing commands",e.getMessage()); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/bug/Bug32533Test.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/bug/Bug32533Test.java b/src/test/org/apache/commons/cli2/bug/Bug32533Test.java deleted file mode 100644 index c9f94e5..0000000 --- a/src/test/org/apache/commons/cli2/bug/Bug32533Test.java +++ /dev/null @@ -1,47 +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.bug; - -import org.apache.commons.cli2.Group; -import org.apache.commons.cli2.Option; -import org.apache.commons.cli2.OptionException; -import org.apache.commons.cli2.builder.DefaultOptionBuilder; -import org.apache.commons.cli2.builder.GroupBuilder; -import org.apache.commons.cli2.commandline.Parser; - -import junit.framework.TestCase; - -/** - * @author roxspring - */ -public class Bug32533Test extends TestCase { - - public void testBlah() throws OptionException { - - Option a1 = new DefaultOptionBuilder().withLongName("a1").create(); - Option b1 = new DefaultOptionBuilder().withLongName("b1").create(); - Option c1 = new DefaultOptionBuilder().withLongName("c1").create(); - - Group b = new GroupBuilder().withOption(b1).create(); - Group c = new GroupBuilder().withOption(c1).create(); - Group a = new GroupBuilder().withOption(a1).withOption(b).withOption(c).create(); - - Parser parser = new Parser(); - parser.setGroup(a); - parser.parse(new String[]{"--a1","--b1"}); - } - -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/bug/BugCLI18Test.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/bug/BugCLI18Test.java b/src/test/org/apache/commons/cli2/bug/BugCLI18Test.java deleted file mode 100644 index 224780d..0000000 --- a/src/test/org/apache/commons/cli2/bug/BugCLI18Test.java +++ /dev/null @@ -1,59 +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.bug; - -import java.io.PrintWriter; -import java.io.StringWriter; - -import org.apache.commons.cli2.Group; -import org.apache.commons.cli2.Option; -import org.apache.commons.cli2.builder.DefaultOptionBuilder; -import org.apache.commons.cli2.builder.GroupBuilder; -import org.apache.commons.cli2.util.HelpFormatter; - -import junit.framework.TestCase; - -/** - * http://issues.apache.org/jira/browse/CLI-18 - */ -public class BugCLI18Test extends TestCase { - - public BugCLI18Test() { - super(); - } - - - public void testBug() { - Option a = new DefaultOptionBuilder().withLongName("aaa").withShortName("a").withDescription("aaaaaaa").create(); - Option b = new DefaultOptionBuilder().withLongName("bbb").withDescription("bbbbbbbb dksh fkshd fkhs dkfhsdk fhskd hksdks dhfowehfsdhfkjshf skfhkshf sf jkshfk sfh skfh skf f").create(); - Option c = new DefaultOptionBuilder().withLongName("ccc").withShortName("c").withDescription("ccccccc").create(); - - Group g = new GroupBuilder().withOption(a).withOption(b).withOption(c).create(); - - HelpFormatter formatter = new HelpFormatter(); - StringWriter out = new StringWriter(); - - formatter.setPrintWriter(new PrintWriter(out)); - formatter.setHeader("dsfkfsh kdh hsd hsdh fkshdf ksdh fskdh fsdh fkshfk sfdkjhskjh fkjh fkjsh khsdkj hfskdhf skjdfh ksf khf s"); - formatter.setFooter("blort j jgj j jg jhghjghjgjhgjhg jgjhgj jhg jhg hjg jgjhghjg jhg hjg jhgjg jgjhghjg jg jgjhgjgjg jhg jhgjh" + '\r' + '\n' + "rarrr"); - formatter.setGroup(g); - formatter.setShellCommand("foobar"); - - formatter.print(); - - } -} - http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/bug/BugLoopingOptionLookAlikeTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/bug/BugLoopingOptionLookAlikeTest.java b/src/test/org/apache/commons/cli2/bug/BugLoopingOptionLookAlikeTest.java deleted file mode 100644 index e95ba3d..0000000 --- a/src/test/org/apache/commons/cli2/bug/BugLoopingOptionLookAlikeTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright 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.bug; - -import junit.framework.TestCase; - -import org.apache.commons.cli2.Argument; -import org.apache.commons.cli2.Group; -import org.apache.commons.cli2.OptionException; -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.SourceDestArgument; - -/** - * The first is a loop in Parser.parse() if I set a non-declared option. This - * code goes into a loop in Parser.java method parse this �while� loop runs - * endless - * - * @author Steve Alberty - */ -public class BugLoopingOptionLookAlikeTest extends TestCase { - - public void testLoopingOptionLookAlike() { - final DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); - final ArgumentBuilder abuilder = new ArgumentBuilder(); - final GroupBuilder gbuilder = new GroupBuilder(); - final Group options = gbuilder - .withName("ant") - .withOption(obuilder.withShortName("help").withDescription("print this message").create()) - .withOption(obuilder.withShortName("projecthelp").withDescription("print project help information").create()) - .withOption(abuilder.withName("target").create()) - .create(); - - final Parser parser = new Parser(); - parser.setGroup(options); - try { - parser.parse(new String[] { "-abcdef", - "testfile.txt ", }); - fail("OptionException"); - } catch (OptionException e) { - assertEquals("Unexpected -abcdef while processing ant",e.getMessage()); - } - } - - public void testLoopingOptionLookAlike2() { - final ArgumentBuilder abuilder = new ArgumentBuilder(); - final GroupBuilder gbuilder = new GroupBuilder(); - final Argument inputfile_opt = abuilder.withName("input").withMinimum(1).withMaximum(1).create(); - final Argument outputfile_opt = abuilder.withName("output").withMinimum(1).withMaximum(1).create(); - final Argument targets = new SourceDestArgument(inputfile_opt, outputfile_opt); - final Group options = gbuilder.withOption(targets).create(); - final Parser parser = new Parser(); - parser.setGroup(options); - try { - parser.parse(new String[] { "testfile.txt", "testfile.txt", "testfile.txt", "testfile.txt" }); - fail("OptionException"); - } catch (OptionException e) { - assertEquals("Unexpected testfile.txt while processing ", e.getMessage()); - } - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/builder/ArgumentBuilderTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/builder/ArgumentBuilderTest.java b/src/test/org/apache/commons/cli2/builder/ArgumentBuilderTest.java deleted file mode 100644 index 74eb46c..0000000 --- a/src/test/org/apache/commons/cli2/builder/ArgumentBuilderTest.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright 2004-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.builder; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.commons.cli2.option.ArgumentImpl; -import org.apache.commons.cli2.resource.ResourceConstants; -import org.apache.commons.cli2.resource.ResourceHelper; -import org.apache.commons.cli2.validation.DateValidator; -import org.apache.commons.cli2.validation.Validator; - -public class ArgumentBuilderTest - extends TestCase { - private static final ResourceHelper resources = ResourceHelper.getResourceHelper(); - private ArgumentBuilder argumentBuilder; - - /* - * @see TestCase#setUp() - */ - protected void setUp() - throws Exception { - this.argumentBuilder = new ArgumentBuilder(); - } - - public void testConsumeRemaining() { - this.argumentBuilder.withConsumeRemaining("--"); - this.argumentBuilder.withName("arg"); - - ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create(); - - assertEquals("incorrect consume remaining token", "--", arg.getConsumeRemaining()); - } - - public void testNullConsumeRemaining() { - try { - this.argumentBuilder.withConsumeRemaining(null); - fail("cannot use null consume remaining token"); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_CONSUME_REMAINING), - exp.getMessage()); - } - } - - public void testEmptyConsumeRemaining() { - try { - this.argumentBuilder.withConsumeRemaining(""); - fail("cannot use empty string consume remaining token"); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_EMPTY_CONSUME_REMAINING), - exp.getMessage()); - } - } - - public void testDefault() { - this.argumentBuilder.withDefault("defaultString"); - this.argumentBuilder.withName("arg"); - - ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create(); - - assertEquals("incorrect number of default values", 1, arg.getDefaultValues().size()); - assertEquals("incorrect default value", "defaultString", arg.getDefaultValues().get(0)); - } - - public void testDefaultX2() { - this.argumentBuilder.withDefault("defaultString1"); - this.argumentBuilder.withDefault("defaultString2"); - this.argumentBuilder.withName("arg"); - - ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create(); - - assertEquals("incorrect number of default values", 2, arg.getDefaultValues().size()); - assertEquals("incorrect default value-1", "defaultString1", arg.getDefaultValues().get(0)); - assertEquals("incorrect default value-2", "defaultString2", arg.getDefaultValues().get(1)); - } - - public void testNullDefault() { - try { - this.argumentBuilder.withDefault(null); - fail("cannot use null default"); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_DEFAULT), - exp.getMessage()); - } - } - - public void testDefaults() { - final List defaults = new ArrayList(); - defaults.add("one"); - defaults.add("two"); - - this.argumentBuilder.withDefaults(defaults); - this.argumentBuilder.withName("arg"); - - ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create(); - - assertEquals("incorrect number of default values", 2, arg.getDefaultValues().size()); - assertEquals("incorrect default value-1", "one", arg.getDefaultValues().get(0)); - assertEquals("incorrect default value-2", "two", arg.getDefaultValues().get(1)); - assertEquals("incorrect default values list", defaults, arg.getDefaultValues()); - - } - - public void testNullDefaults() { - try { - this.argumentBuilder.withDefaults(null); - fail("cannot use null defaults"); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_DEFAULTS), - exp.getMessage()); - } - } - - public void testId() { - this.argumentBuilder.withId(1); - this.argumentBuilder.withName("arg"); - - ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create(); - - assertEquals("incorrect id", 1, arg.getId()); - } - - public void testInitialSeparator() { - this.argumentBuilder.withInitialSeparator(','); - this.argumentBuilder.withName("arg"); - - ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create(); - - assertEquals("incorrect initial separator", ',', arg.getInitialSeparator()); - } - - public void testMaximum() { - this.argumentBuilder.withMaximum(1); - this.argumentBuilder.withName("arg"); - - ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create(); - - assertEquals("incorrect maximum", 1, arg.getMaximum()); - } - - public void testNegativeMaximum() { - try { - this.argumentBuilder.withMaximum(-1); - fail("cannot use negative maximum"); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NEGATIVE_MAXIMUM), - exp.getMessage()); - } - } - - public void testMinimum() { - this.argumentBuilder.withMinimum(1); - this.argumentBuilder.withName("arg"); - - ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create(); - - assertEquals("incorrect maximum", 1, arg.getMinimum()); - } - - public void testNegativeMinimum() { - try { - this.argumentBuilder.withMinimum(-1); - fail("cannot use negative minimum"); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NEGATIVE_MINIMUM), - exp.getMessage()); - } - } - - public void testName() { - this.argumentBuilder.withName("arg"); - - ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create(); - - assertEquals("incorrect preferred name", "arg", arg.getPreferredName()); - } - - public void testNullName() { - try { - this.argumentBuilder.withName(null); - fail("cannot use null name"); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_NAME), - exp.getMessage()); - } - } - - public void testEmptyName() { - try { - this.argumentBuilder.withName(""); - fail("cannot use empty name"); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_EMPTY_NAME), - exp.getMessage()); - } - } - - public void testSubsequentSeparator() { - this.argumentBuilder.withSubsequentSeparator(':'); - this.argumentBuilder.withName("arg"); - - ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create(); - - assertEquals("incorrect subsequent separator", ':', arg.getSubsequentSeparator()); - } - - public void testValidator() { - Validator validator = DateValidator.getDateInstance(); - this.argumentBuilder.withValidator(validator); - this.argumentBuilder.withName("arg"); - - ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create(); - - assertEquals("incorrect validator", validator, arg.getValidator()); - } - - public void testNullValidator() { - try { - this.argumentBuilder.withValidator(null); - fail("cannot use null validator"); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_VALIDATOR), - exp.getMessage()); - } - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/builder/DefaultOptionBuilderTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/builder/DefaultOptionBuilderTest.java b/src/test/org/apache/commons/cli2/builder/DefaultOptionBuilderTest.java deleted file mode 100644 index 0c7bd5e..0000000 --- a/src/test/org/apache/commons/cli2/builder/DefaultOptionBuilderTest.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2004-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.builder; - -import junit.framework.TestCase; - -import org.apache.commons.cli2.Argument; -import org.apache.commons.cli2.Group; -import org.apache.commons.cli2.option.DefaultOption; -import org.apache.commons.cli2.resource.ResourceConstants; -import org.apache.commons.cli2.resource.ResourceHelper; - -public class DefaultOptionBuilderTest - extends TestCase { - private static final ResourceHelper resources = ResourceHelper.getResourceHelper(); - private DefaultOptionBuilder defaultOptionBuilder; - - /* - * @see TestCase#setUp() - */ - protected void setUp() - throws Exception { - this.defaultOptionBuilder = new DefaultOptionBuilder(); - } - - /* - * Class to test for void DefaultOptionBuilder(String, String, boolean) - */ - public void testNew_NullShortPrefix() { - try { - new DefaultOptionBuilder(null, null, false); - fail("null short prefix is not permitted"); - } catch (IllegalArgumentException e) { - assertEquals(resources.getMessage(ResourceConstants.OPTION_ILLEGAL_SHORT_PREFIX), - e.getMessage()); - } - } - - /* - * Class to test for void DefaultOptionBuilder(String, String, boolean) - */ - public void testNew_EmptyShortPrefix() { - try { - new DefaultOptionBuilder("", null, false); - fail("empty short prefix is not permitted"); - } catch (IllegalArgumentException e) { - assertEquals(resources.getMessage(ResourceConstants.OPTION_ILLEGAL_SHORT_PREFIX), - e.getMessage()); - } - } - - /* - * Class to test for void DefaultOptionBuilder(String, String, boolean) - */ - public void testNew_NullLongPrefix() { - try { - new DefaultOptionBuilder("-", null, false); - fail("null long prefix is not permitted"); - } catch (IllegalArgumentException e) { - assertEquals(resources.getMessage(ResourceConstants.OPTION_ILLEGAL_LONG_PREFIX), - e.getMessage()); - } - } - - /* - * Class to test for void DefaultOptionBuilder(String, String, boolean) - */ - public void testNew_EmptyLongPrefix() { - try { - new DefaultOptionBuilder("-", "", false); - fail("empty long prefix is not permitted"); - } catch (IllegalArgumentException e) { - assertEquals(resources.getMessage(ResourceConstants.OPTION_ILLEGAL_LONG_PREFIX), - e.getMessage()); - } - } - - public void testCreate() { - try { - this.defaultOptionBuilder.create(); - fail("options must have a name"); - } catch (IllegalStateException e) { - assertEquals(resources.getMessage(ResourceConstants.OPTION_NO_NAME), e.getMessage()); - } - - this.defaultOptionBuilder.withShortName("j"); - this.defaultOptionBuilder.create(); - this.defaultOptionBuilder.withLongName("jkeyes"); - this.defaultOptionBuilder.create(); - - { - DefaultOptionBuilder builder = new DefaultOptionBuilder("-", "--", true); - builder.withShortName("mx"); - } - } - - public void testName() { - // withLongName && this.preferred != null - { - this.defaultOptionBuilder.withShortName("a"); - this.defaultOptionBuilder.withLongName("apples"); - } - // withShortName && this.preferred != null - { - this.defaultOptionBuilder.withLongName("apples"); - this.defaultOptionBuilder.withShortName("a"); - } - // withShortName && this.preferred != null - { - this.defaultOptionBuilder.withLongName("apples"); - this.defaultOptionBuilder.withShortName("a"); - } - } - - public void testWithDescription() { - String description = "desc"; - this.defaultOptionBuilder.withShortName("a"); - this.defaultOptionBuilder.withDescription(description); - - DefaultOption opt = this.defaultOptionBuilder.create(); - assertEquals("wrong description found", description, opt.getDescription()); - } - - public void testWithRequired() { - { - boolean required = false; - this.defaultOptionBuilder.withShortName("a"); - this.defaultOptionBuilder.withRequired(required); - - DefaultOption opt = this.defaultOptionBuilder.create(); - assertEquals("wrong required found", required, opt.isRequired()); - } - - { - boolean required = true; - this.defaultOptionBuilder.withShortName("a"); - this.defaultOptionBuilder.withRequired(required); - - DefaultOption opt = this.defaultOptionBuilder.create(); - assertEquals("wrong required found", required, opt.isRequired()); - } - } - - public void testWithChildren() { - GroupBuilder gbuilder = new GroupBuilder(); - - this.defaultOptionBuilder.withShortName("a"); - this.defaultOptionBuilder.withRequired(true); - - DefaultOption opt = this.defaultOptionBuilder.create(); - - Group group = gbuilder.withName("withchildren").withOption(opt).create(); - - { - this.defaultOptionBuilder.withShortName("b"); - this.defaultOptionBuilder.withChildren(group); - - DefaultOption option = this.defaultOptionBuilder.create(); - assertEquals("wrong children found", group, option.getChildren()); - } - } - - public void testWithArgument() { - ArgumentBuilder abuilder = new ArgumentBuilder(); - abuilder.withName("myarg"); - - Argument arg = abuilder.create(); - - this.defaultOptionBuilder.withShortName("a"); - this.defaultOptionBuilder.withRequired(true); - this.defaultOptionBuilder.withArgument(arg); - - DefaultOption opt = this.defaultOptionBuilder.create(); - - assertEquals("wrong argument found", arg, opt.getArgument()); - } - - public void testWithId() { - this.defaultOptionBuilder.withShortName("a"); - this.defaultOptionBuilder.withId(0); - - DefaultOption opt = this.defaultOptionBuilder.create(); - - assertEquals("wrong id found", 0, opt.getId()); - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java b/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java deleted file mode 100644 index 6125ee7..0000000 --- a/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 2004-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.commandline; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.Set; - -import org.apache.commons.cli2.CommandLine; -import org.apache.commons.cli2.CommandLineTestCase; -import org.apache.commons.cli2.Option; -import org.apache.commons.cli2.WriteableCommandLine; -import org.apache.commons.cli2.builder.DefaultOptionBuilder; - -/** - * @author Rob Oxspring - */ -public class DefaultingCommandLineTest - extends CommandLineTestCase { - private CommandLine first; - private CommandLine second; - private Option inFirst = new DefaultOptionBuilder().withLongName("infirst").create(); - private Option inBoth = new DefaultOptionBuilder().withLongName("inboth").create(); - private Option inSecond = new DefaultOptionBuilder().withLongName("insecond").create(); - - /* (non-Javadoc) - * @see org.apache.commons.cli2.CommandLineTest#createCommandLine() - */ - protected final CommandLine createCommandLine() { - final WriteableCommandLine writeable = new WriteableCommandLineImpl(root, new ArrayList()); - writeable.addOption(present); - writeable.addProperty("present", "present property"); - writeable.addSwitch(bool, true); - writeable.addValue(present, "present value"); - writeable.addOption(multiple); - writeable.addValue(multiple, "value 1"); - writeable.addValue(multiple, "value 2"); - writeable.addValue(multiple, "value 3"); - - final DefaultingCommandLine defaults = new DefaultingCommandLine(); - defaults.appendCommandLine(writeable); - - return defaults; - } - - public void setUp() - throws Exception { - super.setUp(); - - WriteableCommandLine writeable; - - writeable = new WriteableCommandLineImpl(root, new ArrayList()); - writeable.addOption(inFirst); - writeable.addOption(inBoth); - writeable.addProperty("infirst", "infirst first value"); - writeable.addProperty("inboth", "inboth first value"); - writeable.addSwitch(inFirst, true); - writeable.addSwitch(inBoth, true); - writeable.addValue(inFirst, "infirst first value 1"); - writeable.addValue(inFirst, "infirst first value 2"); - writeable.addValue(inBoth, "inboth first value 1"); - writeable.addValue(inBoth, "inboth first value 2"); - first = writeable; - - writeable = new WriteableCommandLineImpl(root, new ArrayList()); - writeable.addOption(inSecond); - writeable.addOption(inBoth); - writeable.addProperty("insecond", "insecond second value"); - writeable.addProperty("inboth", "inboth second value"); - writeable.addSwitch(inSecond, true); - writeable.addSwitch(inBoth, true); - writeable.addValue(inSecond, "insecond second value 1"); - writeable.addValue(inSecond, "insecond second value 2"); - writeable.addValue(inBoth, "inboth second value 1"); - writeable.addValue(inBoth, "inboth second value 2"); - second = writeable; - } - - public final void testAppendCommandLine() { - final DefaultingCommandLine defaults = new DefaultingCommandLine(); - Iterator i; - - i = defaults.commandLines(); - assertFalse(i.hasNext()); - - defaults.appendCommandLine(first); - i = defaults.commandLines(); - assertSame(first, i.next()); - assertFalse(i.hasNext()); - - defaults.appendCommandLine(second); - i = defaults.commandLines(); - assertSame(first, i.next()); - assertSame(second, i.next()); - assertFalse(i.hasNext()); - } - - public final void testInsertCommandLine() { - final DefaultingCommandLine defaults = new DefaultingCommandLine(); - Iterator i; - - i = defaults.commandLines(); - assertFalse(i.hasNext()); - - defaults.insertCommandLine(0, first); - i = defaults.commandLines(); - assertSame(first, i.next()); - assertFalse(i.hasNext()); - - defaults.insertCommandLine(0, second); - i = defaults.commandLines(); - assertSame(second, i.next()); - assertSame(first, i.next()); - assertFalse(i.hasNext()); - } - - public void testTriggers() { - final DefaultingCommandLine defaults = new DefaultingCommandLine(); - defaults.appendCommandLine(first); - defaults.appendCommandLine(second); - - Set set = defaults.getOptionTriggers(); - Iterator iter = set.iterator(); - assertEquals("wrong # of triggers", 3, set.size()); - assertTrue("cannot find trigger", set.contains("--insecond")); - assertTrue("cannot find trigger", set.contains("--inboth")); - assertTrue("cannot find trigger", set.contains("--infirst")); - } - - public void testDefaults() { - final DefaultingCommandLine defaults = new DefaultingCommandLine(); - - assertEquals("wrong # of defaults", 0, defaults.getValues("--insecond").size()); - assertEquals("wrong Set of defaults", Collections.EMPTY_LIST, defaults.getValues("--insecond", null)); - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/commandline/ParserTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/commandline/ParserTest.java b/src/test/org/apache/commons/cli2/commandline/ParserTest.java deleted file mode 100644 index 096a919..0000000 --- a/src/test/org/apache/commons/cli2/commandline/ParserTest.java +++ /dev/null @@ -1,124 +0,0 @@ -package org.apache.commons.cli2.commandline; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringReader; -import java.io.StringWriter; - -import org.apache.commons.cli2.CommandLine; -import org.apache.commons.cli2.Group; -import org.apache.commons.cli2.OptionException; -import org.apache.commons.cli2.builder.DefaultOptionBuilder; -import org.apache.commons.cli2.builder.GroupBuilder; -import org.apache.commons.cli2.option.DefaultOption; -import org.apache.commons.cli2.util.HelpFormatter; - -import junit.framework.TestCase; - -public class ParserTest extends TestCase { - - private Parser parser; - private DefaultOption verboseOption; - private DefaultOption helpOption; - private Group options; - private HelpFormatter helpFormatter; - private StringWriter out; - private BufferedReader in; - - public void setUp() { - parser = new Parser(); - - final GroupBuilder gBuilder = new GroupBuilder(); - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - - helpOption = oBuilder.withLongName("help").withShortName("h").create(); - verboseOption = oBuilder.withLongName("verbose").withShortName("v").create(); - options = gBuilder.withOption(helpOption).withOption(verboseOption).create(); - parser.setGroup(options); - - helpFormatter = new HelpFormatter(); - out = new StringWriter(); - helpFormatter.setPrintWriter(new PrintWriter(out)); - parser.setHelpFormatter(helpFormatter); - } - - public void testParse_Successful() throws OptionException { - final CommandLine cl = parser.parse(new String[]{"-hv"}); - - assertTrue(cl.hasOption(helpOption)); - assertTrue(cl.hasOption(verboseOption)); - - assertEquals("--help --verbose",cl.toString()); - - final WriteableCommandLineImpl wcli = (WriteableCommandLineImpl)cl; - assertEquals("[--help, --verbose]",wcli.getNormalised().toString()); - } - - public void testParse_WithUnexpectedOption() { - try { - parser.parse(new String[]{"--unexpected"}); - fail("OptionException"); - } - catch(OptionException e) { - assertEquals(options,e.getOption()); - assertEquals("Unexpected --unexpected while processing --help|--verbose",e.getMessage()); - } - } - - public void testParseAndHelp_Successful() throws IOException { - final CommandLine cl = parser.parseAndHelp(new String[]{"-v"}); - - assertTrue(cl.hasOption(verboseOption)); - assertEquals("",out.getBuffer().toString()); - } - - public void testParseAndHelp_ByHelpOption() throws IOException { - parser.setHelpOption(helpOption); - - assertNull(parser.parseAndHelp(new String[]{"-hv"})); - - inReader(); - assertInReaderUsage(); - assertInReaderEOF(); - } - - public void testParseAndHelp_ByHelpTrigger() throws IOException { - parser.setHelpTrigger("--help"); - - assertNull(parser.parseAndHelp(new String[]{"-hv"})); - - inReader(); - assertInReaderUsage(); - assertInReaderEOF(); - } - - public void testParseAndHelp_WithUnexpectedOption() throws IOException { - assertNull(parser.parseAndHelp(new String[]{"--unexpected"})); - - inReader(); - assertInReaderLine("Unexpected --unexpected while processing --help|--verbose"); - assertInReaderUsage(); - assertInReaderEOF(); - } - - private void assertInReaderUsage() throws IOException { - assertInReaderLine("Usage:"); - assertInReaderLine("[--help --verbose]"); - assertInReaderLine("--help|--verbose"); - assertInReaderLine("--help (-h)"); - assertInReaderLine("--verbose (-v)"); - } - - private void assertInReaderLine(final String string) throws IOException { - assertEquals(string,in.readLine().trim()); - } - - private void assertInReaderEOF() throws IOException { - assertNull(in.readLine()); - } - - private void inReader() { - in = new BufferedReader(new StringReader(out.getBuffer().toString())); - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java b/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java deleted file mode 100644 index d77c598..0000000 --- a/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2004-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.commandline; - -import java.util.Iterator; -import java.util.Set; -import java.util.prefs.Preferences; - -import org.apache.commons.cli2.CommandLine; -import org.apache.commons.cli2.CommandLineTestCase; - -/** - * @author Rob Oxspring - */ -public class PreferencesCommandLineTest extends CommandLineTestCase { - - /* (non-Javadoc) - * @see org.apache.commons.cli2.CommandLineTest#createCommandLine() - */ - protected CommandLine createCommandLine() { - // TODO Auto-generated method stub - final Preferences props = Preferences.userNodeForPackage(PreferencesCommandLineTest.class); - props.put("--present","present value"); - props.put("--alsopresent",""); - props.put("--multiple","value 1|value 2|value 3"); - props.put("--bool","true"); - - props.put("present","present property"); - - return new PreferencesCommandLine(root,props,'|'); - } - - protected CommandLine createCommandLineNoSep() { - // TODO Auto-generated method stub - final Preferences props = Preferences.userNodeForPackage(PreferencesCommandLineTest.class); - props.put("--present","present value"); - props.put("--alsopresent",""); - props.put("--multiple","value 1|value 2|value 3"); - props.put("--bool","false"); - - props.put("present","present property"); - - return new PreferencesCommandLine(root,props); - } - - public void testPropertyValues() { - // nothing to test - CommandLine cmdline = createCommandLine(); - - assertEquals("wrong value", "present value", cmdline.getValue("--present")); - assertEquals("wrong value", "present value", cmdline.getValue("--alsopresent")); - assertEquals("wrong # of values", 3, cmdline.getValues("--multiple").size()); - assertEquals("wrong value 1", "value 1", cmdline.getValues("--multiple").get(0)); - assertEquals("wrong value 2", "value 2", cmdline.getValues("--multiple").get(1)); - assertEquals("wrong value 3", "value 3", cmdline.getValues("--multiple").get(2)); - } - - public void testNoSeparator() { - // nothing to test - CommandLine cmdline = createCommandLineNoSep(); - - assertEquals("wrong value", "present value", cmdline.getValue("--present")); - assertEquals("wrong value", "present value", cmdline.getValue("--alsopresent")); - assertEquals("wrong # of values", 1, cmdline.getValues("--multiple").size()); - assertEquals("wrong value", "value 1|value 2|value 3", cmdline.getValue("--multiple")); - assertFalse("expected a false", cmdline.getSwitch("--bool").booleanValue()); - } - - public void testNullOption() { - // nothing to test - CommandLine cmdline = createCommandLine(); - - assertFalse("should not find null option", cmdline.hasOption((String) null)); - assertTrue("expected a true", cmdline.getSwitch("--bool").booleanValue()); - } - - public void testPreferenceTriggers() { - // nothing to test - CommandLine cmdline = createCommandLine(); - - Set triggers = cmdline.getOptionTriggers(); - Iterator iter = triggers.iterator(); - assertEquals("wrong # of triggers", 4, triggers.size()); - assertTrue("cannot find trigger", triggers.contains("--bool")); - assertTrue("cannot find trigger", triggers.contains("--present")); - assertTrue("cannot find trigger", triggers.contains("--multiple")); - assertTrue("cannot find trigger", triggers.contains("--alsopresent")); - - assertFalse("should not find null option", cmdline.hasOption((String) null)); - assertTrue("expected a true", cmdline.getSwitch("--bool").booleanValue()); - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java b/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java deleted file mode 100644 index 4cec1c4..0000000 --- a/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2004-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.commandline; - -import java.util.Iterator; -import java.util.Properties; -import java.util.Set; - -import org.apache.commons.cli2.CommandLine; -import org.apache.commons.cli2.CommandLineTestCase; - -/** - * @author Rob Oxspring - */ -public class PropertiesCommandLineTest - extends CommandLineTestCase { - private Properties props = null; - - protected CommandLine createCommandLine() { - props = new Properties(); - props.setProperty("--present", "present value"); - props.setProperty("--alsopresent", ""); - props.setProperty("--multiple", "value 1|value 2|value 3"); - props.setProperty("--bool", "true"); - - props.setProperty("present", "present property"); - return new PropertiesCommandLine(root, props, '|'); - } - - protected CommandLine createCommandLineNoSep() { - props = new Properties(); - props.setProperty("--present", "present value"); - props.setProperty("--alsopresent", ""); - props.setProperty("--multiple", "value 1|value 2|value 3"); - props.setProperty("--bool", "false"); - - props.setProperty("present", "present property"); - return new PropertiesCommandLine(root, props); - } - - public void testPropertyValues() { - // nothing to test - CommandLine cmdline = createCommandLine(); - - assertEquals("wrong value", "present value", cmdline.getValue("--present")); - assertEquals("wrong value", "present value", cmdline.getValue("--alsopresent")); - assertEquals("wrong # of values", 3, cmdline.getValues("--multiple").size()); - assertEquals("wrong value 1", "value 1", cmdline.getValues("--multiple").get(0)); - assertEquals("wrong value 2", "value 2", cmdline.getValues("--multiple").get(1)); - assertEquals("wrong value 3", "value 3", cmdline.getValues("--multiple").get(2)); - } - - public void testNoSeparator() { - // nothing to test - CommandLine cmdline = createCommandLineNoSep(); - - assertEquals("wrong value", "present value", cmdline.getValue("--present")); - assertEquals("wrong value", "present value", cmdline.getValue("--alsopresent")); - assertEquals("wrong # of values", 1, cmdline.getValues("--multiple").size()); - assertEquals("wrong value", "value 1|value 2|value 3", cmdline.getValue("--multiple")); - assertFalse("expected a false", cmdline.getSwitch("--bool").booleanValue()); - } - - public void testNullOption() { - // nothing to test - CommandLine cmdline = createCommandLine(); - - assertFalse("should not find null option", cmdline.hasOption((String) null)); - assertTrue("expected a true", cmdline.getSwitch("--bool").booleanValue()); - } - - public void testPropertyTriggers() { - // nothing to test - CommandLine cmdline = createCommandLine(); - - Set triggers = cmdline.getOptionTriggers(); - Iterator iter = triggers.iterator(); - assertEquals("wrong # of triggers", 4, triggers.size()); - assertTrue("cannot find trigger", triggers.contains("--bool")); - assertTrue("cannot find trigger", triggers.contains("--present")); - assertTrue("cannot find trigger", triggers.contains("--multiple")); - assertTrue("cannot find trigger", triggers.contains("--alsopresent")); - - assertFalse("should not find null option", cmdline.hasOption((String) null)); - assertTrue("expected a true", cmdline.getSwitch("--bool").booleanValue()); - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/commandline/WriteableCommandLineImplTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/commandline/WriteableCommandLineImplTest.java b/src/test/org/apache/commons/cli2/commandline/WriteableCommandLineImplTest.java deleted file mode 100644 index 7fafe03..0000000 --- a/src/test/org/apache/commons/cli2/commandline/WriteableCommandLineImplTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2004-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.commandline; - -import java.util.ArrayList; - -import org.apache.commons.cli2.WriteableCommandLine; -import org.apache.commons.cli2.WriteableCommandLineTestCase; - -public class WriteableCommandLineImplTest - extends WriteableCommandLineTestCase { - /* (non-Javadoc) - * @see org.apache.commons.cli2.WriteableCommandLineTest#createWriteableCommandLine() - */ - protected WriteableCommandLine createWriteableCommandLine() { - return new WriteableCommandLineImpl(root, new ArrayList()); - } - - public void testToMakeEclipseSpotTheTestCase() { - // nothing to test - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/jdepend/JDependTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/jdepend/JDependTest.java b/src/test/org/apache/commons/cli2/jdepend/JDependTest.java deleted file mode 100644 index 6550c69..0000000 --- a/src/test/org/apache/commons/cli2/jdepend/JDependTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright 2003-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.jdepend; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; - -import jdepend.framework.JDepend; -import jdepend.framework.JavaPackage; -import junit.framework.TestCase; - -/** - * @author Rob Oxspring - */ -public class JDependTest extends TestCase { - - private JDepend dependancies = null; - - public void setUp() throws IOException { - dependancies = new JDepend(); - dependancies.addDirectory("target/classes"); - dependancies.analyze(); - } - - public void testJUnitNotPresent() { - // if junit dependancy is found then jdepend has been poluted - // with test classes and all tests are meaningless - assertNull( - "JUnit dependancy found", - dependancies.getPackage("junit.framework")); - - // the same applies to jdepend - assertNull( - "JDepend dependancy found", - dependancies.getPackage("jdepend.framework")); - } - - public void testAcceptableDistance() { - Collection packages = dependancies.getPackages(); - // only interested in cli2 - packages = cli2Packages(packages); - // resources is well off the line - packages = - namedPackages(packages, "org.apache.commons.cli2.resource", false); - - for (final Iterator i = packages.iterator(); i.hasNext();) { - final JavaPackage pkg = (JavaPackage)i.next(); - final float distance = pkg.distance(); - final String message = pkg.getName() + " too far from line: " + distance; - assertTrue( - message, - distance < 0.21d); - } - } - - public void testNoCyclesPresent() { - assertEquals("Cycles exist", false, dependancies.containsCycles()); - } - - public void testApiIndependance() { - dependancies.analyze(); - - final JavaPackage apiPackage = - dependancies.getPackage("org.apache.commons.cli2"); - final Collection dependsUpon = cli2Packages(apiPackage.getEfferents()); - - assertEquals("Api should depend on one package", 1, dependsUpon.size()); - - JavaPackage pkg = (JavaPackage) dependsUpon.iterator().next(); - assertEquals( - "Wrong package name", - "org.apache.commons.cli2.resource", - pkg.getName()); - } - - private Collection cli2Packages(final Collection incoming) { - return namedPackages(incoming, "org.apache.commons.cli2", true); - } - - private Collection namedPackages( - final Collection incoming, - final String name, - final boolean include) { - final Collection outgoing = new ArrayList(); - for (final Iterator i = incoming.iterator(); i.hasNext();) { - final JavaPackage pkg = (JavaPackage)i.next(); - if (include ^ !pkg.getName().startsWith(name)) { - outgoing.add(pkg); - } - } - return outgoing; - } -}
