Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 12563 invoked from network); 22 Mar 2008 02:51:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Mar 2008 02:51:11 -0000 Received: (qmail 47370 invoked by uid 500); 22 Mar 2008 02:50:54 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 47157 invoked by uid 500); 22 Mar 2008 02:50:53 -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 47054 invoked by uid 99); 22 Mar 2008 02:50:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Mar 2008 19:50:52 -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.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Mar 2008 02:50:19 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BEF4E1A9876; Fri, 21 Mar 2008 19:49:58 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r639941 [15/17] - in /commons/proper/cli/trunk: ./ src/java/org/apache/commons/cli2/ src/java/org/apache/commons/cli2/builder/ src/java/org/apache/commons/cli2/commandline/ src/java/org/apache/commons/cli2/option/ src/java/org/apache/common... Date: Sat, 22 Mar 2008 02:49:46 -0000 To: commits@commons.apache.org From: bayard@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080322024958.BEF4E1A9876@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ParentTest.java URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ParentTest.java?rev=639941&r1=639940&r2=639941&view=diff ============================================================================== --- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ParentTest.java (original) +++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ParentTest.java Fri Mar 21 19:49:41 2008 @@ -1,419 +1 @@ -/** - * 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.option; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Set; - -import org.apache.commons.cli2.Argument; -import org.apache.commons.cli2.DisplaySetting; -import org.apache.commons.cli2.Group; -import org.apache.commons.cli2.HelpLine; -import org.apache.commons.cli2.Option; -import org.apache.commons.cli2.OptionException; -import org.apache.commons.cli2.Parent; -import org.apache.commons.cli2.WriteableCommandLine; -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.WriteableCommandLineImpl; -import org.apache.commons.cli2.resource.ResourceConstants; -import org.apache.commons.cli2.resource.ResourceHelper; - -/** - * @author Rob Oxspring - */ -public class ParentTest - extends ParentTestCase { - public static final Argument COMPLEX_ARGUMENT = - new ArgumentBuilder().withName("username").withMinimum(1).withMaximum(1).create(); - public static final Option COMPLEX_CHILD_SSL = - new DefaultOptionBuilder().withLongName("ssl").withShortName("s").create(); - public static final Option COMPLEX_CHILD_BASIC = - new DefaultOptionBuilder().withLongName("basic").withShortName("b").create(); - public static final Option COMPLEX_CHILD_DIGEST = - new DefaultOptionBuilder().withLongName("digest").withShortName("d").create(); - public static final Group COMPLEX_CHILDREN = - new GroupBuilder().withName("login-opts").withOption(COMPLEX_CHILD_BASIC) - .withOption(COMPLEX_CHILD_DIGEST).withOption(COMPLEX_CHILD_SSL).create(); - - public static Parent buildLibParent() { - final Argument argument = ArgumentTest.buildPathArgument(); - - return new DefaultOption("-", "--", false, "--lib", "Specifies library search path", null, - null, false, argument, null, 'l'); - } - - public static Parent buildKParent() { - final Group children = GroupTest.buildApacheCommandGroup(); - - return new DefaultOption("-", "--", false, "-k", "desc", null, null, false, null, children, - 'k'); - } - - public static Parent buildComplexParent() { - return new CommandBuilder().withName("login").withName("lo").withName("l") - .withArgument(COMPLEX_ARGUMENT).withChildren(COMPLEX_CHILDREN) - .create(); - } - - /* (non-Javadoc) - * @see org.apache.commons.cli2.ParentTestCase#testProcessParent() - */ - public void testProcessParent() - throws OptionException { - final Parent option = buildKParent(); - final List args = list("-k", "start"); - final WriteableCommandLine commandLine = commandLine(option, args); - final ListIterator iterator = args.listIterator(); - option.processParent(commandLine, iterator); - - assertEquals("start", iterator.next()); - assertFalse(iterator.hasNext()); - assertTrue(commandLine.hasOption(option)); - assertTrue(commandLine.hasOption("-k")); - assertTrue(commandLine.getValues(option).isEmpty()); - } - - /* (non-Javadoc) - * @see org.apache.commons.cli2.OptionTestCase#testCanProcess() - */ - public void testCanProcess() { - final Parent option = buildKParent(); - assertTrue(option.canProcess(new WriteableCommandLineImpl(option, null), "-k")); - } - - public void testCanProcess_BadMatch() { - final Parent option = buildKParent(); - assertFalse(option.canProcess(new WriteableCommandLineImpl(option, null), "-K")); - } - - public void testCanProcess_ContractedArgument() { - final Parent option = buildLibParent(); - assertTrue(option.canProcess(new WriteableCommandLineImpl(option, null), "--lib=/usr/lib")); - } - - /* (non-Javadoc) - * @see org.apache.commons.cli2.OptionTestCase#testPrefixes() - */ - public void testPrefixes() { - final Parent option = buildKParent(); - assertContentsEqual(list("-", "--"), option.getPrefixes()); - } - - /* (non-Javadoc) - * @see org.apache.commons.cli2.OptionTestCase#testProcess() - */ - public void testProcess() - throws OptionException { - final Parent option = CommandTest.buildStartCommand(); - final List args = list("start"); - final WriteableCommandLine commandLine = commandLine(option, args); - final ListIterator iterator = args.listIterator(); - option.process(commandLine, iterator); - - assertFalse(iterator.hasNext()); - assertTrue(commandLine.hasOption(option)); - assertTrue(commandLine.hasOption("start")); - assertFalse(commandLine.hasOption("stop")); - assertTrue(commandLine.getValues(option).isEmpty()); - } - - public void testProcess_NoMatch() - throws OptionException { - final Parent option = CommandTest.buildStartCommand(); - final List args = list("whatever"); - final WriteableCommandLine commandLine = commandLine(option, args); - final ListIterator iterator = args.listIterator(); - - try { - option.process(commandLine, iterator); - fail("unexpected token not thrown"); - } catch (OptionException exp) { - OptionException e = - new OptionException(option, ResourceConstants.UNEXPECTED_TOKEN, "whatever"); - assertEquals("wrong exception message", e.getMessage(), exp.getMessage()); - } - } - - public void testProcess_Children() - throws OptionException { - final Parent option = buildKParent(); - final List args = list("-k", "start"); - final WriteableCommandLine commandLine = commandLine(option, args); - final ListIterator iterator = args.listIterator(); - option.process(commandLine, iterator); - - assertNull(option.findOption("whatever")); - assertNotNull(option.findOption("start")); - - assertFalse(iterator.hasNext()); - assertTrue(commandLine.hasOption(option)); - assertTrue(commandLine.hasOption("-k")); - assertTrue(commandLine.hasOption("start")); - assertFalse(commandLine.hasOption("stop")); - assertTrue(commandLine.getValues(option).isEmpty()); - } - - public void testProcess_Argument() - throws OptionException { - final Parent option = buildLibParent(); - final List args = list("--lib=C:\\WINDOWS;C:\\WINNT;C:\\"); - final WriteableCommandLine commandLine = commandLine(option, args); - final ListIterator iterator = args.listIterator(); - option.process(commandLine, iterator); - - assertFalse(iterator.hasNext()); - assertTrue(commandLine.hasOption(option)); - assertTrue(commandLine.hasOption("--lib")); - assertContentsEqual(list("C:\\WINDOWS", "C:\\WINNT", "C:\\"), commandLine.getValues(option)); - } - - /* (non-Javadoc) - * @see org.apache.commons.cli2.OptionTestCase#testTriggers() - */ - public void testTriggers() { - final Parent option = buildKParent(); - assertContentsEqual(list("-k"), option.getTriggers()); - } - - /* (non-Javadoc) - * @see org.apache.commons.cli2.OptionTestCase#testValidate() - */ - public void testValidate() - throws OptionException { - final Parent option = CommandTest.buildStartCommand(); - final WriteableCommandLine commandLine = commandLine(option, list()); - - option.validate(commandLine); - - commandLine.addOption(option); - - option.validate(commandLine); - } - - public void testValidate_Children() - throws OptionException { - final Parent option = buildKParent(); - final WriteableCommandLine commandLine = commandLine(option, list()); - - option.validate(commandLine); - commandLine.addOption(option); - - try { - option.validate(commandLine); - fail("Missing a command"); - } catch (OptionException moe) { - assertNotNull(moe.getOption()); - assertNotSame(option, moe.getOption()); - } - } - - public void testValidate_Argument() - throws OptionException { - final Command option = CommandTest.buildLoginCommand(); - final WriteableCommandLine commandLine = commandLine(option, list()); - - option.validate(commandLine); - - commandLine.addOption(option); - - try { - option.validate(commandLine); - fail("Missing a value"); - } catch (OptionException moe) { - assertSame(option, moe.getOption()); - } - } - - /* (non-Javadoc) - * @see org.apache.commons.cli2.OptionTestCase#testAppendUsage() - */ - public void testAppendUsage() { - final Option option = buildComplexParent(); - final StringBuffer buffer = new StringBuffer(); - final Set settings = new HashSet(DisplaySetting.ALL); - settings.remove(DisplaySetting.DISPLAY_GROUP_OUTER); - option.appendUsage(buffer, settings, null); - - assertEquals("[login (l,lo) [login-opts (--basic (-b)|--digest (-d)|--ssl (-s))]]", - buffer.toString()); - } - - public void testAppendUsage_NoArguments() { - final Option option = buildComplexParent(); - final StringBuffer buffer = new StringBuffer(); - final Set settings = new HashSet(DisplaySetting.ALL); - settings.remove(DisplaySetting.DISPLAY_PARENT_ARGUMENT); - settings.remove(DisplaySetting.DISPLAY_GROUP_OUTER); - option.appendUsage(buffer, settings, null); - - assertEquals("[login (l,lo) [login-opts (--basic (-b)|--digest (-d)|--ssl (-s))]]", - buffer.toString()); - } - - public void testAppendUsage_NoChildren() { - final Option option = buildComplexParent(); - final StringBuffer buffer = new StringBuffer(); - final Set settings = new HashSet(DisplaySetting.ALL); - settings.remove(DisplaySetting.DISPLAY_PARENT_CHILDREN); - option.appendUsage(buffer, settings, null); - - assertEquals("[login (l,lo) ]", buffer.toString()); - } - - public void testAppendUsage_NoArgumentsOrChildren() { - final Option option = buildComplexParent(); - final StringBuffer buffer = new StringBuffer(); - final Set settings = new HashSet(DisplaySetting.ALL); - settings.remove(DisplaySetting.DISPLAY_PARENT_CHILDREN); - settings.remove(DisplaySetting.DISPLAY_PARENT_ARGUMENT); - option.appendUsage(buffer, settings, null); - - assertEquals("[login (l,lo)]", buffer.toString()); - } - - /* (non-Javadoc) - * @see org.apache.commons.cli2.OptionTestCase#testGetPreferredName() - */ - public void testGetPreferredName() { - final Option option = buildLibParent(); - assertEquals("--lib", option.getPreferredName()); - } - - /* (non-Javadoc) - * @see org.apache.commons.cli2.OptionTestCase#testGetDescription() - */ - public void testGetDescription() { - final Option option = buildLibParent(); - assertEquals("Specifies library search path", option.getDescription()); - } - - /* (non-Javadoc) - * @see org.apache.commons.cli2.OptionTestCase#testHelpLines() - */ - public void testHelpLines() { - final Option option = buildComplexParent(); - final List lines = option.helpLines(0, DisplaySetting.ALL, null); - final Iterator i = lines.iterator(); - - final HelpLine line1 = (HelpLine) i.next(); - assertEquals(0, line1.getIndent()); - assertEquals(option, line1.getOption()); - - final HelpLine line2 = (HelpLine) i.next(); - assertEquals(1, line2.getIndent()); - assertEquals(COMPLEX_ARGUMENT, line2.getOption()); - - final HelpLine line3 = (HelpLine) i.next(); - assertEquals(1, line3.getIndent()); - assertEquals(COMPLEX_CHILDREN, line3.getOption()); - - final HelpLine line4 = (HelpLine) i.next(); - assertEquals(2, line4.getIndent()); - assertEquals(COMPLEX_CHILD_BASIC, line4.getOption()); - - final HelpLine line5 = (HelpLine) i.next(); - assertEquals(2, line5.getIndent()); - assertEquals(COMPLEX_CHILD_DIGEST, line5.getOption()); - - final HelpLine line6 = (HelpLine) i.next(); - assertEquals(2, line6.getIndent()); - assertEquals(COMPLEX_CHILD_SSL, line6.getOption()); - - assertFalse(i.hasNext()); - } - - public void testHelpLines_NoArgument() { - final Option option = buildComplexParent(); - final Set settings = new HashSet(DisplaySetting.ALL); - settings.remove(DisplaySetting.DISPLAY_PARENT_ARGUMENT); - - final List lines = option.helpLines(0, settings, null); - final Iterator i = lines.iterator(); - - final HelpLine line1 = (HelpLine) i.next(); - assertEquals(0, line1.getIndent()); - assertEquals(option, line1.getOption()); - - final HelpLine line3 = (HelpLine) i.next(); - assertEquals(1, line3.getIndent()); - assertEquals(COMPLEX_CHILDREN, line3.getOption()); - - final HelpLine line4 = (HelpLine) i.next(); - assertEquals(2, line4.getIndent()); - assertEquals(COMPLEX_CHILD_BASIC, line4.getOption()); - - final HelpLine line5 = (HelpLine) i.next(); - assertEquals(2, line5.getIndent()); - assertEquals(COMPLEX_CHILD_DIGEST, line5.getOption()); - - final HelpLine line6 = (HelpLine) i.next(); - assertEquals(2, line6.getIndent()); - assertEquals(COMPLEX_CHILD_SSL, line6.getOption()); - - assertFalse(i.hasNext()); - } - - public void testHelpLines_NoChildren() { - final Option option = buildComplexParent(); - final Set settings = new HashSet(DisplaySetting.ALL); - settings.remove(DisplaySetting.DISPLAY_PARENT_CHILDREN); - - final List lines = option.helpLines(0, settings, null); - final Iterator i = lines.iterator(); - - final HelpLine line1 = (HelpLine) i.next(); - assertEquals(0, line1.getIndent()); - assertEquals(option, line1.getOption()); - - final HelpLine line2 = (HelpLine) i.next(); - assertEquals(1, line2.getIndent()); - assertEquals(COMPLEX_ARGUMENT, line2.getOption()); - - assertFalse(i.hasNext()); - } - - public void testNullPreferredName() { - try { - new CommandBuilder().create(); - } catch (IllegalStateException exp) { - assertEquals(ResourceHelper.getResourceHelper().getMessage(ResourceConstants.OPTION_NO_NAME), exp.getMessage()); - } - } - - public void testRequired() { - Command cmd = new CommandBuilder().withRequired(true).withName("blah").create(); - assertTrue("cmd is not required", cmd.isRequired()); - assertEquals("id is incorrect", 0, cmd.getId()); - } - - public void testID() { - Command cmd = new CommandBuilder().withId('c').withName("blah").create(); - assertEquals("id is incorrect", 'c', cmd.getId()); - } - - public void testGetId() { - assertEquals('h', DefaultOptionTest.buildHelpOption().getId()); - assertEquals('X', DefaultOptionTest.buildXOption().getId()); - assertEquals(0, CommandTest.buildStartCommand().getId()); - } -} +/** * 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.option;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.ListIterator;import java.util.Set;import org.apache.commons.cli2.Argument ;import org.apache.commons.cli2.DisplaySetting;import org.apache.commons.cli2.Group;import org.apache.commons.cli2.HelpLine;import org.apache.commons.cli2.Option;import org.apache.commons.cli2.OptionException;import org.apache.commons.cli2.Parent;import org.apache.commons.cli2.WriteableCommandLine;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.WriteableCommandLineImpl;import org.apache.commons.cli2.resource.ResourceConstants;import org.apache.commons.cli2.resource.ResourceHelper;/** * @author Rob Oxspring */public class ParentTest extends ParentTestCase { public static final Argument COMPLEX_ARGUMENT = new ArgumentBuilder().withName("username").withMinimum(1).withMaximum(1).create(); public static final Option COMPLEX_CHILD_SSL = new Defau ltOptionBuilder().withLongName("ssl").withShortName("s").create(); public static final Option COMPLEX_CHILD_BASIC = new DefaultOptionBuilder().withLongName("basic").withShortName("b").create(); public static final Option COMPLEX_CHILD_DIGEST = new DefaultOptionBuilder().withLongName("digest").withShortName("d").create(); public static final Group COMPLEX_CHILDREN = new GroupBuilder().withName("login-opts").withOption(COMPLEX_CHILD_BASIC) .withOption(COMPLEX_CHILD_DIGEST).withOption(COMPLEX_CHILD_SSL).create(); public static Parent buildLibParent() { final Argument argument = ArgumentTest.buildPathArgument(); return new DefaultOption("-", "--", false, "--lib", "Specifies library search path", null, null, false, argument, null, 'l'); } public static Parent buildKParent() { final Group children = GroupTest.buildApacheCommandGroup(); return new DefaultOptio n("-", "--", false, "-k", "desc", null, null, false, null, children, 'k'); } public static Parent buildComplexParent() { return new CommandBuilder().withName("login").withName("lo").withName("l") .withArgument(COMPLEX_ARGUMENT).withChildren(COMPLEX_CHILDREN) .create(); } /* (non-Javadoc) * @see org.apache.commons.cli2.ParentTestCase#testProcessParent() */ public void testProcessParent() throws OptionException { final Parent option = buildKParent(); final List args = list("-k", "start"); final WriteableCommandLine commandLine = commandLine(option, args); final ListIterator iterator = args.listIterator(); option.processParent(commandLine, iterator); assertEquals("start", iterator.next()); assertFalse(iterator.hasNext()); assertTrue(commandLine.hasOption(option)); assertTrue(comman dLine.hasOption("-k")); assertTrue(commandLine.getValues(option).isEmpty()); } /* (non-Javadoc) * @see org.apache.commons.cli2.OptionTestCase#testCanProcess() */ public void testCanProcess() { final Parent option = buildKParent(); assertTrue(option.canProcess(new WriteableCommandLineImpl(option, null), "-k")); } public void testCanProcess_BadMatch() { final Parent option = buildKParent(); assertFalse(option.canProcess(new WriteableCommandLineImpl(option, null), "-K")); } public void testCanProcess_ContractedArgument() { final Parent option = buildLibParent(); assertTrue(option.canProcess(new WriteableCommandLineImpl(option, null), "--lib=/usr/lib")); } /* (non-Javadoc) * @see org.apache.commons.cli2.OptionTestCase#testPrefixes() */ public void testPrefixes() { final Parent option = buildKParent(); assertContentsEqual(list("-", "--"), option.getPrefixes()); } /* (non-Javadoc) * @see org.apache.commons.cli2.OptionTestCase#testProcess() */ public void testProcess() throws OptionException { final Parent option = CommandTest.buildStartCommand(); final List args = list("start"); final WriteableCommandLine commandLine = commandLine(option, args); final ListIterator iterator = args.listIterator(); option.process(commandLine, iterator); assertFalse(iterator.hasNext()); assertTrue(commandLine.hasOption(option)); assertTrue(commandLine.hasOption("start")); assertFalse(commandLine.hasOption("stop")); assertTrue(commandLine.getValues(option).isEmpty()); } public void testProcess_NoMatch() throws OptionException { final Parent option = CommandTest.buildStartCommand(); final List args = list("whatever"); final WriteableCommandLine commandLine = commandLine(option, args); final ListIterator iterator = args.listIterator() ; try { option.process(commandLine, iterator); fail("unexpected token not thrown"); } catch (OptionException exp) { OptionException e = new OptionException(option, ResourceConstants.UNEXPECTED_TOKEN, "whatever"); assertEquals("wrong exception message", e.getMessage(), exp.getMessage()); } } public void testProcess_Children() throws OptionException { final Parent option = buildKParent(); final List args = list("-k", "start"); final WriteableCommandLine commandLine = commandLine(option, args); final ListIterator iterator = args.listIterator(); option.process(commandLine, iterator); assertNull(option.findOption("whatever")); assertNotNull(option.findOption("start")); assertFalse(iterator.hasNext()); assertTrue(commandLine.hasOption(option)); assertTrue(commandLine.hasOption("-k")); assertTrue(commandLine.hasOpt ion("start")); assertFalse(commandLine.hasOption("stop")); assertTrue(commandLine.getValues(option).isEmpty()); } public void testProcess_Argument() throws OptionException { final Parent option = buildLibParent(); final List args = list("--lib=C:\\WINDOWS;C:\\WINNT;C:\\"); final WriteableCommandLine commandLine = commandLine(option, args); final ListIterator iterator = args.listIterator(); option.process(commandLine, iterator); assertFalse(iterator.hasNext()); assertTrue(commandLine.hasOption(option)); assertTrue(commandLine.hasOption("--lib")); assertContentsEqual(list("C:\\WINDOWS", "C:\\WINNT", "C:\\"), commandLine.getValues(option)); } /* (non-Javadoc) * @see org.apache.commons.cli2.OptionTestCase#testTriggers() */ public void testTriggers() { final Parent option = buildKParent(); assertContentsEqual(list("-k"), option.getTriggers()); } /* (non-J avadoc) * @see org.apache.commons.cli2.OptionTestCase#testValidate() */ public void testValidate() throws OptionException { final Parent option = CommandTest.buildStartCommand(); final WriteableCommandLine commandLine = commandLine(option, list()); option.validate(commandLine); commandLine.addOption(option); option.validate(commandLine); } public void testValidate_Children() throws OptionException { final Parent option = buildKParent(); final WriteableCommandLine commandLine = commandLine(option, list()); option.validate(commandLine); commandLine.addOption(option); try { option.validate(commandLine); fail("Missing a command"); } catch (OptionException moe) { assertNotNull(moe.getOption()); assertNotSame(option, moe.getOption()); } } public void testValidate_Argument() throws OptionException { final Command option = CommandTest.buildLoginCommand(); final WriteableCommandLine commandLine = commandLine(option, list()); option.validate(commandLine); commandLine.addOption(option); try { option.validate(commandLine); fail("Missing a value"); } catch (OptionException moe) { assertSame(option, moe.getOption()); } } /* (non-Javadoc) * @see org.apache.commons.cli2.OptionTestCase#testAppendUsage() */ public void testAppendUsage() { final Option option = buildComplexParent(); final StringBuffer buffer = new StringBuffer(); final Set settings = new HashSet(DisplaySetting.ALL); settings.remove(DisplaySetting.DISPLAY_GROUP_OUTER); option.appendUsage(buffer, settings, null); assertEquals("[login (l,lo) [login-opts (--basic (-b)|--digest (-d)|--ssl (-s))]]", buffer.toString()); } public void testAppendUsage_NoArgument s() { final Option option = buildComplexParent(); final StringBuffer buffer = new StringBuffer(); final Set settings = new HashSet(DisplaySetting.ALL); settings.remove(DisplaySetting.DISPLAY_PARENT_ARGUMENT); settings.remove(DisplaySetting.DISPLAY_GROUP_OUTER); option.appendUsage(buffer, settings, null); assertEquals("[login (l,lo) [login-opts (--basic (-b)|--digest (-d)|--ssl (-s))]]", buffer.toString()); } public void testAppendUsage_NoChildren() { final Option option = buildComplexParent(); final StringBuffer buffer = new StringBuffer(); final Set settings = new HashSet(DisplaySetting.ALL); settings.remove(DisplaySetting.DISPLAY_PARENT_CHILDREN); option.appendUsage(buffer, settings, null); assertEquals("[login (l,lo) ]", buffer.toString()); } public void testAppendUsage_NoArgumentsOrChildren() { final Option option = buildComplexParen t(); final StringBuffer buffer = new StringBuffer(); final Set settings = new HashSet(DisplaySetting.ALL); settings.remove(DisplaySetting.DISPLAY_PARENT_CHILDREN); settings.remove(DisplaySetting.DISPLAY_PARENT_ARGUMENT); option.appendUsage(buffer, settings, null); assertEquals("[login (l,lo)]", buffer.toString()); } /* (non-Javadoc) * @see org.apache.commons.cli2.OptionTestCase#testGetPreferredName() */ public void testGetPreferredName() { final Option option = buildLibParent(); assertEquals("--lib", option.getPreferredName()); } /* (non-Javadoc) * @see org.apache.commons.cli2.OptionTestCase#testGetDescription() */ public void testGetDescription() { final Option option = buildLibParent(); assertEquals("Specifies library search path", option.getDescription()); } /* (non-Javadoc) * @see org.apache.commons.cli2.OptionTestCase#testHelpLines() */ public void te stHelpLines() { final Option option = buildComplexParent(); final List lines = option.helpLines(0, DisplaySetting.ALL, null); final Iterator i = lines.iterator(); final HelpLine line1 = (HelpLine) i.next(); assertEquals(0, line1.getIndent()); assertEquals(option, line1.getOption()); final HelpLine line2 = (HelpLine) i.next(); assertEquals(1, line2.getIndent()); assertEquals(COMPLEX_ARGUMENT, line2.getOption()); final HelpLine line3 = (HelpLine) i.next(); assertEquals(1, line3.getIndent()); assertEquals(COMPLEX_CHILDREN, line3.getOption()); final HelpLine line4 = (HelpLine) i.next(); assertEquals(2, line4.getIndent()); assertEquals(COMPLEX_CHILD_BASIC, line4.getOption()); final HelpLine line5 = (HelpLine) i.next(); assertEquals(2, line5.getIndent()); assertEquals(COMPLEX_CHILD_DIGEST, line5.getOption()); final HelpLine line6 = (HelpLine) i.next( ); assertEquals(2, line6.getIndent()); assertEquals(COMPLEX_CHILD_SSL, line6.getOption()); assertFalse(i.hasNext()); } public void testHelpLines_NoArgument() { final Option option = buildComplexParent(); final Set settings = new HashSet(DisplaySetting.ALL); settings.remove(DisplaySetting.DISPLAY_PARENT_ARGUMENT); final List lines = option.helpLines(0, settings, null); final Iterator i = lines.iterator(); final HelpLine line1 = (HelpLine) i.next(); assertEquals(0, line1.getIndent()); assertEquals(option, line1.getOption()); final HelpLine line3 = (HelpLine) i.next(); assertEquals(1, line3.getIndent()); assertEquals(COMPLEX_CHILDREN, line3.getOption()); final HelpLine line4 = (HelpLine) i.next(); assertEquals(2, line4.getIndent()); assertEquals(COMPLEX_CHILD_BASIC, line4.getOption()); final HelpLine line5 = (HelpLine) i.next(); assertEquals (2, line5.getIndent()); assertEquals(COMPLEX_CHILD_DIGEST, line5.getOption()); final HelpLine line6 = (HelpLine) i.next(); assertEquals(2, line6.getIndent()); assertEquals(COMPLEX_CHILD_SSL, line6.getOption()); assertFalse(i.hasNext()); } public void testHelpLines_NoChildren() { final Option option = buildComplexParent(); final Set settings = new HashSet(DisplaySetting.ALL); settings.remove(DisplaySetting.DISPLAY_PARENT_CHILDREN); final List lines = option.helpLines(0, settings, null); final Iterator i = lines.iterator(); final HelpLine line1 = (HelpLine) i.next(); assertEquals(0, line1.getIndent()); assertEquals(option, line1.getOption()); final HelpLine line2 = (HelpLine) i.next(); assertEquals(1, line2.getIndent()); assertEquals(COMPLEX_ARGUMENT, line2.getOption()); assertFalse(i.hasNext()); } public void testNullPreferredName() { try { new CommandBuilder().create(); } catch (IllegalStateException exp) { assertEquals(ResourceHelper.getResourceHelper().getMessage(ResourceConstants.OPTION_NO_NAME), exp.getMessage()); } } public void testRequired() { Command cmd = new CommandBuilder().withRequired(true).withName("blah").create(); assertTrue("cmd is not required", cmd.isRequired()); assertEquals("id is incorrect", 0, cmd.getId()); } public void testID() { Command cmd = new CommandBuilder().withId('c').withName("blah").create(); assertEquals("id is incorrect", 'c', cmd.getId()); } public void testGetId() { assertEquals('h', DefaultOptionTest.buildHelpOption().getId()); assertEquals('X', DefaultOptionTest.buildXOption().getId()); assertEquals(0, CommandTest.buildStartCommand().getId()); }} \ No newline at end of file Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ParentTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ParentTestCase.java?rev=639941&r1=639940&r2=639941&view=diff ============================================================================== --- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ParentTestCase.java (original) +++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ParentTestCase.java Fri Mar 21 19:49:41 2008 @@ -1,26 +1 @@ -/** - * 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.option; - -import org.apache.commons.cli2.OptionException; - -/** - * @author Rob Oxspring - */ -public abstract class ParentTestCase extends OptionTestCase { - public abstract void testProcessParent() throws OptionException; -} +/** * 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.option;import org.apache.commons.cli2.OptionException;/** * @author Rob Oxspring */public abstract class ParentTestCase extends OptionTestCase { public abstract void t estProcessParent() throws OptionException;} \ No newline at end of file Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/PropertyOptionTest.java URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/PropertyOptionTest.java?rev=639941&r1=639940&r2=639941&view=diff ============================================================================== --- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/PropertyOptionTest.java (original) +++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/PropertyOptionTest.java Fri Mar 21 19:49:41 2008 @@ -1,233 +1 @@ -/** - * 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.option; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Set; - -import org.apache.commons.cli2.DisplaySetting; -import org.apache.commons.cli2.HelpLine; -import org.apache.commons.cli2.Option; -import org.apache.commons.cli2.OptionException; -import org.apache.commons.cli2.WriteableCommandLine; -import org.apache.commons.cli2.commandline.WriteableCommandLineImpl; - -/** - * @author Rob Oxspring - */ -public class PropertyOptionTest extends OptionTestCase { - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testCanProcess() - */ - public void testCanProcess() { - final Option option = new PropertyOption(); - assertTrue(option.canProcess(new WriteableCommandLineImpl(option,null), "-Dmyprop=myval")); - } - - public void testCanProcess_Null() { - final Option option = new PropertyOption(); - assertFalse(option.canProcess(new WriteableCommandLineImpl(option,null), (String) null)); - } - - public void testCanProcess_TooShort() { - final Option option = new PropertyOption(); - assertFalse(option.canProcess(new WriteableCommandLineImpl(option,null), "-D")); - } - - public void testCanProcess_BadMatch() { - final Option option = new PropertyOption(); - assertFalse(option.canProcess(new WriteableCommandLineImpl(option,null),"-dump")); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testPrefixes() - */ - public void testPrefixes() { - final Option option = new PropertyOption(); - assertContentsEqual(list("-D"), option.getPrefixes()); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testProcess() - */ - public void testProcess() throws OptionException { - final Option option = new PropertyOption(); - final List args = list("-Dmyprop=myvalue"); - final WriteableCommandLine commandLine = commandLine(option, args); - final ListIterator iterator = args.listIterator(); - - option.process(commandLine, iterator); - assertEquals("myvalue", commandLine.getProperty("myprop")); - assertFalse(iterator.hasNext()); - assertEquals(1, commandLine.getProperties().size()); - } - - public void testProcess_UnexpectedOptionException() { - final Option option = new PropertyOption(); - final List args = list("--help"); - final WriteableCommandLine commandLine = commandLine(option, args); - final ListIterator iterator = args.listIterator(); - - try { - option.process(commandLine, iterator); - fail("UnexpectedOption"); - } - catch (final OptionException uoe) { - assertEquals(option, uoe.getOption()); - assertEquals( - "Unexpected --help while processing -Dproperty=value", - uoe.getMessage()); - } - } - - public void testProcess_BadPropertyException() throws OptionException { - final Option option = new PropertyOption(); - final List args = list("-Dmyprop"); - final WriteableCommandLine commandLine = commandLine(option, args); - final ListIterator iterator = args.listIterator(); - - option.process(commandLine, iterator); - - assertEquals("true", commandLine.getProperty("myprop")); - } - - public void testProcess_SetToEmpty() throws OptionException { - final Option option = new PropertyOption(); - final List args = list("-Dmyprop="); - final WriteableCommandLine commandLine = commandLine(option, args); - final ListIterator iterator = args.listIterator(); - - option.process(commandLine, iterator); - assertEquals("", commandLine.getProperty("myprop")); - assertFalse(iterator.hasNext()); - assertEquals(1, commandLine.getProperties().size()); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testTriggers() - */ - public void testTriggers() { - final Option option = new PropertyOption(); - - assertContentsEqual(list("-D"), option.getTriggers()); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testValidate() - */ - public void testValidate() throws OptionException { - final Option option = new PropertyOption(); - final List args = list("-Dproperty=value"); - final WriteableCommandLine commandLine = commandLine(option, args); - final ListIterator iterator = args.listIterator(); - - option.process(commandLine, iterator); - - option.validate(commandLine); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testAppendUsage() - */ - public void testAppendUsage() { - final Option option = new PropertyOption(); - final StringBuffer buffer = new StringBuffer(); - option.appendUsage(buffer, DisplaySetting.ALL, null); - - assertEquals("-D=", buffer.toString()); - } - - public void testAppendUsage_Hidden() { - final Option option = new PropertyOption(); - final StringBuffer buffer = new StringBuffer(); - final Set settings = new HashSet(DisplaySetting.ALL); - settings.remove(DisplaySetting.DISPLAY_PROPERTY_OPTION); - option.appendUsage(buffer, settings, null); - - assertEquals("", buffer.toString()); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testGetPreferredName() - */ - public void testGetPreferredName() { - final Option option = new PropertyOption(); - assertEquals("-D", option.getPreferredName()); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testGetDescription() - */ - public void testGetDescription() { - final Option option = new PropertyOption(); - assertEquals( - "Passes properties and values to the application", - option.getDescription()); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testHelpLines() - */ - public void testHelpLines() { - final Option option = new PropertyOption(); - final List lines = option.helpLines(0, DisplaySetting.ALL, null); - final Iterator i = lines.iterator(); - - final HelpLine line1 = (HelpLine)i.next(); - assertEquals(0, line1.getIndent()); - assertEquals(option, line1.getOption()); - - assertFalse(i.hasNext()); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testHelpLines() - */ - public void testHelpLines_NoDisplay() { - final Option option = new PropertyOption(); - final Set settings = new HashSet(DisplaySetting.ALL); - settings.remove(DisplaySetting.DISPLAY_PROPERTY_OPTION); - final List lines = option.helpLines(0, settings, null); - final Iterator i = lines.iterator(); - - assertFalse(i.hasNext()); - } -} +/** * 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.option;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.ListIterator;import java.util.Set;import org.apache.commons.cli2.DisplayS etting;import org.apache.commons.cli2.HelpLine;import org.apache.commons.cli2.Option;import org.apache.commons.cli2.OptionException;import org.apache.commons.cli2.WriteableCommandLine;import org.apache.commons.cli2.commandline.WriteableCommandLineImpl;/** * @author Rob Oxspring */public class PropertyOptionTest extends OptionTestCase { /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testCanProcess() */ public void testCanProcess() { final Option option = new PropertyOption(); assertTrue(option.canProcess(new WriteableCommandLineImpl(option,null), "-Dmyprop=myval")); } public void testCanProcess_Null() { final Option option = new PropertyOption(); assertFalse(option.canProcess(new WriteableCommandLineImpl(option,null), (String) null)); } public void testCanProcess_TooShort() { final Option option = new PropertyOption(); assertFalse(option.canProcess(new WriteableCommandLineImpl(opti on,null), "-D")); } public void testCanProcess_BadMatch() { final Option option = new PropertyOption(); assertFalse(option.canProcess(new WriteableCommandLineImpl(option,null),"-dump")); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testPrefixes() */ public void testPrefixes() { final Option option = new PropertyOption(); assertContentsEqual(list("-D"), option.getPrefixes()); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testProcess() */ public void testProcess() throws OptionException { final Option option = new PropertyOption(); final List args = list("-Dmyprop=myvalue"); final WriteableCommandLine commandLine = commandLine(option, args); final ListIterator iterator = args.listIterator(); option.process(commandLine, iterator); assertEquals("myvalue", commandLine.getProperty("myprop")); assertFalse (iterator.hasNext()); assertEquals(1, commandLine.getProperties().size()); } public void testProcess_UnexpectedOptionException() { final Option option = new PropertyOption(); final List args = list("--help"); final WriteableCommandLine commandLine = commandLine(option, args); final ListIterator iterator = args.listIterator(); try { option.process(commandLine, iterator); fail("UnexpectedOption"); } catch (final OptionException uoe) { assertEquals(option, uoe.getOption()); assertEquals( "Unexpected --help while processing -Dproperty=value", uoe.getMessage()); } } public void testProcess_BadPropertyException() throws OptionException { final Option option = new PropertyOption(); final List args = list("-Dmyprop"); final WriteableCommandLine commandLine = commandLine(option, args); final ListIterator itera tor = args.listIterator(); option.process(commandLine, iterator); assertEquals("true", commandLine.getProperty("myprop")); } public void testProcess_SetToEmpty() throws OptionException { final Option option = new PropertyOption(); final List args = list("-Dmyprop="); final WriteableCommandLine commandLine = commandLine(option, args); final ListIterator iterator = args.listIterator(); option.process(commandLine, iterator); assertEquals("", commandLine.getProperty("myprop")); assertFalse(iterator.hasNext()); assertEquals(1, commandLine.getProperties().size()); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testTriggers() */ public void testTriggers() { final Option option = new PropertyOption(); assertContentsEqual(list("-D"), option.getTriggers()); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testVal idate() */ public void testValidate() throws OptionException { final Option option = new PropertyOption(); final List args = list("-Dproperty=value"); final WriteableCommandLine commandLine = commandLine(option, args); final ListIterator iterator = args.listIterator(); option.process(commandLine, iterator); option.validate(commandLine); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testAppendUsage() */ public void testAppendUsage() { final Option option = new PropertyOption(); final StringBuffer buffer = new StringBuffer(); option.appendUsage(buffer, DisplaySetting.ALL, null); assertEquals("-D=", buffer.toString()); } public void testAppendUsage_Hidden() { final Option option = new PropertyOption(); final StringBuffer buffer = new StringBuffer(); final Set settings = new HashSet(DisplaySetting.ALL); se ttings.remove(DisplaySetting.DISPLAY_PROPERTY_OPTION); option.appendUsage(buffer, settings, null); assertEquals("", buffer.toString()); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testGetPreferredName() */ public void testGetPreferredName() { final Option option = new PropertyOption(); assertEquals("-D", option.getPreferredName()); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testGetDescription() */ public void testGetDescription() { final Option option = new PropertyOption(); assertEquals( "Passes properties and values to the application", option.getDescription()); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testHelpLines() */ public void testHelpLines() { final Option option = new PropertyOption(); final List lines = option.helpLines(0, DisplaySettin g.ALL, null); final Iterator i = lines.iterator(); final HelpLine line1 = (HelpLine)i.next(); assertEquals(0, line1.getIndent()); assertEquals(option, line1.getOption()); assertFalse(i.hasNext()); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testHelpLines() */ public void testHelpLines_NoDisplay() { final Option option = new PropertyOption(); final Set settings = new HashSet(DisplaySetting.ALL); settings.remove(DisplaySetting.DISPLAY_PROPERTY_OPTION); final List lines = option.helpLines(0, settings, null); final Iterator i = lines.iterator(); assertFalse(i.hasNext()); }} \ No newline at end of file Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/SwitchTest.java URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/SwitchTest.java?rev=639941&r1=639940&r2=639941&view=diff ============================================================================== --- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/SwitchTest.java (original) +++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/SwitchTest.java Fri Mar 21 19:49:41 2008 @@ -1,308 +1 @@ -/** - * 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.option; - -import java.util.HashSet; -import java.util.List; -import java.util.ListIterator; -import java.util.Set; - -import org.apache.commons.cli2.DisplaySetting; -import org.apache.commons.cli2.Option; -import org.apache.commons.cli2.OptionException; -import org.apache.commons.cli2.Parent; -import org.apache.commons.cli2.WriteableCommandLine; -import org.apache.commons.cli2.commandline.WriteableCommandLineImpl; -import org.apache.commons.cli2.resource.ResourceConstants; -import org.apache.commons.cli2.resource.ResourceHelper; - -/** - * @author Rob Oxspring - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class SwitchTest - extends ParentTestCase { - public static Switch buildDisplaySwitch() { - final Set aliases = new HashSet(); - aliases.add("d"); - aliases.add("disp"); - - return new Switch("+", "-", "display", aliases, "Sets whether to display to screen", true, - null, null, 'd', null); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.ParentTestCase#testProcessParent() - */ - public void testProcessParent() - throws OptionException { - final Switch option = buildDisplaySwitch(); - final List args = list("+d"); - final WriteableCommandLine commandLine = commandLine(option, args); - final ListIterator iterator = args.listIterator(); - option.processParent(commandLine, iterator); - - assertFalse(iterator.hasNext()); - assertTrue(commandLine.hasOption(option)); - assertTrue(commandLine.hasOption("+d")); - assertTrue(commandLine.hasOption("-display")); - assertEquals(Boolean.TRUE, commandLine.getSwitch("-d")); - assertTrue(commandLine.getValues(option).isEmpty()); - } - - public void testProcessParent_Disabled() - throws OptionException { - final Switch option = buildDisplaySwitch(); - final List args = list("-disp"); - final WriteableCommandLine commandLine = commandLine(option, args); - final ListIterator iterator = args.listIterator(); - option.process(commandLine, iterator); - - assertFalse(iterator.hasNext()); - assertTrue(commandLine.hasOption(option)); - assertTrue(commandLine.hasOption("+d")); - assertTrue(commandLine.hasOption("-display")); - assertEquals(Boolean.FALSE, commandLine.getSwitch("-d")); - assertTrue(commandLine.getValues(option).isEmpty()); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testCanProcess() - */ - public void testCanProcess() { - final Switch option = buildDisplaySwitch(); - assertTrue(option.canProcess(new WriteableCommandLineImpl(option, null), "+d")); - } - - public void testCanProcess_BadMatch() { - final Switch option = buildDisplaySwitch(); - assertFalse(option.canProcess(new WriteableCommandLineImpl(option, null), "-dont")); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testPrefixes() - */ - public void testPrefixes() { - final Switch option = buildDisplaySwitch(); - assertContentsEqual(list("-", "+"), option.getPrefixes()); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testProcess() - */ - public void testProcess() { - // TODO Auto-generated method stub - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testTriggers() - */ - public void testTriggers() { - final Switch option = buildDisplaySwitch(); - assertContentsEqual(list("-d", "+d", "-disp", "+disp", "+display", "-display"), - option.getTriggers()); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testValidate() - */ - public void testValidate() { - final Parent option = buildDisplaySwitch(); - final WriteableCommandLine commandLine = commandLine(option, list()); - - try { - option.validate(commandLine); - fail("Missing an option"); - } catch (OptionException moe) { - assertSame(option, moe.getOption()); - } - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testAppendUsage() - */ - public void testAppendUsage() { - final Option option = buildDisplaySwitch(); - final StringBuffer buffer = new StringBuffer(); - option.appendUsage(buffer, DisplaySetting.ALL, null); - - assertEquals("+display|-display (+d|-d,+disp|-disp)", buffer.toString()); - } - - public void testAppendUsage_NoAlias() { - final Option option = buildDisplaySwitch(); - final StringBuffer buffer = new StringBuffer(); - final Set settings = new HashSet(DisplaySetting.ALL); - settings.remove(DisplaySetting.DISPLAY_ALIASES); - option.appendUsage(buffer, settings, null); - - assertEquals("+display|-display", buffer.toString()); - } - - public void testAppendUsage_NoDisabled() { - final Option option = buildDisplaySwitch(); - final StringBuffer buffer = new StringBuffer(); - final Set settings = new HashSet(DisplaySetting.ALL); - settings.remove(DisplaySetting.DISPLAY_SWITCH_DISABLED); - option.appendUsage(buffer, settings, null); - - assertEquals("+display (+d,+disp)", buffer.toString()); - } - - public void testAppendUsage_NoEnabled() { - final Option option = buildDisplaySwitch(); - final StringBuffer buffer = new StringBuffer(); - final Set settings = new HashSet(DisplaySetting.ALL); - settings.remove(DisplaySetting.DISPLAY_SWITCH_ENABLED); - option.appendUsage(buffer, settings, null); - - assertEquals("-display (-d,-disp)", buffer.toString()); - } - - public void testAppendUsage_NoDisabledOrEnabled() { - final Option option = buildDisplaySwitch(); - final StringBuffer buffer = new StringBuffer(); - final Set settings = new HashSet(DisplaySetting.ALL); - settings.remove(DisplaySetting.DISPLAY_SWITCH_DISABLED); - settings.remove(DisplaySetting.DISPLAY_SWITCH_ENABLED); - option.appendUsage(buffer, settings, null); - - assertEquals("+display (+d,+disp)", buffer.toString()); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testGetPreferredName() - */ - public void testGetPreferredName() { - final Option option = buildDisplaySwitch(); - assertEquals("+display", option.getPreferredName()); - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testGetDescription() - */ - public void testGetDescription() { - final Option option = buildDisplaySwitch(); - assertEquals("Sets whether to display to screen", option.getDescription()); - } - - public void testNullPreferredName() { - try { - new Switch("+", "-", null, null, "Sets whether to display to screen", true, null, null, - 'd', null); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT), - exp.getMessage()); - } - } - - public void testEmptyPreferredName() { - try { - new Switch("+", "-", "", null, "Sets whether to display to screen", true, null, null, - 'd', null); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT), - exp.getMessage()); - } - } - - public void testNullAliases() { - try { - new Switch("+", "-", "display", null, "Sets whether to display to screen", true, null, - null, 'd', null); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT), - exp.getMessage()); - } - } - - public void testNullEnablePrefix() { - try { - new Switch(null, "-", "display", null, "Sets whether to display to screen", true, null, - null, 'd', null); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_NO_ENABLED_PREFIX), - exp.getMessage()); - } - } - - public void testNullDisablePrefix() { - try { - new Switch("+", null, "display", null, "Sets whether to display to screen", true, null, - null, 'd', null); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_NO_DISABLED_PREFIX), - exp.getMessage()); - } - } - - public void testEnabledPrefixStartsWithDisabledPrefix() { - try { - new Switch("-", "-", "display", null, "Sets whether to display to screen", true, null, - null, 'd', null); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_ENABLED_STARTS_WITH_DISABLED), - exp.getMessage()); - } - } - - public void testDisabledPrefixStartsWithEnabledPrefix() { - try { - new Switch("o", "on", "display", null, "Sets whether to display to screen", true, null, - null, 'd', null); - } catch (IllegalArgumentException exp) { - assertEquals("wrong exception message", - ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_DISABLED_STARTWS_WITH_ENABLED), - exp.getMessage()); - } - } - - /* - * (non-Javadoc) - * - * @see org.apache.commons.cli2.OptionTestCase#testHelpLines() - */ - public void testHelpLines() { - // TODO Auto-generated method stub - } -} +/** * 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.option;import java.util.HashSet;import java.util.List;import java.util.ListIterator;import java.util.Set;import org.apache.commons.cli2.DisplaySetting;import org.apache.c ommons.cli2.Option;import org.apache.commons.cli2.OptionException;import org.apache.commons.cli2.Parent;import org.apache.commons.cli2.WriteableCommandLine;import org.apache.commons.cli2.commandline.WriteableCommandLineImpl;import org.apache.commons.cli2.resource.ResourceConstants;import org.apache.commons.cli2.resource.ResourceHelper;/** * @author Rob Oxspring * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */public class SwitchTest extends ParentTestCase { public static Switch buildDisplaySwitch() { final Set aliases = new HashSet(); aliases.add("d"); aliases.add("disp"); return new Switch("+", "-", "display", aliases, "Sets whether to display to screen", true, null, null, 'd', null); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.ParentTestCase#testProcessParent() */ public void testProcessParent() t hrows OptionException { final Switch option = buildDisplaySwitch(); final List args = list("+d"); final WriteableCommandLine commandLine = commandLine(option, args); final ListIterator iterator = args.listIterator(); option.processParent(commandLine, iterator); assertFalse(iterator.hasNext()); assertTrue(commandLine.hasOption(option)); assertTrue(commandLine.hasOption("+d")); assertTrue(commandLine.hasOption("-display")); assertEquals(Boolean.TRUE, commandLine.getSwitch("-d")); assertTrue(commandLine.getValues(option).isEmpty()); } public void testProcessParent_Disabled() throws OptionException { final Switch option = buildDisplaySwitch(); final List args = list("-disp"); final WriteableCommandLine commandLine = commandLine(option, args); final ListIterator iterator = args.listIterator(); option.process(commandLine, iterator); assertFalse(iterat or.hasNext()); assertTrue(commandLine.hasOption(option)); assertTrue(commandLine.hasOption("+d")); assertTrue(commandLine.hasOption("-display")); assertEquals(Boolean.FALSE, commandLine.getSwitch("-d")); assertTrue(commandLine.getValues(option).isEmpty()); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testCanProcess() */ public void testCanProcess() { final Switch option = buildDisplaySwitch(); assertTrue(option.canProcess(new WriteableCommandLineImpl(option, null), "+d")); } public void testCanProcess_BadMatch() { final Switch option = buildDisplaySwitch(); assertFalse(option.canProcess(new WriteableCommandLineImpl(option, null), "-dont")); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testPrefixes() */ public void testPrefixes() { final Switch option = buildDisplaySwitch(); assertContentsEqual(lis t("-", "+"), option.getPrefixes()); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testProcess() */ public void testProcess() { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testTriggers() */ public void testTriggers() { final Switch option = buildDisplaySwitch(); assertContentsEqual(list("-d", "+d", "-disp", "+disp", "+display", "-display"), option.getTriggers()); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testValidate() */ public void testValidate() { final Parent option = buildDisplaySwitch(); final WriteableCommandLine commandLine = commandLine(option, list()); try { option.validate(commandLine); fail("Missing an option"); } catch (OptionException moe) { assertSame(option, moe.getOption ()); } } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testAppendUsage() */ public void testAppendUsage() { final Option option = buildDisplaySwitch(); final StringBuffer buffer = new StringBuffer(); option.appendUsage(buffer, DisplaySetting.ALL, null); assertEquals("+display|-display (+d|-d,+disp|-disp)", buffer.toString()); } public void testAppendUsage_NoAlias() { final Option option = buildDisplaySwitch(); final StringBuffer buffer = new StringBuffer(); final Set settings = new HashSet(DisplaySetting.ALL); settings.remove(DisplaySetting.DISPLAY_ALIASES); option.appendUsage(buffer, settings, null); assertEquals("+display|-display", buffer.toString()); } public void testAppendUsage_NoDisabled() { final Option option = buildDisplaySwitch(); final StringBuffer buffer = new StringBuffer(); final Set settings = new HashSet( DisplaySetting.ALL); settings.remove(DisplaySetting.DISPLAY_SWITCH_DISABLED); option.appendUsage(buffer, settings, null); assertEquals("+display (+d,+disp)", buffer.toString()); } public void testAppendUsage_NoEnabled() { final Option option = buildDisplaySwitch(); final StringBuffer buffer = new StringBuffer(); final Set settings = new HashSet(DisplaySetting.ALL); settings.remove(DisplaySetting.DISPLAY_SWITCH_ENABLED); option.appendUsage(buffer, settings, null); assertEquals("-display (-d,-disp)", buffer.toString()); } public void testAppendUsage_NoDisabledOrEnabled() { final Option option = buildDisplaySwitch(); final StringBuffer buffer = new StringBuffer(); final Set settings = new HashSet(DisplaySetting.ALL); settings.remove(DisplaySetting.DISPLAY_SWITCH_DISABLED); settings.remove(DisplaySetting.DISPLAY_SWITCH_ENABLED); option.appendUsage(buffer, settings , null); assertEquals("+display (+d,+disp)", buffer.toString()); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testGetPreferredName() */ public void testGetPreferredName() { final Option option = buildDisplaySwitch(); assertEquals("+display", option.getPreferredName()); } /* * (non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testGetDescription() */ public void testGetDescription() { final Option option = buildDisplaySwitch(); assertEquals("Sets whether to display to screen", option.getDescription()); } public void testNullPreferredName() { try { new Switch("+", "-", null, null, "Sets whether to display to screen", true, null, null, 'd', null); } catch (IllegalArgumentException exp) { assertEquals("wrong exception message", ResourceHelper.getResourceHelper().getMessage(R esourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT), exp.getMessage()); } } public void testEmptyPreferredName() { try { new Switch("+", "-", "", null, "Sets whether to display to screen", true, null, null, 'd', null); } catch (IllegalArgumentException exp) { assertEquals("wrong exception message", ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT), exp.getMessage()); } } public void testNullAliases() { try { new Switch("+", "-", "display", null, "Sets whether to display to screen", true, null, null, 'd', null); } catch (IllegalArgumentException exp) { assertEquals("wrong exception message", ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT), exp.getMessage()); } } public void testNullEnablePrefix() { try { new Switch(null, "-", "display", null, "Sets whether to display to screen", true, null, null, 'd', null); } catch (IllegalArgumentException exp) { assertEquals("wrong exception message", ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_NO_ENABLED_PREFIX), exp.getMessage()); } } public void testNullDisablePrefix() { try { new Switch("+", null, "display", null, "Sets whether to display to screen", true, null, null, 'd', null); } catch (IllegalArgumentException exp) { assertEquals("wrong exception message", ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_NO_DISABLED_PREFIX), exp.getMessage()); } } public void testEnabledPrefixStartsWithDisabledPrefix() { try { new Switch("-", "-", "display", null, "Sets whether to display to screen", true, null, null, 'd', null); } catch (IllegalArgumentException exp) { assertEquals("wrong exception message", ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_ENABLED_STARTS_WITH_DISABLED), exp.getMessage()); } } public void testDisabledPrefixStartsWithEnabledPrefix() { try { new Switch("o", "on", "display", null, "Sets whether to display to screen", true, null, null, 'd', null); } catch (IllegalArgumentException exp) { assertEquals("wrong exception message", ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_DISABLED_STARTWS_WITH_ENABLED), exp.getMessage()); } } /* * ( non-Javadoc) * * @see org.apache.commons.cli2.OptionTestCase#testHelpLines() */ public void testHelpLines() { // TODO Auto-generated method stub }} \ No newline at end of file Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/resource/ResourceHelperTest.java URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/resource/ResourceHelperTest.java?rev=639941&r1=639940&r2=639941&view=diff ============================================================================== --- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/resource/ResourceHelperTest.java (original) +++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/resource/ResourceHelperTest.java Fri Mar 21 19:49:41 2008 @@ -1,84 +1 @@ -/* - * 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.resource; - -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import junit.framework.TestCase; - -/** - * A utility class used to provide internationalisation support. - * - * @author John Keyes - */ -public class ResourceHelperTest extends TestCase { - /** system property */ - private static final String PROP_LOCALE = "org.apache.commons.cli2.resource.bundle"; - - private static ResourceHelper helper; - - /** resource bundle */ - private ResourceBundle bundle; - - public void setUp() { - System.setProperty(PROP_LOCALE, "org.apache.commons.cli2.resource.TestBundle"); - helper = ResourceHelper.getResourceHelper(); - } - - public void tearDown() { - System.setProperty(PROP_LOCALE, "org.apache.commons.cli2.resource.CLIMessageBundle_en_US.properties"); - } - - /** - * Create a new ResourceHelper for the specified class. - * - * @param clazz the Class that requires some resources - */ - public ResourceHelperTest() { - super("ResourceHelperTest"); - } - - public void testOverridden() { - assertEquals("wrong message", "The class name \"ResourceHelper\" is invalid.", helper.getMessage("ClassValidator.bad.classname", "ResourceHelper")); - } - - public void testNewMessage1Param() { - assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message")); - } - - public void testNewMessage2Params() { - assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some")); - } - - public void testNewMessage3Params() { - assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some", "might")); - } - - public void testNewMessage4Params() { - assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some", "might", "say")); - } - - public void testDefaultBundle() { - System.setProperty(PROP_LOCALE, "madeupname.properties"); - helper = ResourceHelper.getResourceHelper(); - assertEquals("wrong message", "The class name \"ResourceHelper\" is invalid.", helper.getMessage("ClassValidator.bad.classname", "ResourceHelper")); - } -} +/* * 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.resource;import java.util.Locale;import java.util.MissingResourceException;import java.util.ResourceBundle;import junit.framework.TestCase;/** * A utility class used to provide internationalisation support. * * @author John Keyes */public class ResourceHelperTest extends TestCase { /** system property */ private static final String PROP_LOCALE = "org.apache.commons.cli2.resource.bundle"; private static ResourceHelper helper; /** resource bundle */ private ResourceBundle bundle; public void setUp() { System.setProperty(PROP_LOCALE, "org.apache.commons.cli2.resource.TestBundle"); helper = ResourceHelper.getResourceHelper(); } public void tearDown() { System.setProperty(PROP_LOCALE, "org.apache.commons.cli2.resource.CLIMessageBundle_en_US.properties"); } /** * Create a new ResourceHelper for the specified class. * * @param clazz the Class that requires some resources */ public ResourceHelperTest() { super("ResourceHelperTest"); } public void testOverridden() { assertEquals("wrong message", "The class name \"ResourceHelper\" is invalid.", helper.getMessage("ClassValidato r.bad.classname", "ResourceHelper")); } public void testNewMessage1Param() { assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message")); } public void testNewMessage2Params() { assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some")); } public void testNewMessage3Params() { assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some", "might")); } public void testNewMessage4Params() { assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some", "might", "say")); } public void testDefaultBundle() { System.setProperty(PROP_LOCALE, "madeupname.properties"); helper = ResourceHelper.getResourceHelper(); assertEquals("wrong message", "The class name \"ResourceHelper\" is invalid.", helper.getMessa ge("ClassValidator.bad.classname", "ResourceHelper")); }} \ No newline at end of file