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