1 16 package net.sf.dozer.util.mapping.util; 17 18 import java.beans.PropertyDescriptor ; 19 20 import net.sf.dozer.util.mapping.DozerTestBase; 21 import net.sf.dozer.util.mapping.MappingException; 22 import net.sf.dozer.util.mapping.vo.SimpleObj; 23 import net.sf.dozer.util.mapping.vo.inheritance.ChildChildIF; 24 25 28 public class ReflectionUtilsTest extends DozerTestBase { 29 private ReflectionUtils utils = new ReflectionUtils(); 30 31 public void testGetMethod_NotFound() throws Exception { 32 SimpleObj src = new SimpleObj(); 33 try { 34 utils.getMethod(src, String.valueOf(System.currentTimeMillis())); 35 fail("Should have thrown exception"); 36 } catch (MappingException e) { 37 } 38 } 39 40 public void testGetDeepFieldHierarchy_NonDeepField() throws Exception { 41 try { 42 utils.getDeepFieldHierarchy(SimpleObj.class, "test"); 43 fail("Should have thrown exception"); 44 } catch (MappingException e) { 45 assertEquals("invalid exception thrown", "Field does not contain deep field delimitor", e.getMessage()); 46 } 47 } 48 49 public void testGetDeepFieldHierarchy_NotExists() throws Exception { 50 try { 51 utils.getDeepFieldHierarchy(SimpleObj.class, String.valueOf(System.currentTimeMillis()) + "." + String.valueOf(System.currentTimeMillis())); 52 fail("Should have thrown exception"); 53 } catch (MappingException e) { 54 } 55 } 56 57 public void testGetPropertyDescriptors_InterfaceInheritance() throws Exception { 58 PropertyDescriptor [] pds = utils.getPropertyDescriptors(ChildChildIF.class); 60 assertNotNull("prop descriptors should not be null", pds); 61 assertEquals("3 prop descriptors should have been found", 3, pds.length); 62 } 63 64 public void testGetPropertyDescriptor_InterfaceInheritance() throws Exception { 65 String fieldName = "parentField"; 67 PropertyDescriptor pd = utils.getPropertyDescriptor(ChildChildIF.class, fieldName); 68 assertNotNull("prop descriptor should not be null", pd); 69 assertEquals("invalid prop descriptor name found", fieldName, pd.getName()); 70 } 71 } 72 | Popular Tags |