You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jk...@apache.org on 2005/10/02 01:57:52 UTC
svn commit: r293045 - in
/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2: ./
commandline/ option/
Author: jkeyes
Date: Sat Oct 1 16:57:10 2005
New Revision: 293045
URL: http://svn.apache.org/viewcvs?rev=293045&view=rev
Log:
- added tests
Modified:
jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/PrecedenceTest.java
jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java
jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java
jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java
jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ArgumentTest.java
Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/PrecedenceTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/PrecedenceTest.java?rev=293045&r1=293044&r2=293045&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/PrecedenceTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/PrecedenceTest.java Sat Oct 1 16:57:10 2005
@@ -102,7 +102,7 @@
assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);
}
- public void XtestSimpleVsArgument() throws OptionException {
+ public void testSimpleVsArgument() throws OptionException {
final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
final GroupBuilder gBuilder = new GroupBuilder();
final ArgumentBuilder aBuilder = new ArgumentBuilder();
@@ -121,7 +121,7 @@
assertEquals(new String[] { "-f" }, cl);
}
- public void XtestSimpleVsBurst() throws OptionException {
+ public void testSimpleVsBurst() throws OptionException {
final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
final GroupBuilder gBuilder = new GroupBuilder();
final Group options =
@@ -137,7 +137,7 @@
assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);
}
- public void XtestSimpleVsChildren() throws OptionException {
+ public void testSimpleVsChildren() throws OptionException {
final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
final GroupBuilder gBuilder = new GroupBuilder();
@@ -248,7 +248,7 @@
cl);
}
- public void XtestSimpleVsArgumentVsBurst() throws OptionException {
+ public void testSimpleVsArgumentVsBurst() throws OptionException {
final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
final GroupBuilder gBuilder = new GroupBuilder();
final ArgumentBuilder aBuilder = new ArgumentBuilder();
@@ -270,7 +270,7 @@
assertEquals(new String[] { "-f" }, cl);
}
- public void XtestSimpleVsArgumentVsChildren() throws OptionException {
+ public void testSimpleVsArgumentVsChildren() throws OptionException {
final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
final GroupBuilder gBuilder = new GroupBuilder();
final ArgumentBuilder aBuilder = new ArgumentBuilder();
@@ -300,7 +300,7 @@
assertEquals(new String[] { "-f" }, cl);
}
- public void XtestSimpleVsBurstVsChildren() throws OptionException {
+ public void testSimpleVsBurstVsChildren() throws OptionException {
final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
final GroupBuilder gBuilder = new GroupBuilder();
@@ -363,7 +363,7 @@
assertEquals(new String[] { "-f" }, cl);
}
- public void XtestSimpleVsArgumentVsBurstVsChildren()
+ public void testSimpleVsArgumentVsBurstVsChildren()
throws OptionException {
final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
final GroupBuilder gBuilder = new GroupBuilder();
@@ -408,9 +408,8 @@
final List expected = Arrays.asList(options);
final Set actual = line.getOptionTriggers();
- //System.out.println(getName() + ": " + actual);
-
assertTrue(expected.containsAll(actual));
assertTrue(actual.containsAll(expected));
}
+
}
Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java?rev=293045&r1=293044&r2=293045&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/DefaultingCommandLineTest.java Sat Oct 1 16:57:10 2005
@@ -16,7 +16,9 @@
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;
@@ -124,5 +126,25 @@
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: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java?rev=293045&r1=293044&r2=293045&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PreferencesCommandLineTest.java Sat Oct 1 16:57:10 2005
@@ -15,6 +15,8 @@
*/
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;
@@ -40,8 +42,64 @@
return new PreferencesCommandLine(root,props,'|');
}
-
- public void testToMakeEclipseSpotTheTestCase(){
- // nothing to test
+
+ 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: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java?rev=293045&r1=293044&r2=293045&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/commandline/PropertiesCommandLineTest.java Sat Oct 1 16:57:10 2005
@@ -15,7 +15,9 @@
*/
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;
@@ -27,9 +29,6 @@
extends CommandLineTestCase {
private Properties props = null;
- /* (non-Javadoc)
- * @see org.apache.commons.cli2.CommandLineTest#createCommandLine()
- */
protected CommandLine createCommandLine() {
props = new Properties();
props.setProperty("--present", "present value");
@@ -38,11 +37,64 @@
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");
- return new PropertiesCommandLine(root, props, '|');
+ 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();
- public void testToMakeEclipseSpotTheTestCase() {
+ 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: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ArgumentTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ArgumentTest.java?rev=293045&r1=293044&r2=293045&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ArgumentTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/option/ArgumentTest.java Sat Oct 1 16:57:10 2005
@@ -591,10 +591,14 @@
bounds.process(commandLine, iterator);
+ // test with values
List values = new ArrayList();
values.add("50");
values.add("100");
assertEquals(values, commandLine.getValues(bounds, values));
+
+ // test without values
+ assertEquals(Collections.EMPTY_LIST, commandLine.getValues(bounds, null));
}
public void testProcess_StripBoundaryQuotes()
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org