Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 86959 invoked from network); 30 May 2008 14:11:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 30 May 2008 14:11:58 -0000 Received: (qmail 65046 invoked by uid 500); 30 May 2008 14:11:59 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 64976 invoked by uid 500); 30 May 2008 14:11:59 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 64967 invoked by uid 99); 30 May 2008 14:11:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 May 2008 07:11:59 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 May 2008 14:11:11 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3494E2388A0F; Fri, 30 May 2008 07:11:33 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r661726 - /commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionTest.java Date: Fri, 30 May 2008 14:11:33 -0000 To: commits@commons.apache.org From: ebourg@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080530141133.3494E2388A0F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ebourg Date: Fri May 30 07:11:32 2008 New Revision: 661726 URL: http://svn.apache.org/viewvc?rev=661726&view=rev Log: More tests for the Option class covering the hasArgs, hasArgName and getValue methods Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionTest.java Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionTest.java URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionTest.java?rev=661726&r1=661725&r2=661726&view=diff ============================================================================== --- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionTest.java (original) +++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionTest.java Fri May 30 07:11:32 2008 @@ -22,29 +22,35 @@ /** * @author brianegge */ -public class OptionTest extends TestCase { - - private static class TestOption extends Option { - public TestOption(String opt, boolean hasArg, String description) throws IllegalArgumentException { +public class OptionTest extends TestCase +{ + private static class TestOption extends Option + { + public TestOption(String opt, boolean hasArg, String description) throws IllegalArgumentException + { super(opt, hasArg, description); } - public boolean addValue(String value) { + + public boolean addValue(String value) + { addValueForProcessing(value); return true; } - } + } - public void testClear() { - TestOption option = new TestOption("x", true, ""); - assertEquals(0, option.getValuesList().size()); - option.addValue("a"); - assertEquals(1, option.getValuesList().size()); - option.clearValues(); - assertEquals(0, option.getValuesList().size()); - } + public void testClear() + { + TestOption option = new TestOption("x", true, ""); + assertEquals(0, option.getValuesList().size()); + option.addValue("a"); + assertEquals(1, option.getValuesList().size()); + option.clearValues(); + assertEquals(0, option.getValuesList().size()); + } // See http://issues.apache.org/jira/browse/CLI-21 - public void testClone() throws CloneNotSupportedException { + public void testClone() throws CloneNotSupportedException + { TestOption a = new TestOption("a", true, ""); TestOption b = (TestOption) a.clone(); assertEquals(a, b); @@ -59,25 +65,76 @@ assertEquals(2, b.getValues().length); } - private static class DefaultOption extends Option { - + private static class DefaultOption extends Option + { private final String defaultValue; - public DefaultOption(String opt, String description, String defaultValue) throws IllegalArgumentException { + public DefaultOption(String opt, String description, String defaultValue) throws IllegalArgumentException + { super(opt, true, description); this.defaultValue = defaultValue; } - public String getValue() { + public String getValue() + { return super.getValue() != null ? super.getValue() : defaultValue; } } - public void testSubclass() throws CloneNotSupportedException { + public void testSubclass() throws CloneNotSupportedException + { Option option = new DefaultOption("f", "file", "myfile.txt"); Option clone = (Option) option.clone(); assertEquals("myfile.txt", clone.getValue()); assertEquals(DefaultOption.class, clone.getClass()); } + public void testHasArgName() + { + Option option = new Option("f", null); + + option.setArgName(null); + assertFalse(option.hasArgName()); + + option.setArgName(""); + assertFalse(option.hasArgName()); + + option.setArgName("file"); + assertTrue(option.hasArgName()); + } + + public void testHasArgs() + { + Option option = new Option("f", null); + + option.setArgs(0); + assertFalse(option.hasArgs()); + + option.setArgs(1); + assertFalse(option.hasArgs()); + + option.setArgs(10); + assertTrue(option.hasArgs()); + + option.setArgs(Option.UNLIMITED_VALUES); + assertTrue(option.hasArgs()); + + option.setArgs(Option.UNINITIALIZED); + assertFalse(option.hasArgs()); + } + + public void testGetValue() + { + Option option = new Option("f", null); + option.setArgs(Option.UNLIMITED_VALUES); + + assertEquals("default", option.getValue("default")); + assertEquals(null, option.getValue(0)); + + option.addValueForProcessing("foo"); + + assertEquals("foo", option.getValue()); + assertEquals("foo", option.getValue(0)); + assertEquals("foo", option.getValue("default")); + } }