001: package org.incava.jagol;
002:
003: import java.io.*;
004: import java.util.*;
005: import junit.framework.TestCase;
006:
007: public class TestStringOption extends TestCase {
008: StringOption opt = new StringOption("stropt",
009: "this is the description of stropt");
010:
011: public TestStringOption(String name) {
012: super (name);
013: }
014:
015: public void testDefaultNull() {
016: assertEquals("stropt", opt.getLongName());
017: assertEquals("this is the description of stropt", opt
018: .getDescription());
019:
020: assertNull("default value", opt.getValue());
021: }
022:
023: public void testDefaultValue() {
024: StringOption opt = new StringOption("stropt",
025: "this is the description of stropt", "defval");
026: assertEquals("default value", "defval", opt.getValue());
027: }
028:
029: public void testShortName() {
030: opt.setShortName('d');
031: assertEquals('d', opt.getShortName());
032: }
033:
034: public void testSetStringValue() {
035: opt.setValue("krisiun");
036: assertEquals("option value", "krisiun", opt.getValue());
037: }
038:
039: public void testSetFromArgsListEqual() {
040: List args = new ArrayList();
041: try {
042: boolean processed = opt.set("--stropt=hecate", args);
043: assertEquals("option processed", true, processed);
044: assertEquals("option value", "hecate", opt.getValue());
045: assertEquals("argument removed from list", 0, args.size());
046: } catch (OptionException ite) {
047: fail("failure is not an option");
048: }
049: }
050:
051: public void testSetFromArgsListSeparateString() {
052: List args = new ArrayList();
053: args.add("opeth");
054: try {
055: boolean processed = opt.set("--stropt", args);
056: assertEquals("option processed", true, processed);
057: assertEquals("option value", "opeth", opt.getValue());
058: assertEquals("argument removed from list", 0, args.size());
059: } catch (OptionException ite) {
060: fail("failure is not an option");
061: }
062: }
063:
064: public void testSetFromLongerArgsListEqual() {
065: List args = new ArrayList();
066: args.add("--anotheropt");
067: try {
068: boolean processed = opt.set("--stropt=vader", args);
069: assertEquals("option processed", true, processed);
070: assertEquals("option value", "vader", opt.getValue());
071: assertEquals("argument removed from list", 1, args.size());
072: } catch (OptionException ite) {
073: fail("failure is not an option");
074: }
075: }
076:
077: public void testSetFromLongerArgsListSeparateString() {
078: List args = new ArrayList();
079: args.add("wham");
080: args.add("--anotheropt");
081: try {
082: boolean processed = opt.set("--stropt", args);
083: assertEquals("option processed", true, processed);
084: assertEquals("option value", "wham", opt.getValue());
085: assertEquals("argument removed from list", 1, args.size());
086: } catch (OptionException ite) {
087: fail("failure is not an option");
088: }
089: }
090:
091: public void testSetInvalidValueDanglingEquals() {
092: List args = new ArrayList();
093: args.add("--anotheropt");
094: try {
095: boolean processed = opt.set("--stropt=", args);
096: fail("exception expected");
097: } catch (OptionException ite) {
098: }
099: }
100:
101: }
|