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 java.math.BigDecimal;
20  
21  import org.apache.commons.math.MathException;
22  import junit.framework.TestCase;
23  
24  /**
25   * @version $Revision: 201916 $ $Date: 2005-06-26 15:25:41 -0700 (Sun, 26 Jun 2005) $
26   */
27  public class DefaultTransformerTest extends TestCase {
28      /**
29       * 
30       */
31      public void testTransformDouble() throws Exception {
32          double expected = 1.0;
33          Double input = new Double(expected);
34          DefaultTransformer t = new DefaultTransformer();
35          assertEquals(expected, t.transform(input), 1.0e-4);
36      }
37      
38      /**
39       * 
40       */
41      public void testTransformNull(){
42          DefaultTransformer t = new DefaultTransformer();
43          try {
44              t.transform(null);
45              fail("Expection MathException");
46          } catch (MathException e) {
47              // expected
48          }
49      }
50      
51      /**
52       * 
53       */
54      public void testTransformInteger() throws Exception {
55          double expected = 1.0;
56          Integer input = new Integer(1);
57          DefaultTransformer t = new DefaultTransformer();
58          assertEquals(expected, t.transform(input), 1.0e-4);
59      }        
60      
61      /**
62       * 
63       */
64      public void testTransformBigDecimal() throws Exception {
65          double expected = 1.0;
66          BigDecimal input = new BigDecimal("1.0");
67          DefaultTransformer t = new DefaultTransformer();
68          assertEquals(expected, t.transform(input), 1.0e-4);
69      }        
70      
71      /**
72       * 
73       */
74      public void testTransformString() throws Exception {
75          double expected = 1.0;
76          String input = "1.0";
77          DefaultTransformer t = new DefaultTransformer();
78          assertEquals(expected, t.transform(input), 1.0e-4);
79      }
80      
81      /**
82       * 
83       */
84      public void testTransformObject(){
85          Boolean input = Boolean.TRUE;
86          DefaultTransformer t = new DefaultTransformer();
87          try {
88              t.transform(input);
89              fail("Expecting MathException");
90          } catch (MathException e) {
91              // expected
92          }
93      }
94  }