commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r639943 [12/17] - in /commons/proper/cli/trunk/src: java/org/apache/commons/cli2/ java/org/apache/commons/cli2/builder/ java/org/apache/commons/cli2/commandline/ java/org/apache/commons/cli2/option/ java/org/apache/commons/cli2/resource/ ja...
Date Sat, 22 Mar 2008 03:08:35 GMT
Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/builder/DefaultOptionBuilderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/builder/DefaultOptionBuilderTest.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/builder/DefaultOptionBuilderTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/builder/DefaultOptionBuilderTest.java Fri Mar 21 20:08:23 2008
@@ -1 +1,200 @@
-/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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;im
 port 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, Str
 ing, 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 Def
 aultOptionBuilder("-", "", 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.withChildr
 en(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());    }}
\ No newline at end of file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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());
+    }
+}

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java Fri Mar 21 20:08:23 2008
@@ -1 +1,151 @@
-/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.ap
 ache.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.addSwit
 ch(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.hasNe
 xt());        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 Defaulting
 CommandLine();        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));    }}
\ No newline at end of file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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));
+    }
+}

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/ParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/ParserTest.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/ParserTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/ParserTest.java Fri Mar 21 20:08:23 2008
@@ -1 +1,140 @@
-/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.io.BufferedReader;import java.io.IOException;import java.io.PrintWriter;import java.io.StringReader;import java.io.StringWriter;import org.apache.c
 ommons.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());            assertEqua
 ls("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()));    }}
\ No newline at end of file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.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()));
+    }
+}

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java Fri Mar 21 20:08:23 2008
@@ -1 +1,106 @@
-/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.Com
 mandLineTestCase;/** * @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","presen
 t 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("--mu
 ltiple"));        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());    }}
\ No newline at end of file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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());
+    }
+}

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java Fri Mar 21 20:08:23 2008
@@ -1 +1,101 @@
-/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.CommandLin
 eTestCase;/** * @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 te
 stPropertyValues() {        // 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("--alsopresen
 t"));    	assertFalse("should not find null option", cmdline.hasOption((String) null));    	assertTrue("expected a true", cmdline.getSwitch("--bool").booleanValue());    }}
\ No newline at end of file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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());
+    }
+}

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/WriteableCommandLineImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/WriteableCommandLineImplTest.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/WriteableCommandLineImplTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/WriteableCommandLineImplTest.java Fri Mar 21 20:08:23 2008
@@ -1 +1,36 @@
-/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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 Writeab
 leCommandLineImplTest    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    }}
\ No newline at end of file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+    }
+}

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/jdepend/JDependTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/jdepend/JDependTest.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/jdepend/JDependTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/jdepend/JDependTest.java Fri Mar 21 20:08:23 2008
@@ -1 +1,109 @@
-/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.framew
 ork.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;    }}
\ No newline at end of file
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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;
+    }
+}



Mime
View raw message