1 2 package net.sf.voruta; 3 4 import junit.framework.*; 5 import java.util.*; 6 7 /*** 8 * 9 * @author baliuka 10 */ 11 public class BeanPropertiesTest extends TestCase { 12 13 public BeanPropertiesTest(java.lang.String testName) { 14 super(testName); 15 } 16 17 public static void main(java.lang.String[] args) { 18 junit.textui.TestRunner.run(suite()); 19 } 20 21 public static Test suite() { 22 TestSuite suite = new TestSuite(BeanPropertiesTest.class); 23 return suite; 24 } 25 26 public void testSimpleProperty()throws Exception{ 27 28 DemoBean bean = new DemoBean(); 29 Integer v = new Integer(11); 30 int indexed[] = new int[]{1,2,3}; 31 bean.setId(v.intValue()); 32 bean.setName("testName"); 33 bean.setIndexed(indexed); 34 35 BeanProperties.Property prop = 36 BeanProperties.getProperty( bean.getClass(), "name"); 37 38 assertEquals( prop.getValue(bean), bean.getName() ); 39 40 prop = 41 BeanProperties.getProperty( bean.getClass(), "ID"); 42 43 assertEquals( prop.getValue(bean), v ); 44 45 prop = 46 BeanProperties.getProperty( bean.getClass(), "indexed[1]"); 47 48 assertEquals( prop.getValue(bean), new Integer( indexed[1] ) ); 49 50 prop = 51 BeanProperties.getProperty( Map.class , "key"); 52 53 Map map = new HashMap(); 54 map.put("key",v); 55 56 assertEquals( prop.getValue(map), v ); 57 58 String test = "next"; 59 60 bean.getNext().getNext().setName(test); 61 62 63 prop = 64 BeanProperties.getProperty( bean.getClass() , "next->next->name"); 65 66 67 assertEquals( prop.getValue(bean), test ); 68 69 70 prop = 71 BeanProperties.getProperty( bean.getClass() , "next.next.name"); 72 73 74 assertEquals( prop.getValue(bean), test ); 75 76 77 List list = new ArrayList(); 78 list.add(test); 79 80 prop = 81 BeanProperties.getProperty( list.getClass() , "[0]"); 82 83 assertEquals( prop.getValue(list), test ); 84 85 86 } 87 88 89 90 }

This page was automatically generated by Maven