1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.tags;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import junit.framework.TestCase;
23
24 import org.seasar.cubby.action.ActionErrors;
25
26 public class TagUtilsTest extends TestCase {
27
28 public void testConstructor() throws Throwable {
29 new TagUtils();
30 assertTrue("Test call resulted in expected outcome", true);
31 }
32
33 @SuppressWarnings("unchecked")
34 public void testAddClassName() throws Throwable {
35 Map dyn = new HashMap(100, 100.0F);
36 dyn.put("class", "testString");
37 TagUtils.addClassName(dyn, "testTagUtilsClassName");
38 assertEquals("(HashMap) dyn.get(\"class\")", "testString testTagUtilsClassName", dyn.get("class"));
39 }
40
41 @SuppressWarnings("unchecked")
42 public void testAddClassName1() throws Throwable {
43 Map dyn = new HashMap(100, 100.0F);
44 TagUtils.addClassName(dyn, "testTagUtilsClassName");
45 assertEquals("(HashMap) dyn.size()", 1, dyn.size());
46 assertEquals("(HashMap) dyn.get(\"class\")", "testTagUtilsClassName", dyn.get("class"));
47 }
48
49 public void testErrors() throws Throwable {
50 ActionErrors result = TagUtils.errors(new MockJspContext());
51 assertNull("result", result);
52 }
53
54 @SuppressWarnings("unchecked")
55 public void testFormValue() throws Throwable {
56 Integer specifiedValue = new Integer(-2);
57 Integer result = (Integer) TagUtils.formValue(new MockJspContext(), new HashMap(100, 100.0F), "testTagUtilsName", new Integer(2), specifiedValue);
58 assertSame("result", specifiedValue, result);
59 }
60
61 @SuppressWarnings("unchecked")
62 public void testFormValue1() throws Throwable {
63 String[] strings = new String[3];
64 strings[0] = "testString";
65 Map outputValuesMap = new HashMap(100, 100.0F);
66 outputValuesMap.put("testString", strings);
67 String result = (String) TagUtils.formValue(new MockJspContext(), outputValuesMap, "testString", new Integer(0), null);
68 assertEquals("result", "testString", result);
69 }
70
71 @SuppressWarnings("unchecked")
72 public void testFormValue2() throws Throwable {
73 Integer specifiedValue = new Integer(0);
74 Integer result = (Integer) TagUtils.formValue(new MockJspContext(), new HashMap(100, 100.0F), "testTagUtilsName", new Integer(0), specifiedValue);
75 assertSame("result", specifiedValue, result);
76 }
77
78 @SuppressWarnings("unchecked")
79 public void testFormValue3() throws Throwable {
80 String result = (String) TagUtils.formValue(new MockJspContext(), new HashMap(100, 100.0F), "testTagUtilsName", new Integer(1), null);
81 assertEquals("result", "", result);
82 }
83
84 @SuppressWarnings("unchecked")
85 public void testFormValue4() throws Throwable {
86 String result = (String) TagUtils.formValue(new MockJspContext(), new HashMap(100, 100.0F), "testTagUtilsName", null, null);
87 assertEquals("result", "", result);
88 }
89
90 @SuppressWarnings("unchecked")
91 public void testFormValue5() throws Throwable {
92 Boolean specifiedValue = Boolean.FALSE;
93 Boolean result = (Boolean) TagUtils.formValue(new MockJspContext(), new HashMap(100, 100.0F), "testTagUtilsName", new Integer(-1), specifiedValue);
94 assertSame("result", specifiedValue, result);
95 }
96
97 @SuppressWarnings("unchecked")
98 public void testFormValue6() throws Throwable {
99 String[] strings = new String[3];
100 Map outputValuesMap = new HashMap(100, 100.0F);
101 outputValuesMap.put("testString", strings);
102 Object result = TagUtils.formValue(new MockJspContext(), outputValuesMap, "testString", new Integer(0), null);
103 assertNull("result", result);
104 }
105
106 public void testIsChecked() throws Throwable {
107 Object[] values = new Object[1];
108 values[0] = "";
109 boolean result = TagUtils.contains(values, "testTagUtilsValue");
110 assertFalse("result", result);
111 }
112
113 @SuppressWarnings("unchecked")
114 public void testIsChecked1() throws Throwable {
115 boolean result = TagUtils.contains(new ArrayList(100), "testTagUtilsValue");
116 assertFalse("result", result);
117 }
118
119 public void testIsChecked2() throws Throwable {
120 Object[] values = new Object[2];
121 values[1] = "testString";
122 boolean result = TagUtils.contains(values, "testString");
123 assertTrue("result", result);
124 }
125
126 public void testIsChecked3() throws Throwable {
127 Object[] values = new Object[0];
128 boolean result = TagUtils.contains(values, "testTagUtilsValue");
129 assertFalse("result", result);
130 }
131
132 public void testIsChecked4() throws Throwable {
133 Object[] values = new Object[3];
134 values[0] = "";
135 boolean result = TagUtils.contains(values, "");
136 assertTrue("result", result);
137 }
138
139 public void testIsChecked5() throws Throwable {
140 boolean result = TagUtils.contains("testString", "testString");
141 assertTrue("result", result);
142 }
143
144 public void testIsChecked6() throws Throwable {
145 Object[] values = new Object[1];
146 boolean result = TagUtils.contains(values, "testTagUtilsValue");
147 assertFalse("result", result);
148 }
149
150 public void testIsChecked7() throws Throwable {
151 Object[] values = new Object[3];
152 values[1] = new Integer(100);
153 boolean result = TagUtils.contains(values, "testTagUtilsValue");
154 assertFalse("result", result);
155 }
156
157 public void testIsChecked8() throws Throwable {
158 boolean result = TagUtils.contains(Boolean.FALSE, "testTagUtilsValue");
159 assertFalse("result", result);
160 }
161
162 public void testIsChecked9() throws Throwable {
163 Object[] values = new Object[4];
164 values[0] = "testString";
165 boolean result = TagUtils.contains(values, "testString");
166 assertTrue("result", result);
167 }
168
169 public void testIsChecked10() throws Throwable {
170 Object[] values = new Object[2];
171 values[0] = new Integer(-2);
172 values[1] = "testString";
173 boolean result = TagUtils.contains(values, "testString");
174 assertTrue("result", result);
175 }
176
177 @SuppressWarnings("unchecked")
178 public void testMultipleFormValues() throws Throwable {
179 String[] strings = new String[2];
180 Map outputValuesMap = new HashMap(100, 100.0F);
181 outputValuesMap.put("testString", strings);
182 String[] result = (String[]) TagUtils.multipleFormValues(new MockJspContext(), outputValuesMap, "testString", null);
183 assertSame("result", strings, result);
184 assertNull("strings[0]", strings[0]);
185 }
186
187 @SuppressWarnings("unchecked")
188 public void testMultipleFormValues1() throws Throwable {
189 Object[] result = TagUtils.multipleFormValues(new MockJspContext(), new HashMap(100, 100.0F), "testTagUtilsName", null);
190 assertEquals("result.length", 0, result.length);
191 }
192
193 @SuppressWarnings("unchecked")
194 public void testMultipleFormValues2() throws Throwable {
195 Object[] result = TagUtils.multipleFormValues(new MockJspContext(), new HashMap(100, 100.0F), "testTagUtilsName", "testTagUtilsCheckedValue");
196 assertEquals("result.length", 1, result.length);
197 assertEquals("result[0]", "testTagUtilsCheckedValue", result[0]);
198 }
199
200 public void testMultipleFormValues3() throws Throwable {
201 Object[] result = TagUtils.multipleFormValues(new MockJspContext(), null, "testTagUtilsName", null);
202 assertEquals("result.length", 0, result.length);
203 }
204
205 public void testMultipleFormValues4() throws Throwable {
206 Object[] result = TagUtils.multipleFormValues(new MockJspContext(), null, "testTagUtilsName");
207 assertEquals("result.length", 0, result.length);
208 }
209
210 @SuppressWarnings("unchecked")
211 public void testMultipleFormValues5() throws Throwable {
212 Map outputValuesMap = new HashMap(100, 100.0F);
213 String[] strings = new String[0];
214 outputValuesMap.put("testString", strings);
215 String[] result = (String[]) TagUtils.multipleFormValues(new MockJspContext(), outputValuesMap, "testString");
216 assertSame("result", strings, result);
217 }
218
219 @SuppressWarnings("unchecked")
220 public void testMultipleFormValues6() throws Throwable {
221 Object[] result = TagUtils.multipleFormValues(new MockJspContext(), new HashMap(100, 100.0F), "testTagUtilsName");
222 assertEquals("result.length", 0, result.length);
223 }
224
225 @SuppressWarnings("unchecked")
226 public void testMultipleFormValues7() throws Throwable {
227 Map outputValuesMap = new HashMap(100, 100.0F);
228 String[] strings = new String[3];
229 outputValuesMap.put("testString", strings);
230 String[] result = (String[]) TagUtils.multipleFormValues(new MockJspContext(), outputValuesMap, "testString");
231 assertSame("result", strings, result);
232 assertNull("strings[0]", strings[0]);
233 }
234
235 @SuppressWarnings("unchecked")
236 public void testOutputValues() throws Throwable {
237 Map result = TagUtils.outputValues(new MockJspContext());
238 assertNull("result", result);
239 }
240
241 @SuppressWarnings("unchecked")
242 public void testToAttr() throws Throwable {
243 String result = TagUtils.toAttr(new HashMap(100, 100.0F));
244 assertEquals("result", "", result);
245 }
246
247 @SuppressWarnings("unchecked")
248 public void testToAttr1() throws Throwable {
249 Map map = new HashMap(100, 100.0F);
250 map.put("testString", new Integer(-32));
251 String result = TagUtils.toAttr(map);
252 assertEquals("result", "testString=\"-32\" ", result);
253 }
254
255 public void testAddClassNameThrowsNullPointerException() throws Throwable {
256 try {
257 TagUtils.addClassName(null, "testTagUtilsClassName");
258 fail("Expected NullPointerException to be thrown");
259 } catch (NullPointerException ex) {
260 assertNull("ex.getMessage()", ex.getMessage());
261 }
262 }
263
264 public void testErrorsThrowsNullPointerException() throws Throwable {
265 try {
266 TagUtils.errors(null);
267 fail("Expected NullPointerException to be thrown");
268 } catch (NullPointerException ex) {
269 assertNull("ex.getMessage()", ex.getMessage());
270 }
271 }
272
273 public void testIsCheckedThrowsClassCastException() throws Throwable {
274 char[] values = new char[2];
275 try {
276 TagUtils.contains(values, "testTagUtilsValue");
277 fail("Expected ClassCastException to be thrown");
278 } catch (ClassCastException ex) {
279 assertEquals("ex.getClass()", ClassCastException.class, ex.getClass());
280 }
281 }
282
283 public void testIsCheckedThrowsNullPointerException() throws Throwable {
284 try {
285 TagUtils.contains(null, "testTagUtilsValue");
286 fail("Expected NullPointerException to be thrown");
287 } catch (NullPointerException ex) {
288 assertNull("ex.getMessage()", ex.getMessage());
289 }
290 }
291
292 public void testOutputValuesThrowsNullPointerException() throws Throwable {
293 try {
294 TagUtils.outputValues(null);
295 fail("Expected NullPointerException to be thrown");
296 } catch (NullPointerException ex) {
297 assertNull("ex.getMessage()", ex.getMessage());
298 }
299 }
300
301 public void testToAttrThrowsNullPointerException() throws Throwable {
302 try {
303 TagUtils.toAttr(null);
304 fail("Expected NullPointerException to be thrown");
305 } catch (NullPointerException ex) {
306 assertNull("ex.getMessage()", ex.getMessage());
307 }
308 }
309 }
310