1 4 package org.oddjob.values.types; 5 6 import java.io.InputStream ; 7 import java.text.ParseException ; 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 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 { 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 .class)); 35 36 assertEquals("Object", "Hello World", IntrospectionHelper.valueFor(test, Object .class)); 37 } 38 39 public void testConversions() { 40 ValueType test = new ValueType(); 41 42 test.setValue("true"); 43 assertTrue(InputStream .class.isInstance( 44 IntrospectionHelper.valueFor(test, InputStream .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 s = (String ) nt.valueFor(Object .class); 54 55 assertEquals("127", s); 56 57 Byte b = (Byte ) cub.convert(s, Byte .class); 58 assertEquals(127, b.byteValue()); 59 60 nt.setValue("123.4"); 61 s = (String ) nt.valueFor(Object .class); 62 Integer i = (Integer ) cub.convert(s, Integer .class); 63 assertEquals(new Integer ("0"), i); 64 } 65 66 public void testAsObject() { 67 Object o = new Object (); 68 69 ValueType vt = new ValueType(); 70 vt.setValue(o); 71 72 assertEquals(o, vt.valueFor(Object .class)); 73 } 74 } 75 | Popular Tags |