1 18 package net.sf.uitags.tagutil; 19 20 import java.beans.BeanInfo ; 21 import java.beans.Introspector ; 22 import java.beans.PropertyDescriptor ; 23 import java.util.Map ; 24 import java.util.TreeMap ; 25 26 import net.sf.uitags.tagutil.bean.ElTagBeanInfo; 27 28 import junit.framework.TestCase; 29 30 36 public final class ElTagBeanInfoTest extends TestCase { 37 42 public static void main(String [] args) { 43 junit.textui.TestRunner.run(ElTagBeanInfoTest.class); 44 } 45 46 47 protected void setUp() throws Exception { 48 super.setUp(); 49 } 50 51 52 protected void tearDown() throws Exception { 53 super.tearDown(); 54 } 55 56 63 public void testGetTagHandlerSetters() throws Exception { 64 BeanInfo beanInfo = Introspector.getBeanInfo(BeanUnderTest.class); 65 PropertyDescriptor [] props = beanInfo.getPropertyDescriptors(); 66 Map sortedProps = mapPropertyDescriptors(props); 67 68 PropertyDescriptor prop0 = ((PropertyDescriptor ) sortedProps.get("prop0")); 70 assertEquals(prop0.getPropertyType(), String .class); 71 72 assertNotNull(sortedProps.get("prop1")); 74 assertNotNull(sortedProps.get("prop2")); 75 76 assertTrue(sortedProps.size() == 3); 78 } 79 80 87 private Map mapPropertyDescriptors(PropertyDescriptor [] props) { 88 Map ret = new TreeMap (); 89 for (int i = 0; i < props.length; i++) { 90 if (props[i].getName().startsWith("prop")) { 91 ret.put(props[i].getName(), props[i]); 92 } 93 } 94 95 return ret; 96 } 97 98 101 public static final class BeanUnderTest { 102 public void setProp0(Long nonStringProp) { 103 } 105 public void setProp0(String stringProp) { 106 } 108 public void setProp1(String prop) { 109 } 111 public void setProp2(Integer prop) { 112 } 114 } 115 116 119 public static final class BeanUnderTestBeanInfo extends ElTagBeanInfo { 120 } 122 } | Popular Tags |