01: package org.incava.jagol;
02:
03: import java.io.*;
04: import java.util.*;
05: import junit.framework.TestCase;
06:
07: public class TestNonBooleanOption extends TestCase {
08: NonBooleanOption opt = new NonBooleanOption("nbopt",
09: "this is the description of nbopt") {
10: public void setValue(String value) throws InvalidTypeException {
11: }
12:
13: protected String getType() {
14: return "";
15: }
16: };
17:
18: public TestNonBooleanOption(String name) {
19: super (name);
20: }
21:
22: public void testSetFromArgsListEqual() {
23: List args = new ArrayList();
24: try {
25: boolean processed = opt.set("--nbopt=444", args);
26: assertEquals("option processed", true, processed);
27: assertEquals("argument removed from list", 0, args.size());
28: } catch (OptionException ite) {
29: fail("failure is not an option");
30: }
31: }
32:
33: public void testSetFromArgsListSeparateString() {
34: List args = new ArrayList();
35: args.add("41");
36: try {
37: boolean processed = opt.set("--nbopt", args);
38: assertEquals("option processed", true, processed);
39: assertEquals("argument removed from list", 0, args.size());
40: } catch (OptionException ite) {
41: fail("failure is not an option");
42: }
43: }
44:
45: public void testSetFromLongerArgsListEqual() {
46: List args = new ArrayList();
47: args.add("--anotheropt");
48: try {
49: boolean processed = opt.set("--nbopt=666", args);
50: assertEquals("option processed", true, processed);
51: assertEquals("argument removed from list", 1, args.size());
52: } catch (OptionException ite) {
53: fail("failure is not an option");
54: }
55: }
56:
57: public void testSetFromLongerArgsListSeparateString() {
58: List args = new ArrayList();
59: args.add("1234");
60: args.add("--anotheropt");
61: try {
62: boolean processed = opt.set("--nbopt", args);
63: assertEquals("option processed", true, processed);
64: assertEquals("argument removed from list", 1, args.size());
65: } catch (OptionException ite) {
66: fail("failure is not an option");
67: }
68: }
69:
70: public void testSetInvalidValueDanglingEquals() {
71: List args = new ArrayList();
72: args.add("--anotheropt");
73: try {
74: boolean processed = opt.set("--nbopt=", args);
75: fail("exception expected");
76: } catch (OptionException ite) {
77: }
78: }
79:
80: }
|