KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > math > util > BeanTransformerTest


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation.
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
17 package org.apache.commons.math.util;
18
19 import org.apache.commons.math.MathException;
20 import org.apache.commons.math.TestUtils;
21
22 import junit.framework.TestCase;
23
24 /**
25  * @version $Revision$ $Date: 2005-02-26 05:11:52 -0800 (Sat, 26 Feb 2005) $
26  */

27 public class BeanTransformerTest extends TestCase {
28     
29     /**
30      *
31      */

32     public void testConstructor(){
33         BeanTransformer b = new BeanTransformer();
34         assertNull(b.getPropertyName());
35     }
36     
37     /**
38      *
39      */

40     public void testConstructorString(){
41         String JavaDoc name = "property";
42         BeanTransformer b = new BeanTransformer(name);
43         assertEquals(name, b.getPropertyName());
44     }
45     
46     /**
47      *
48      */

49     public void testSetPropertyName(){
50         String JavaDoc name = "property";
51         BeanTransformer b = new BeanTransformer();
52         b.setPropertyName(name);
53         assertEquals(name, b.getPropertyName());
54     }
55     
56     /**
57      *
58      */

59     public void testTransformNoSuchMethod(){
60         BeanTransformer b = new BeanTransformer("z");
61         TestBean target = new TestBean();
62         try {
63             b.transform(target);
64             fail("Expecting MathException");
65         } catch (MathException e) {
66             // expected
67
}
68     }
69     
70     /**
71      *
72      */

73     public void testTransform() throws Exception JavaDoc {
74         BeanTransformer b = new BeanTransformer("x");
75         TestBean target = new TestBean();
76         double value = Double.NaN;
77         value = b.transform(target);
78         TestUtils.assertEquals(1.0, value, 1.0e-2);
79     }
80     
81     /**
82      */

83     public void testTransformInvalidType() throws Exception JavaDoc {
84         BeanTransformer b = new BeanTransformer("y");
85         TestBean target = new TestBean();
86         try {
87             b.transform(target);
88             fail("Expecting ClassCastException");
89         } catch(ClassCastException JavaDoc ex){
90             // success
91
}
92     }
93 }
94
Popular Tags