KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > dozer > util > mapping > util > ReflectionUtilsTest


1 /*
2  * Copyright 2005-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package net.sf.dozer.util.mapping.util;
17
18 import java.beans.PropertyDescriptor JavaDoc;
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 /**
26  * @author tierney.matt
27  */

28 public class ReflectionUtilsTest extends DozerTestBase {
29   private ReflectionUtils utils = new ReflectionUtils();
30
31   public void testGetMethod_NotFound() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
58     //Should walk the inheritance hierarchy all the way up to the super interface and find all properties along the way
59
PropertyDescriptor JavaDoc[] 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 JavaDoc {
65     //Should walk the inheritance hierarchy all the way up to the super interface and find the property along the way
66
String JavaDoc fieldName = "parentField";
67     PropertyDescriptor JavaDoc 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