KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.incava.jagol;
2
3 import java.io.*;
4 import java.util.*;
5 import junit.framework.TestCase;
6
7
8 public class TestIntegerOption extends TestCase
9 {
10     IntegerOption opt = new IntegerOption("intopt", "this is the description of intopt");
11
12     public TestIntegerOption(String JavaDoc name)
13     {
14         super(name);
15     }
16
17     public void testDefaultNull()
18     {
19         assertEquals("intopt", opt.getLongName());
20         assertEquals("this is the description of intopt", opt.getDescription());
21
22         assertNull("default value", opt.getValue());
23     }
24
25     public void testDefaultValue()
26     {
27         IntegerOption opt = new IntegerOption("intopt", "this is the description of intopt", new Integer JavaDoc(1012));
28         assertEquals("default value", new Integer JavaDoc(1012), opt.getValue());
29     }
30     
31     public void testSetIntegerValue()
32     {
33         opt.setValue(new Integer JavaDoc(14));
34         assertEquals("option value", new Integer JavaDoc(14), opt.getValue());
35     }
36
37     public void testSetInvalidValueString()
38     {
39         try {
40             opt.setValue("fred");
41             fail("exception expected");
42         }
43         catch (InvalidTypeException ite) {
44         }
45     }
46
47     public void testSetInvalidValueFloatingPoint()
48     {
49         try {
50             opt.setValue("1.4");
51             fail("exception expected");
52         }
53         catch (InvalidTypeException ite) {
54         }
55     }
56
57     public void testSetValidValueNegative()
58     {
59         try {
60             opt.setValue("-987");
61             assertEquals("option value", new Integer JavaDoc(-987), opt.getValue());
62         }
63         catch (InvalidTypeException ite) {
64             fail("exception not expected");
65         }
66     }
67
68     public void testSetFromArgsListEqual()
69     {
70         List args = new ArrayList();
71         try {
72             boolean processed = opt.set("--intopt=444", args);
73             assertEquals("option processed", true, processed);
74             assertEquals("option value", new Integer JavaDoc(444), opt.getValue());
75             assertEquals("argument removed from list", 0, args.size());
76         }
77         catch (OptionException ite) {
78             fail("failure is not an option");
79         }
80     }
81
82     public void testSetFromArgsListSeparateString()
83     {
84         List args = new ArrayList();
85         args.add("41");
86         try {
87             boolean processed = opt.set("--intopt", args);
88             assertEquals("option processed", true, processed);
89             assertEquals("option value", new Integer JavaDoc(41), opt.getValue());
90             assertEquals("argument removed from list", 0, args.size());
91         }
92         catch (OptionException ite) {
93             fail("failure is not an option");
94         }
95     }
96
97     public void testSetFromLongerArgsListEqual()
98     {
99         List args = new ArrayList();
100         args.add("--anotheropt");
101         try {
102             boolean processed = opt.set("--intopt=666", args);
103             assertEquals("option processed", true, processed);
104             assertEquals("option value", new Integer JavaDoc(666), opt.getValue());
105             assertEquals("argument removed from list", 1, args.size());
106         }
107         catch (OptionException ite) {
108             fail("failure is not an option");
109         }
110     }
111
112     public void testSetFromLongerArgsListSeparateString()
113     {
114         List args = new ArrayList();
115         args.add("1234");
116         args.add("--anotheropt");
117         try {
118             boolean processed = opt.set("--intopt", args);
119             assertEquals("option processed", true, processed);
120             assertEquals("option value", new Integer JavaDoc(1234), opt.getValue());
121             assertEquals("argument removed from list", 1, args.size());
122         }
123         catch (OptionException ite) {
124             fail("failure is not an option");
125         }
126     }
127
128     public void testSetInvalidValueDanglingEquals()
129     {
130         List args = new ArrayList();
131         args.add("--anotheropt");
132         try {
133             boolean processed = opt.set("--intopt=", args);
134             fail("exception expected");
135         }
136         catch (OptionException ite) {
137         }
138     }
139
140 }
141
Popular Tags