1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.beanutils.locale.converters;
19
20
21
22
23
24
25
26
27
28 public class IntegerLocaleConverterTestCase extends BaseLocaleConverterTestCase {
29
30
31
32
33
34 public IntegerLocaleConverterTestCase(String name) {
35 super(name);
36 }
37
38
39
40
41
42
43 public void setUp() throws Exception {
44
45 super.setUp();
46
47 defaultValue = new Integer("999");
48 expectedValue = new Integer(expectedIntegerValue);
49
50 }
51
52
53
54
55 public void tearDown() {
56 super.tearDown();
57 }
58
59
60
61
62
63
64
65 public void testConstructorMain() {
66
67
68 converter = new IntegerLocaleConverter(defaultValue,
69 localizedLocale,
70 localizedIntegerPattern,
71 true);
72
73
74 convertValueNoPattern(converter, "(A)", localizedIntegerValue, expectedValue);
75 convertValueWithPattern(converter, "(A)", localizedIntegerValue, localizedIntegerPattern, expectedValue);
76 convertInvalid(converter, "(A)", defaultValue);
77 convertNull(converter, "(A)", defaultValue);
78
79
80
81
82
83
84
85
86 convertValueNoPattern(converter, "(B)", defaultIntegerValue, new Integer("1"));
87
88
89
90
91
92
93
94
95 convertValueWithPattern(converter, "(B)", localizedIntegerValue, defaultIntegerPattern, new Integer("1"));
96
97
98
99
100
101
102
103
104
105 convertValueToType(converter, "(B)", Double.class, localizedIntegerValue, localizedIntegerPattern, expectedValue);
106
107
108
109 converter = new IntegerLocaleConverter(defaultValue,
110 localizedLocale,
111 defaultIntegerPattern,
112 false);
113
114
115 convertValueNoPattern(converter, "(C)", localizedIntegerValue, expectedValue);
116 convertValueWithPattern(converter, "(C)", localizedIntegerValue, defaultIntegerPattern, expectedValue);
117 convertInvalid(converter, "(C)", defaultValue);
118 convertNull(converter, "(C)", defaultValue);
119
120 }
121
122
123
124
125
126
127
128 public void testConstructor_2() {
129
130
131 converter = new IntegerLocaleConverter();
132
133
134 convertValueNoPattern(converter, defaultIntegerValue, expectedValue);
135 convertValueWithPattern(converter, defaultIntegerValue, defaultIntegerPattern, expectedValue);
136 convertInvalid(converter, null);
137 convertNull(converter, null);
138
139 }
140
141
142
143
144
145
146
147 public void testConstructor_3() {
148
149
150 converter = new IntegerLocaleConverter(true);
151
152
153 convertValueNoPattern(converter, defaultIntegerValue, expectedValue);
154 convertValueWithPattern(converter, defaultIntegerValue, defaultIntegerPattern, expectedValue);
155 convertInvalid(converter, null);
156 convertNull(converter, null);
157
158
159 }
160
161
162
163
164 public void testConstructor_4() {
165
166
167 converter = new IntegerLocaleConverter(localizedLocale);
168
169
170 convertValueNoPattern(converter, localizedIntegerValue, expectedValue);
171 convertValueWithPattern(converter, localizedIntegerValue, defaultIntegerPattern, expectedValue);
172 convertInvalid(converter, null);
173 convertNull(converter, null);
174
175
176 }
177
178
179
180
181
182 public void testConstructor_5() {
183
184
185 converter = new IntegerLocaleConverter(localizedLocale, true);
186
187
188 convertValueNoPattern(converter, localizedIntegerValue, expectedValue);
189 convertValueWithPattern(converter, localizedIntegerValue, localizedIntegerPattern, expectedValue);
190 convertInvalid(converter, null);
191 convertNull(converter, null);
192
193
194 }
195
196
197
198
199 public void testConstructor_6() {
200
201
202 converter = new IntegerLocaleConverter(localizedLocale, defaultIntegerPattern);
203
204
205 convertValueNoPattern(converter, localizedIntegerValue, expectedValue);
206 convertValueWithPattern(converter, localizedIntegerValue, defaultIntegerPattern, expectedValue);
207 convertInvalid(converter, null);
208 convertNull(converter, null);
209
210 }
211
212
213
214
215 public void testConstructor_7() {
216
217
218 converter = new IntegerLocaleConverter(localizedLocale, localizedIntegerPattern, true);
219
220
221 convertValueNoPattern(converter, localizedIntegerValue, expectedValue);
222 convertValueWithPattern(converter, localizedIntegerValue, localizedIntegerPattern, expectedValue);
223 convertInvalid(converter, null);
224 convertNull(converter, null);
225
226 }
227
228
229
230
231 public void testConstructor_8() {
232
233
234 converter = new IntegerLocaleConverter(defaultValue);
235
236
237 convertValueNoPattern(converter, defaultIntegerValue, expectedValue);
238 convertValueWithPattern(converter, defaultIntegerValue, defaultIntegerPattern, expectedValue);
239 convertInvalid(converter, defaultValue);
240 convertNull(converter, defaultValue);
241
242 }
243
244
245
246
247 public void testConstructor_9() {
248
249
250 converter = new IntegerLocaleConverter(defaultValue, true);
251
252
253 convertValueNoPattern(converter, defaultIntegerValue, expectedValue);
254 convertValueWithPattern(converter, defaultIntegerValue, defaultIntegerPattern, expectedValue);
255 convertInvalid(converter, defaultValue);
256 convertNull(converter, defaultValue);
257
258 }
259
260
261
262
263
264 public void testNumber() {
265
266
267 converter = new IntegerLocaleConverter(localizedLocale);
268
269 Integer value = new Integer(1234);
270 assertEquals("Convert Integer", value, converter.convert(value));
271 assertEquals("Convert Long", value, converter.convert(new Long(value.intValue())));
272 }
273
274
275 }
276