KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > bean > TestBeanUtil


1 package jodd.bean;
2
3 import java.math.BigDecimal;
4 import java.sql.Date;
5 import java.sql.Time;
6 import java.sql.Timestamp;
7 import java.util.HashMap;
8
9 import jodd.bean.modifiers.TrimStrings;
10 import junit.framework.TestCase;
11
12 public class TestBeanUtil extends TestCase {
13
14     public void testSetPropertyNumbers() {
15         FooBean fb = new FooBean();
16
17         // Integer
18
boolean valid;
19         String propName = "fooInteger";
20         valid = BeanUtil.setProperty(fb, propName, new Integer(1));
21         assertTrue(valid);
22         assertEquals(1, fb.getFooInteger().intValue());
23         valid = BeanUtil.setProperty(fb, propName, null);
24         assertTrue(valid);
25         assertNull(fb.getFooInteger());
26         valid = BeanUtil.setProperty(fb, propName, "2"); // valid string
27
assertTrue(valid);
28         assertEquals(2, fb.getFooInteger().intValue());
29         valid = BeanUtil.setProperty(fb, propName, "x"); // invalid string - value stays the same
30
assertFalse(valid);
31         assertEquals(2, fb.getFooInteger().intValue());
32
33         // int
34
propName = "fooint";
35         valid = BeanUtil.setProperty(fb, propName, new Integer(1));
36         assertTrue(valid);
37         assertEquals(1, fb.getFooint());
38         valid = BeanUtil.setProperty(fb, propName, null); // null is not an int
39
assertFalse(valid);
40         assertEquals(1, fb.getFooint());
41         valid = BeanUtil.setProperty(fb, propName, "2"); // valid string
42
assertTrue(valid);
43         assertEquals(2, fb.getFooint());
44         valid = BeanUtil.setProperty(fb, propName, "w"); // invalid string
45
assertFalse(valid);
46         assertEquals(2, fb.getFooint());
47
48         // Long
49
propName = "fooLong";
50         valid = BeanUtil.setProperty(fb, propName, new Long(1));
51         assertTrue(valid);
52         assertEquals(1L, fb.getFooLong().longValue());
53         valid = BeanUtil.setProperty(fb, propName, new Integer(3));
54         assertTrue(valid);
55         assertEquals(3L, fb.getFooLong().longValue());
56         valid = BeanUtil.setProperty(fb, propName, null);
57         assertTrue(valid);
58         assertNull(fb.getFooLong());
59         valid = BeanUtil.setProperty(fb, propName, "2"); // valid string
60
assertTrue(valid);
61         assertEquals(2L, fb.getFooLong().longValue());
62         valid = BeanUtil.setProperty(fb, propName, "x"); // invalid string - value stays the same
63
assertFalse(valid);
64         assertEquals(2L, fb.getFooLong().longValue());
65
66         // long
67
propName = "foolong";
68         valid = BeanUtil.setProperty(fb, propName, new Long(1));
69         assertTrue(valid);
70         assertEquals(1L, fb.getFoolong());
71         valid = BeanUtil.setProperty(fb, propName, new Integer(3));
72         assertTrue(valid);
73         assertEquals(3L, fb.getFoolong());
74         valid = BeanUtil.setProperty(fb, propName, null); // null is not a long
75
assertFalse(valid);
76         assertEquals(3L, fb.getFoolong());
77         valid = BeanUtil.setProperty(fb, propName, "2"); // valid string
78
assertTrue(valid);
79         assertEquals(2L, fb.getFoolong());
80         valid = BeanUtil.setProperty(fb, propName, "w"); // invalid string
81
assertFalse(valid);
82         assertEquals(2L, fb.getFoolong());
83
84         // Byte
85
propName = "fooByte";
86         valid = BeanUtil.setProperty(fb, propName, new Byte((byte) 1));
87         assertTrue(valid);
88         assertEquals(1, fb.getFooByte().byteValue());
89         valid = BeanUtil.setProperty(fb, propName, new Integer(3));
90         assertTrue(valid);
91         assertEquals(3, fb.getFooByte().byteValue());
92         valid = BeanUtil.setProperty(fb, propName, new Integer(257));
93         assertTrue(valid);
94         assertEquals(1, fb.getFooByte().byteValue()); // lower byte of 257
95
valid = BeanUtil.setProperty(fb, propName, null);
96         assertTrue(valid);
97         assertNull(fb.getFooByte());
98         valid = BeanUtil.setProperty(fb, propName, "2"); // valid string
99
assertTrue(valid);
100         assertEquals(2, fb.getFooByte().byteValue());
101         valid = BeanUtil.setProperty(fb, propName, "x"); // invalid string - value stays the same
102
assertFalse(valid);
103         assertEquals(2, fb.getFooByte().byteValue());
104
105         // byte
106
propName = "foobyte";
107         valid = BeanUtil.setProperty(fb, propName, new Byte((byte) 1));
108         assertTrue(valid);
109         assertEquals(1, fb.getFoobyte());
110         valid = BeanUtil.setProperty(fb, propName, new Integer(3));
111         assertTrue(valid);
112         assertEquals(3, fb.getFoobyte());
113         valid = BeanUtil.setProperty(fb, propName, new Integer(257));
114         assertTrue(valid);
115         assertEquals(1, fb.getFoobyte());
116         valid = BeanUtil.setProperty(fb, propName, null); // null is not a byte
117
assertFalse(valid);
118         assertEquals(1, fb.getFoobyte());
119         valid = BeanUtil.setProperty(fb, propName, "2"); // valid string
120
assertTrue(valid);
121         assertEquals(2, fb.getFoobyte());
122         valid = BeanUtil.setProperty(fb, propName, "x"); // invalid string - value stays the same
123
assertFalse(valid);
124         assertEquals(2, fb.getFoobyte());
125
126         // Boolean
127
propName = "fooBoolean";
128         valid = BeanUtil.setProperty(fb, propName, Boolean.TRUE);
129         assertTrue(valid);
130         assertEquals(true, fb.getFooBoolean().booleanValue());
131         valid = BeanUtil.setProperty(fb, propName, new Boolean(false));
132         assertTrue(valid);
133         assertEquals(false, fb.getFooBoolean().booleanValue());
134         valid = BeanUtil.setProperty(fb, propName, null);
135         assertTrue(valid);
136         assertNull(fb.getFooBoolean());
137         valid = BeanUtil.setProperty(fb, propName, "yes");
138         assertTrue(valid);
139         assertEquals(true, fb.getFooBoolean().booleanValue());
140         valid = BeanUtil.setProperty(fb, propName, "y");
141         assertTrue(valid);
142         assertEquals(true, fb.getFooBoolean().booleanValue());
143         valid = BeanUtil.setProperty(fb, propName, "true");
144         assertTrue(valid);
145         assertEquals(true, fb.getFooBoolean().booleanValue());
146         valid = BeanUtil.setProperty(fb, propName, "on");
147         assertTrue(valid);
148         assertEquals(true, fb.getFooBoolean().booleanValue());
149         valid = BeanUtil.setProperty(fb, propName, "1");
150         assertTrue(valid);
151         assertEquals(true, fb.getFooBoolean().booleanValue());
152         valid = BeanUtil.setProperty(fb, propName, "no");
153         assertTrue(valid);
154         assertEquals(false, fb.getFooBoolean().booleanValue());
155         valid = BeanUtil.setProperty(fb, propName, "n");
156         assertTrue(valid);
157         assertEquals(false, fb.getFooBoolean().booleanValue());
158         valid = BeanUtil.setProperty(fb, propName, "false");
159         assertTrue(valid);
160         assertEquals(false, fb.getFooBoolean().booleanValue());
161         valid = BeanUtil.setProperty(fb, propName, "off");
162         assertTrue(valid);
163         assertEquals(false, fb.getFooBoolean().booleanValue());
164         valid = BeanUtil.setProperty(fb, propName, "0");
165         assertTrue(valid);
166         assertEquals(false, fb.getFooBoolean().booleanValue());
167
168         // boolean
169
propName = "fooboolean";
170         valid = BeanUtil.setProperty(fb, propName, Boolean.TRUE);
171         assertTrue(valid);
172         assertEquals(true, fb.getFooboolean());
173         valid = BeanUtil.setProperty(fb, propName, new Boolean(false));
174         assertTrue(valid);
175         assertEquals(false, fb.getFooboolean());
176         valid = BeanUtil.setProperty(fb, propName, null);
177         assertFalse(valid);
178         assertEquals(false, fb.getFooboolean());
179         valid = BeanUtil.setProperty(fb, propName, "yes");
180         assertTrue(valid);
181         assertEquals(true, fb.getFooboolean());
182         valid = BeanUtil.setProperty(fb, propName, "y");
183         assertTrue(valid);
184         assertEquals(true, fb.getFooboolean());
185         valid = BeanUtil.setProperty(fb, propName, "true");
186         assertTrue(valid);
187         assertEquals(true, fb.getFooboolean());
188         valid = BeanUtil.setProperty(fb, propName, "on");
189         assertTrue(valid);
190         assertEquals(true, fb.getFooboolean());
191         valid = BeanUtil.setProperty(fb, propName, "1");
192         assertTrue(valid);
193         assertEquals(true, fb.getFooboolean());
194         valid = BeanUtil.setProperty(fb, propName, "no");
195         assertTrue(valid);
196         assertEquals(false, fb.getFooboolean());
197         valid = BeanUtil.setProperty(fb, propName, "n");
198         assertTrue(valid);
199         assertEquals(false, fb.getFooboolean());
200         valid = BeanUtil.setProperty(fb, propName, "false");
201         assertTrue(valid);
202         assertEquals(false, fb.getFooboolean());
203         valid = BeanUtil.setProperty(fb, propName, "off");
204         assertTrue(valid);
205         assertEquals(false, fb.getFooboolean());
206         valid = BeanUtil.setProperty(fb, propName, "0");
207         assertTrue(valid);
208         assertEquals(false, fb.getFooboolean());
209
210         // Float
211
propName = "fooFloat";
212         valid = BeanUtil.setProperty(fb, propName, new Float(1.1));
213         assertTrue(valid);
214         assertEquals(1.1, fb.getFooFloat().floatValue(), 0.0005);
215         valid = BeanUtil.setProperty(fb, propName, new Integer(3));
216         assertTrue(valid);
217         assertEquals(3.0, fb.getFooFloat().floatValue(), 0.0005);
218         valid = BeanUtil.setProperty(fb, propName, null);
219         assertTrue(valid);
220         assertNull(fb.getFooFloat());
221         valid = BeanUtil.setProperty(fb, propName, "2.2"); // valid string
222
assertTrue(valid);
223         assertEquals(2.2, fb.getFooFloat().floatValue(), 0.0005);
224         valid = BeanUtil.setProperty(fb, propName, "x"); // invalid string - value stays the same
225
assertFalse(valid);
226         assertEquals(2.2, fb.getFooFloat().floatValue(), 0.0005);
227
228         // float
229
propName = "foofloat";
230         valid = BeanUtil.setProperty(fb, propName, new Float(1.1));
231         assertTrue(valid);
232         assertEquals(1.1, fb.getFoofloat(), 0.0005);
233         valid = BeanUtil.setProperty(fb, propName, new Integer(3));
234         assertTrue(valid);
235         assertEquals(3.0, fb.getFoofloat(), 0.0005);
236         valid = BeanUtil.setProperty(fb, propName, null); // null is not a long
237
assertFalse(valid);
238         assertEquals(3.0, fb.getFoofloat(), 0.0005);
239         valid = BeanUtil.setProperty(fb, propName, "2.2"); // valid string
240
assertTrue(valid);
241         assertEquals(2.2, fb.getFoofloat(), 0.0005);
242         valid = BeanUtil.setProperty(fb, propName, "w"); // invalid string
243
assertFalse(valid);
244         assertEquals(2.2, fb.getFoofloat(), 0.0005);
245
246
247         // Double
248
propName = "fooDouble";
249         valid = BeanUtil.setProperty(fb, propName, new Double(1.1));
250         assertTrue(valid);
251         assertEquals(1.1, fb.getFooDouble().doubleValue(), 0.0005);
252         valid = BeanUtil.setProperty(fb, propName, new Integer(3));
253         assertTrue(valid);
254         assertEquals(3.0, fb.getFooDouble().doubleValue(), 0.0005);
255         valid = BeanUtil.setProperty(fb, propName, null);
256         assertTrue(valid);
257         assertNull(fb.getFooDouble());
258         valid = BeanUtil.setProperty(fb, propName, "2.2"); // valid string
259
assertTrue(valid);
260         assertEquals(2.2, fb.getFooDouble().doubleValue(), 0.0005);
261         valid = BeanUtil.setProperty(fb, propName, "x"); // invalid string - value stays the same
262
assertFalse(valid);
263         assertEquals(2.2, fb.getFooDouble().doubleValue(), 0.0005);
264
265         // double
266
propName = "foodouble";
267         valid = BeanUtil.setProperty(fb, propName, new Double(1.1));
268         assertTrue(valid);
269         assertEquals(1.1, fb.getFoodouble(), 0.0005);
270         valid = BeanUtil.setProperty(fb, propName, new Integer(3));
271         assertTrue(valid);
272         assertEquals(3.0, fb.getFoodouble(), 0.0005);
273         valid = BeanUtil.setProperty(fb, propName, null); // null is not a long
274
assertFalse(valid);
275         assertEquals(3.0, fb.getFoodouble(), 0.0005);
276         valid = BeanUtil.setProperty(fb, propName, "2.2"); // valid string
277
assertTrue(valid);
278         assertEquals(2.2, fb.getFoodouble(), 0.0005);
279         valid = BeanUtil.setProperty(fb, propName, "w"); // invalid string
280
assertFalse(valid);
281         assertEquals(2.2, fb.getFoodouble(), 0.0005);
282     }
283
284
285     public void testSetPropertySql() {
286         FooBean2 fb = new FooBean2();
287
288         String propName = "fooTimestamp";
289         Timestamp ts = new Timestamp(101, 0, 17, 1, 2, 3, 4);
290         boolean valid = BeanUtil.setProperty(fb, propName, ts);
291         assertTrue(valid);
292         assertEquals("2001-01-17 01:02:03.000000004", fb.getFooTimestamp().toString());
293
294         propName = "fooTime";
295         Time t = new Time(17, 13, 15);
296         valid = BeanUtil.setProperty(fb, propName, t);
297         assertTrue(valid);
298         assertEquals("17:13:15", fb.getFooTime().toString());
299
300         propName = "fooDate";
301         Date d = new Date(101, 1, 17);
302         valid = BeanUtil.setProperty(fb, propName, d);
303         assertTrue(valid);
304         assertEquals("2001-02-17", fb.getFooDate().toString());
305     }
306
307
308     public void testSetPropertyMath() {
309         FooBean2 fb = new FooBean2();
310
311         String propName = "fooBigDecimal";
312         boolean valid = BeanUtil.setProperty(fb, propName, new BigDecimal(1.2));
313         assertTrue(valid);
314         assertEquals(1.2, fb.getFooBigDecimal().doubleValue(), 0.0005);
315     }
316
317     public void testSetPropertyString() {
318         FooBean fb = new FooBean();
319
320         // String
321
String propName = "fooString";
322         boolean valid = BeanUtil.setProperty(fb, propName, "string");
323         assertTrue(valid);
324         assertEquals("string", fb.getFooString());
325         valid = BeanUtil.setProperty(fb, propName, null);
326         assertTrue(valid);
327         assertNull(fb.getFooString());
328
329         // String array
330
propName = "fooStringA";
331         String[] sa = new String[] {"one", "two", "three"};
332         valid = BeanUtil.setProperty(fb, propName, sa);
333         assertTrue(valid);
334         assertEquals("one", fb.getFooStringA()[0]);
335         assertEquals("two", fb.getFooStringA()[1]);
336         assertEquals("three", fb.getFooStringA()[2]);
337
338         valid = BeanUtil.setProperty(fb, propName, "just a string");
339         assertTrue(valid);
340         sa = (String[]) BeanUtil.getProperty(fb, propName);
341         assertEquals(1, sa.length);
342         assertEquals("just a string", sa[0]);
343
344         // Character
345
propName = "fooCharacter";
346         valid = BeanUtil.setProperty(fb, propName, new Character('a'));
347         assertTrue(valid);
348         assertEquals('a', fb.getFooCharacter().charValue());
349         valid = BeanUtil.setProperty(fb, propName, new String("123"));
350         assertTrue(valid);
351         assertEquals('1', fb.getFooCharacter().charValue());
352         valid = BeanUtil.setProperty(fb, propName, new Integer(789));
353         assertTrue(valid);
354         assertEquals('7', fb.getFooCharacter().charValue());
355
356         // char
357
propName = "foochar";
358         valid = BeanUtil.setProperty(fb, propName, new Character('a'));
359         assertTrue(valid);
360         assertEquals('a', fb.getFoochar());
361         valid = BeanUtil.setProperty(fb, propName, new String("123"));
362         assertTrue(valid);
363         assertEquals('1', fb.getFoochar());
364         valid = BeanUtil.setProperty(fb, propName, new Integer(789));
365         assertTrue(valid);
366         assertEquals('7', fb.getFoochar());
367     }
368
369
370     public void testLoaders() {
371         HashMap map = new HashMap();
372         
373         map.put("fooInteger", new Integer(1));
374         map.put("fooint", new Integer(2));
375         map.put("fooLong", new Long(3));
376         map.put("foolong", new Long(4));
377         map.put("fooByte", new Byte((byte)5));
378         map.put("foobyte", new Byte((byte)6));
379         map.put("fooCharacter", new Character('7'));
380         map.put("foochar", new Character('8'));
381         map.put("fooBoolean", new Boolean(true));
382         map.put("fooboolean", new Boolean(false));
383         map.put("fooFloat", new Float(9.0));
384         map.put("foofloat", new Float(10.0));
385         map.put("fooDouble", new Double(11.0));
386         map.put("foodouble", new Double(12.0));
387         map.put("fooString", new String("13"));
388         map.put("fooStringA", new String[]{"14", "15"});
389
390         FooBean fb = new FooBean();
391         BeanUtil.load(fb, map);
392
393         assertEquals(1, fb.getFooInteger().intValue());
394         assertEquals(2, fb.getFooint());
395         assertEquals(3, fb.getFooLong().longValue());
396         assertEquals(4, fb.getFoolong());
397         assertEquals(5, fb.getFooByte().byteValue());
398         assertEquals(6, fb.getFoobyte());
399         assertEquals('7', fb.getFooCharacter().charValue());
400         assertEquals('8', fb.getFoochar());
401         assertTrue(fb.getFooBoolean().booleanValue());
402         assertFalse(fb.getFooboolean());
403         assertEquals(9.0, fb.getFooFloat().floatValue(), 0.005);
404         assertEquals(10.0, fb.getFoofloat(), 0.005);
405         assertEquals(11.0, fb.getFooDouble().doubleValue(), 0.005);
406         assertEquals(12.0, fb.getFoodouble(), 0.005);
407         assertEquals("13", fb.getFooString());
408         assertEquals("14", fb.getFooStringA()[0]);
409         assertEquals("15", fb.getFooStringA()[1]);
410     }
411
412     public void testForEach() {
413         FooBean fb = new FooBean();
414         fb.setFooString(" xxx ");
415         fb.setFooStringA(new String[] {" xxx ", " yy ", " z "});
416         BeanUtil.forEachProperty(fb, new TrimStrings());
417         assertEquals("xxx", fb.getFooString());
418         assertEquals("xxx", fb.getFooStringA()[0]);
419         assertEquals("yy", fb.getFooStringA()[1]);
420         assertEquals("z", fb.getFooStringA()[2]);
421     }
422
423
424     public void testGet() {
425         FooBean fb = new FooBean();
426         fb.setFooInteger(new Integer(101));
427         fb.setFooint(102);
428         fb.setFooLong(new Long(103));
429         fb.setFoolong(104);
430         fb.setFooByte(new Byte((byte) 105));
431         fb.setFoobyte((byte) 106);
432         fb.setFooCharacter(new Character('7'));
433         fb.setFoochar('8');
434         fb.setFooBoolean(new Boolean(true));
435         fb.setFooboolean(false);
436         fb.setFooFloat(new Float(109.0));
437         fb.setFoofloat((float)110.0);
438         fb.setFooDouble(new Double(111.0));
439         fb.setFoodouble(112.0);
440         fb.setFooString("113");
441         fb.setFooStringA(new String[] {"114", "115"} );
442
443         Integer v = (Integer) BeanUtil.getProperty(fb, "FooInteger");
444         assertEquals(101, v.intValue());
445         v = (Integer) BeanUtil.getProperty(fb, "Fooint");
446         assertEquals(102, v.intValue());
447         Long vl = (Long) BeanUtil.getProperty(fb, "FooLong");
448         assertEquals(103, vl.longValue());
449         vl = (Long) BeanUtil.getProperty(fb, "Foolong");
450         assertEquals(104, vl.longValue());
451         Byte vb = (Byte) BeanUtil.getProperty(fb, "FooByte");
452         assertEquals(105, vb.intValue());
453         vb = (Byte) BeanUtil.getProperty(fb, "Foobyte");
454         assertEquals(106, vb.intValue());
455         Character c = (Character) BeanUtil.getProperty(fb, "FooCharacter");
456         assertEquals('7', c.charValue());
457         c = (Character) BeanUtil.getProperty(fb, "Foochar");
458         assertEquals('8', c.charValue());
459         Boolean b = (Boolean) BeanUtil.getProperty(fb, "FooBoolean");
460         assertTrue(b.booleanValue());
461         b = (Boolean) BeanUtil.getProperty(fb, "Fooboolean");
462         assertFalse(b.booleanValue());
463         Float f = (Float) BeanUtil.getProperty(fb, "FooFloat");
464         assertEquals(109.0, f.floatValue(), 0.005);
465         f = (Float) BeanUtil.getProperty(fb, "Foofloat");
466         assertEquals(110.0, f.floatValue(), 0.005);
467         Double d = (Double) BeanUtil.getProperty(fb, "FooDouble");
468         assertEquals(111.0, d.doubleValue(), 0.005);
469         d = (Double) BeanUtil.getProperty(fb, "Foodouble");
470         assertEquals(112.0, d.doubleValue(), 0.005);
471         String s = (String) BeanUtil.getProperty(fb, "FooString");
472         assertEquals("113", s);
473         String[] sa = (String[]) BeanUtil.getProperty(fb, "FooStringA");
474         assertEquals(2, sa.length);
475         assertEquals("114", sa[0]);
476         assertEquals("115", sa[1]);
477
478     }
479
480
481     public void testCopy() {
482         FooBean fb = new FooBean();
483         fb.setFooInteger(new Integer(201));
484         fb.setFooint(202);
485         fb.setFooLong(new Long(203));
486         fb.setFoolong(204);
487         fb.setFooByte(new Byte((byte) 95));
488         fb.setFoobyte((byte) 96);
489         fb.setFooCharacter(new Character('7'));
490         fb.setFoochar('8');
491         fb.setFooBoolean(new Boolean(true));
492         fb.setFooboolean(false);
493         fb.setFooFloat(new Float(209.0));
494         fb.setFoofloat((float)210.0);
495         fb.setFooDouble(new Double(211.0));
496         fb.setFoodouble(212.0);
497         fb.setFooString("213");
498         fb.setFooStringA(new String[] {"214", "215"} );
499
500         FooBean dest = new FooBean();
501         BeanUtil.copyProperties(fb, dest);
502
503         Integer v = (Integer) BeanUtil.getProperty(dest, "FooInteger");
504         assertEquals(201, v.intValue());
505         v = (Integer) BeanUtil.getProperty(dest, "Fooint");
506         assertEquals(202, v.intValue());
507         Long vl = (Long) BeanUtil.getProperty(dest, "FooLong");
508         assertEquals(203, vl.longValue());
509         vl = (Long) BeanUtil.getProperty(dest, "Foolong");
510         assertEquals(204, vl.longValue());
511         Byte vb = (Byte) BeanUtil.getProperty(dest, "FooByte");
512         assertEquals(95, vb.intValue());
513         vb = (Byte) BeanUtil.getProperty(dest, "Foobyte");
514         assertEquals(96, vb.intValue());
515         Character c = (Character) BeanUtil.getProperty(dest, "FooCharacter");
516         assertEquals('7', c.charValue());
517         c = (Character) BeanUtil.getProperty(dest, "Foochar");
518         assertEquals('8', c.charValue());
519         Boolean b = (Boolean) BeanUtil.getProperty(dest, "FooBoolean");
520         assertTrue(b.booleanValue());
521         b = (Boolean) BeanUtil.getProperty(dest, "Fooboolean");
522         assertFalse(b.booleanValue());
523         Float f = (Float) BeanUtil.getProperty(dest, "FooFloat");
524         assertEquals(209.0, f.floatValue(), 0.005);
525         f = (Float) BeanUtil.getProperty(dest, "Foofloat");
526         assertEquals(210.0, f.floatValue(), 0.005);
527         Double d = (Double) BeanUtil.getProperty(dest, "FooDouble");
528         assertEquals(211.0, d.doubleValue(), 0.005);
529         d = (Double) BeanUtil.getProperty(dest, "Foodouble");
530         assertEquals(212.0, d.doubleValue(), 0.005);
531         String s = (String) BeanUtil.getProperty(dest, "FooString");
532         assertEquals("213", s);
533         String[] sa = (String[]) BeanUtil.getProperty(dest, "FooStringA");
534         assertEquals(2, sa.length);
535         assertEquals("214", sa[0]);
536         assertEquals("215", sa[1]);
537
538
539         FooBean empty = new FooBean();
540         BeanUtil.copyProperties(empty, dest);
541         v = (Integer) BeanUtil.getProperty(dest, "FooInteger");
542         assertNull(v);
543         v = (Integer) BeanUtil.getProperty(dest, "Fooint");
544         assertEquals(0, v.intValue());
545         vl = (Long) BeanUtil.getProperty(dest, "FooLong");
546         assertNull(vl);
547         vl = (Long) BeanUtil.getProperty(dest, "Foolong");
548         assertEquals(0, vl.longValue());
549         vb = (Byte) BeanUtil.getProperty(dest, "FooByte");
550         assertNull(vb);
551         vb = (Byte) BeanUtil.getProperty(dest, "Foobyte");
552         assertEquals(0, vb.byteValue());
553         c = (Character) BeanUtil.getProperty(dest, "FooCharacter");
554         assertNull(c);
555         c = (Character) BeanUtil.getProperty(dest, "Foochar");
556         assertEquals(0, c.charValue());
557         b = (Boolean) BeanUtil.getProperty(dest, "FooBoolean");
558         assertNull(b);
559         b = (Boolean) BeanUtil.getProperty(dest, "Fooboolean");
560         assertFalse(b.booleanValue());
561         f = (Float) BeanUtil.getProperty(dest, "FooFloat");
562         assertNull(f);
563         f = (Float) BeanUtil.getProperty(dest, "Foofloat");
564         assertEquals(0, f.floatValue(), 0.005);
565         d = (Double) BeanUtil.getProperty(dest, "FooDouble");
566         assertNull(d);
567         d = (Double) BeanUtil.getProperty(dest, "Foodouble");
568         assertEquals(0, d.doubleValue(), 0.005);
569         s = (String) BeanUtil.getProperty(dest, "FooString");
570         assertNull(s);
571         sa = (String[]) BeanUtil.getProperty(dest, "FooStringA");
572         assertNull(sa);
573     }
574
575     public void testNested() {
576         Cbean cbean = new Cbean();
577         String value = "testnest";
578         String value2 = "nesttest";
579         assertTrue(BeanUtil.setProperty(cbean, "bbean.abean.fooProp", value));
580
581         assertEquals(value, (String) BeanUtil.getProperty(cbean, "bbean.abean.fooProp"));
582         Bbean bbean = (Bbean) BeanUtil.getProperty(cbean, "bbean");
583         assertEquals(value, (String) BeanUtil.getProperty(bbean, "abean.fooProp"));
584         Abean abean = (Abean) BeanUtil.getProperty(bbean, "abean");
585         assertEquals(value, (String) BeanUtil.getProperty(abean, "fooProp"));
586
587         assertTrue(BeanUtil.setProperty(bbean, "abean.fooProp", value2));
588         assertEquals(value2, (String) BeanUtil.getProperty(bbean, "abean.fooProp"));
589     }
590
591     public void testIster() {
592         Abean abean = new Abean();
593
594         Boolean b = (Boolean) BeanUtil.getProperty(abean, "something");
595         assertTrue(b.booleanValue());
596
597
598     }
599 }
600
Popular Tags