001: package org.incava.jagol;
002:
003: import java.io.*;
004: import java.util.*;
005: import junit.framework.TestCase;
006:
007: public class TestListOption extends TestCase {
008: ListOption opt = new ListOption("listopt",
009: "this is the description of listopt");
010:
011: public TestListOption(String name) {
012: super (name);
013: }
014:
015: public void testDefault() {
016: assertEquals("listopt", opt.getLongName());
017: assertEquals("this is the description of listopt", opt
018: .getDescription());
019:
020: assertEquals("default value", (new ArrayList()), opt.getValue());
021: }
022:
023: public void testShortName() {
024: opt.setShortName('d');
025: assertEquals('d', opt.getShortName());
026: }
027:
028: public void testSetListValue() {
029: List v = new ArrayList();
030: v.add("dimmu");
031: v.add("callendish");
032: v.add("charon");
033:
034: opt.setValue(v);
035: List values = opt.getValue();
036: assertNotNull("list", values);
037: assertEquals("list size", 3, values.size());
038: assertEquals("option value", v.get(0), values.get(0));
039: assertEquals("option value", v.get(1), values.get(1));
040: assertEquals("option value", v.get(2), values.get(2));
041: }
042:
043: public void testSetFromArgsListEqual() {
044: List args = new ArrayList();
045: try {
046: boolean processed = opt
047: .set("--listopt=fee,fi,fo,fum", args);
048: assertEquals("option processed", true, processed);
049: List values = opt.getValue();
050: assertEquals("list size", 4, values.size());
051: assertEquals("option value", "fee", values.get(0));
052: assertEquals("option value", "fi", values.get(1));
053: assertEquals("option value", "fo", values.get(2));
054: assertEquals("option value", "fum", values.get(3));
055: assertEquals("argument removed from list", 0, args.size());
056: } catch (OptionException ite) {
057: fail("failure is not an option");
058: }
059: }
060:
061: public void testSetFromArgsListSeparateList() {
062: List args = new ArrayList();
063: args.add("closing\nwinds");
064: try {
065: boolean processed = opt.set("--listopt", args);
066: assertEquals("option processed", true, processed);
067: List values = opt.getValue();
068: assertEquals("list size", 2, values.size());
069: assertEquals("option value", "closing", values.get(0));
070: assertEquals("option value", "winds", values.get(1));
071: assertEquals("argument removed from list", 0, args.size());
072: } catch (OptionException ite) {
073: fail("failure is not an option");
074: }
075: }
076:
077: public void testSetFromLongerArgsListEqual() {
078: List args = new ArrayList();
079: args.add("--anotheropt");
080: try {
081: boolean processed = opt.set("--listopt=ord", args);
082: assertEquals("option processed", true, processed);
083: List values = opt.getValue();
084: assertEquals("list size", 1, values.size());
085: assertEquals("option value", "ord", values.get(0));
086: assertEquals("argument removed from list", 1, args.size());
087: } catch (OptionException ite) {
088: fail("failure is not an option");
089: }
090: }
091:
092: public void testSetFromLongerArgsListSeparateList() {
093: List args = new ArrayList();
094: args.add("\"red blue\tgreen\"");
095: args.add("--anotheropt");
096: try {
097: boolean processed = opt.set("--listopt", args);
098: assertEquals("option processed", true, processed);
099: List values = opt.getValue();
100: assertEquals("list size", 3, values.size());
101: assertEquals("option value", "red", values.get(0));
102: assertEquals("option value", "blue", values.get(1));
103: assertEquals("option value", "green", values.get(2));
104: assertEquals("argument removed from list", 1, args.size());
105: } catch (OptionException ite) {
106: fail("failure is not an option");
107: }
108: }
109:
110: public void testSetInvalidValueDanglingEquals() {
111: List args = new ArrayList();
112: args.add("--anotheropt");
113: try {
114: boolean processed = opt.set("--listopt=", args);
115: fail("exception expected");
116: } catch (OptionException ite) {
117: }
118: }
119:
120: }
|