KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > values > types > ValueTypeTest


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.values.types;
5
6 import java.io.InputStream JavaDoc;
7 import java.text.ParseException JavaDoc;
8
9 import junit.framework.TestCase;
10
11 import org.apache.commons.beanutils.ConvertUtilsBean;
12 import org.oddjob.arooa.PropertyProxyResolver;
13 import org.oddjob.arooa.reflect.IntrospectionHelper;
14
15 /**
16  *
17  */

18 public class ValueTypeTest extends TestCase {
19
20     PropertyProxyResolver typeManager;
21     
22     public void setUp() {
23         typeManager = new PropertyProxyResolver();
24         typeManager.addResource("/org/oddjob/values/proxies.properties");
25     }
26
27     public void testText() throws ParseException JavaDoc {
28         ValueType test = new ValueType();
29         
30         IntrospectionHelper ih = IntrospectionHelper.getHelper(ValueType.class);
31         ih.dump(System.out);
32         ih.addText(test, "Hello World");
33         
34         assertEquals("Text", "Hello World", IntrospectionHelper.valueFor(test, String JavaDoc.class));
35         
36         assertEquals("Object", "Hello World", IntrospectionHelper.valueFor(test, Object JavaDoc.class));
37     }
38
39     public void testConversions() {
40         ValueType test = new ValueType();
41         
42         test.setValue("true");
43         assertTrue(InputStream JavaDoc.class.isInstance(
44                 IntrospectionHelper.valueFor(test, InputStream JavaDoc.class)));
45     }
46     
47     public void testAsNumbers() {
48         ConvertUtilsBean cub = new ConvertUtilsBean();
49         
50         ValueType nt = new ValueType();
51         nt.setValue("127");
52         
53         String JavaDoc s = (String JavaDoc) nt.valueFor(Object JavaDoc.class);
54         
55         assertEquals("127", s);
56         
57         Byte JavaDoc b = (Byte JavaDoc) cub.convert(s, Byte JavaDoc.class);
58         assertEquals(127, b.byteValue());
59
60         nt.setValue("123.4");
61         s = (String JavaDoc) nt.valueFor(Object JavaDoc.class);
62         Integer JavaDoc i = (Integer JavaDoc) cub.convert(s, Integer JavaDoc.class);
63         assertEquals(new Integer JavaDoc("0"), i);
64     }
65     
66     public void testAsObject() {
67         Object JavaDoc o = new Object JavaDoc();
68         
69         ValueType vt = new ValueType();
70         vt.setValue(o);
71         
72         assertEquals(o, vt.valueFor(Object JavaDoc.class));
73     }
74 }
75
Popular Tags