01: package org.incava.jagol;
02:
03: import java.io.*;
04: import java.util.*;
05: import junit.framework.TestCase;
06:
07: public class TestBooleanOption extends TestCase {
08: BooleanOption opt = new BooleanOption("boolopt",
09: "this is the description of boolopt");
10:
11: public TestBooleanOption(String name) {
12: super (name);
13: }
14:
15: public void testDefaultNull() {
16: assertEquals("boolopt", opt.getLongName());
17: assertEquals("this is the description of boolopt", opt
18: .getDescription());
19:
20: assertNull("default value", opt.getValue());
21: }
22:
23: public void testDefaultValue() {
24: BooleanOption opt = new BooleanOption("boolopt",
25: "this is the description of boolopt", Boolean.TRUE);
26: assertEquals("default value", Boolean.TRUE, opt.getValue());
27: }
28:
29: public void testShortName() {
30: opt.setShortName('n');
31: assertEquals('n', opt.getShortName());
32: }
33:
34: public void testSetBooleanValue() {
35: opt.setValue(Boolean.TRUE);
36: assertEquals("option value", Boolean.TRUE, opt.getValue());
37:
38: opt.setValue(Boolean.FALSE);
39: assertEquals("option value", Boolean.FALSE, opt.getValue());
40: }
41:
42: public void testSetFromArgsListPositive() {
43: List args = new ArrayList();
44: try {
45: boolean processed = opt.set("--boolopt", args);
46: assertEquals("option processed", true, processed);
47: assertEquals("option value", Boolean.TRUE, opt.getValue());
48: assertEquals("argument removed from list", 0, args.size());
49: } catch (OptionException ite) {
50: fail("failure is not an option");
51: }
52: }
53:
54: public void testSetFromArgsListNegativeDash() {
55: List args = new ArrayList();
56: try {
57: boolean processed = opt.set("--no-boolopt", args);
58: assertEquals("option processed", true, processed);
59: assertEquals("option value", Boolean.FALSE, opt.getValue());
60: assertEquals("argument removed from list", 0, args.size());
61: } catch (OptionException ite) {
62: fail("failure is not an option");
63: }
64: }
65:
66: public void testSetFromArgsListNegativeNoDash() {
67: List args = new ArrayList();
68: try {
69: boolean processed = opt.set("--noboolopt", args);
70: assertEquals("option processed", true, processed);
71: assertEquals("option value", Boolean.FALSE, opt.getValue());
72: assertEquals("argument removed from list", 0, args.size());
73: } catch (OptionException ite) {
74: fail("failure is not an option");
75: }
76: }
77:
78: }
|