001: package org.incava.jagol;
002:
003: import java.io.*;
004: import java.util.*;
005: import junit.framework.TestCase;
006:
007: public class TestIntegerOption extends TestCase {
008: IntegerOption opt = new IntegerOption("intopt",
009: "this is the description of intopt");
010:
011: public TestIntegerOption(String name) {
012: super (name);
013: }
014:
015: public void testDefaultNull() {
016: assertEquals("intopt", opt.getLongName());
017: assertEquals("this is the description of intopt", opt
018: .getDescription());
019:
020: assertNull("default value", opt.getValue());
021: }
022:
023: public void testDefaultValue() {
024: IntegerOption opt = new IntegerOption("intopt",
025: "this is the description of intopt", new Integer(1012));
026: assertEquals("default value", new Integer(1012), opt.getValue());
027: }
028:
029: public void testSetIntegerValue() {
030: opt.setValue(new Integer(14));
031: assertEquals("option value", new Integer(14), opt.getValue());
032: }
033:
034: public void testSetInvalidValueString() {
035: try {
036: opt.setValue("fred");
037: fail("exception expected");
038: } catch (InvalidTypeException ite) {
039: }
040: }
041:
042: public void testSetInvalidValueFloatingPoint() {
043: try {
044: opt.setValue("1.4");
045: fail("exception expected");
046: } catch (InvalidTypeException ite) {
047: }
048: }
049:
050: public void testSetValidValueNegative() {
051: try {
052: opt.setValue("-987");
053: assertEquals("option value", new Integer(-987), opt
054: .getValue());
055: } catch (InvalidTypeException ite) {
056: fail("exception not expected");
057: }
058: }
059:
060: public void testSetFromArgsListEqual() {
061: List args = new ArrayList();
062: try {
063: boolean processed = opt.set("--intopt=444", args);
064: assertEquals("option processed", true, processed);
065: assertEquals("option value", new Integer(444), opt
066: .getValue());
067: assertEquals("argument removed from list", 0, args.size());
068: } catch (OptionException ite) {
069: fail("failure is not an option");
070: }
071: }
072:
073: public void testSetFromArgsListSeparateString() {
074: List args = new ArrayList();
075: args.add("41");
076: try {
077: boolean processed = opt.set("--intopt", args);
078: assertEquals("option processed", true, processed);
079: assertEquals("option value", new Integer(41), opt
080: .getValue());
081: assertEquals("argument removed from list", 0, args.size());
082: } catch (OptionException ite) {
083: fail("failure is not an option");
084: }
085: }
086:
087: public void testSetFromLongerArgsListEqual() {
088: List args = new ArrayList();
089: args.add("--anotheropt");
090: try {
091: boolean processed = opt.set("--intopt=666", args);
092: assertEquals("option processed", true, processed);
093: assertEquals("option value", new Integer(666), opt
094: .getValue());
095: assertEquals("argument removed from list", 1, args.size());
096: } catch (OptionException ite) {
097: fail("failure is not an option");
098: }
099: }
100:
101: public void testSetFromLongerArgsListSeparateString() {
102: List args = new ArrayList();
103: args.add("1234");
104: args.add("--anotheropt");
105: try {
106: boolean processed = opt.set("--intopt", args);
107: assertEquals("option processed", true, processed);
108: assertEquals("option value", new Integer(1234), opt
109: .getValue());
110: assertEquals("argument removed from list", 1, args.size());
111: } catch (OptionException ite) {
112: fail("failure is not an option");
113: }
114: }
115:
116: public void testSetInvalidValueDanglingEquals() {
117: List args = new ArrayList();
118: args.add("--anotheropt");
119: try {
120: boolean processed = opt.set("--intopt=", args);
121: fail("exception expected");
122: } catch (OptionException ite) {
123: }
124: }
125:
126: }
|