KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > incava > jagol > TestStringOption


1 package org.incava.jagol;
2
3 import java.io.*;
4 import java.util.*;
5 import junit.framework.TestCase;
6
7
8 public class TestStringOption extends TestCase
9 {
10     StringOption opt = new StringOption("stropt", "this is the description of stropt");
11
12     public TestStringOption(String JavaDoc name)
13     {
14         super(name);
15     }
16
17     public void testDefaultNull()
18     {
19         assertEquals("stropt", opt.getLongName());
20         assertEquals("this is the description of stropt", opt.getDescription());
21
22         assertNull("default value", opt.getValue());
23     }
24
25     public void testDefaultValue()
26     {
27         StringOption opt = new StringOption("stropt", "this is the description of stropt", "defval");
28         assertEquals("default value", "defval", opt.getValue());
29     }
30
31     public void testShortName()
32     {
33         opt.setShortName('d');
34         assertEquals('d', opt.getShortName());
35     }
36
37     public void testSetStringValue()
38     {
39         opt.setValue("krisiun");
40         assertEquals("option value", "krisiun", opt.getValue());
41     }
42
43     public void testSetFromArgsListEqual()
44     {
45         List args = new ArrayList();
46         try {
47             boolean processed = opt.set("--stropt=hecate", args);
48             assertEquals("option processed", true, processed);
49             assertEquals("option value", "hecate", opt.getValue());
50             assertEquals("argument removed from list", 0, args.size());
51         }
52         catch (OptionException ite) {
53             fail("failure is not an option");
54         }
55     }
56
57     public void testSetFromArgsListSeparateString()
58     {
59         List args = new ArrayList();
60         args.add("opeth");
61         try {
62             boolean processed = opt.set("--stropt", args);
63             assertEquals("option processed", true, processed);
64             assertEquals("option value", "opeth", opt.getValue());
65             assertEquals("argument removed from list", 0, args.size());
66         }
67         catch (OptionException ite) {
68             fail("failure is not an option");
69         }
70     }
71
72     public void testSetFromLongerArgsListEqual()
73     {
74         List args = new ArrayList();
75         args.add("--anotheropt");
76         try {
77             boolean processed = opt.set("--stropt=vader", args);
78             assertEquals("option processed", true, processed);
79             assertEquals("option value", "vader", opt.getValue());
80             assertEquals("argument removed from list", 1, args.size());
81         }
82         catch (OptionException ite) {
83             fail("failure is not an option");
84         }
85     }
86
87     public void testSetFromLongerArgsListSeparateString()
88     {
89         List args = new ArrayList();
90         args.add("wham");
91         args.add("--anotheropt");
92         try {
93             boolean processed = opt.set("--stropt", args);
94             assertEquals("option processed", true, processed);
95             assertEquals("option value", "wham", opt.getValue());
96             assertEquals("argument removed from list", 1, args.size());
97         }
98         catch (OptionException ite) {
99             fail("failure is not an option");
100         }
101     }
102
103     public void testSetInvalidValueDanglingEquals()
104     {
105         List args = new ArrayList();
106         args.add("--anotheropt");
107         try {
108             boolean processed = opt.set("--stropt=", args);
109             fail("exception expected");
110         }
111         catch (OptionException ite) {
112         }
113     }
114
115 }
116
Popular Tags