1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.math.util;
19  
20  import java.math.BigDecimal;
21  
22  import org.apache.commons.math.MathException;
23  import junit.framework.TestCase;
24  
25  /**
26   * @version $Revision: 480442 $ $Date: 2006-11-29 00:21:22 -0700 (Wed, 29 Nov 2006) $
27   */
28  public class DefaultTransformerTest extends TestCase {
29      /**
30       * 
31       */
32      public void testTransformDouble() throws Exception {
33          double expected = 1.0;
34          Double input = new Double(expected);
35          DefaultTransformer t = new DefaultTransformer();
36          assertEquals(expected, t.transform(input), 1.0e-4);
37      }
38      
39      /**
40       * 
41       */
42      public void testTransformNull(){
43          DefaultTransformer t = new DefaultTransformer();
44          try {
45              t.transform(null);
46              fail("Expection MathException");
47          } catch (MathException e) {
48              // expected
49          }
50      }
51      
52      /**
53       * 
54       */
55      public void testTransformInteger() throws Exception {
56          double expected = 1.0;
57          Integer input = new Integer(1);
58          DefaultTransformer t = new DefaultTransformer();
59          assertEquals(expected, t.transform(input), 1.0e-4);
60      }        
61      
62      /**
63       * 
64       */
65      public void testTransformBigDecimal() throws Exception {
66          double expected = 1.0;
67          BigDecimal input = new BigDecimal("1.0");
68          DefaultTransformer t = new DefaultTransformer();
69          assertEquals(expected, t.transform(input), 1.0e-4);
70      }        
71      
72      /**
73       * 
74       */
75      public void testTransformString() throws Exception {
76          double expected = 1.0;
77          String input = "1.0";
78          DefaultTransformer t = new DefaultTransformer();
79          assertEquals(expected, t.transform(input), 1.0e-4);
80      }
81      
82      /**
83       * 
84       */
85      public void testTransformObject(){
86          Boolean input = Boolean.TRUE;
87          DefaultTransformer t = new DefaultTransformer();
88          try {
89              t.transform(input);
90              fail("Expecting MathException");
91          } catch (MathException e) {
92              // expected
93          }
94      }
95  }