Clover Coverage Report - Commons BeanUtils 1.8.3-kuali-SNAPSHOT
Coverage timestamp: Thu Jun 9 2011 14:31:17 EDT
17   134   9   2.12
2   83   0.53   8
8     1.12  
1    
 
  BigDecimalConverterTestCase       Line # 34 17 0% 9 0 100% 1.0
 
  (17)
 
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.beanutils.converters;
19   
20    import java.math.BigDecimal;
21   
22    import junit.framework.TestSuite;
23   
24    import org.apache.commons.beanutils.Converter;
25   
26   
27    /**
28    * Test Case for the DoubleConverter class.
29    *
30    * @author Rodney Waldhoff
31    * @version $Revision: 471348 $ $Date: 2006-11-04 21:59:26 -0500 (Sat, 04 Nov 2006) $
32    */
33   
 
34    public class BigDecimalConverterTestCase extends NumberConverterTestBase {
35   
36    private Converter converter = null;
37   
38    // ------------------------------------------------------------------------
39   
 
40  17 toggle public BigDecimalConverterTestCase(String name) {
41  17 super(name);
42    }
43   
44    // ------------------------------------------------------------------------
45   
 
46  17 toggle public void setUp() throws Exception {
47  17 converter = makeConverter();
48  17 numbers[0] = new BigDecimal("-12");
49  17 numbers[1] = new BigDecimal("13");
50  17 numbers[2] = new BigDecimal("-22");
51  17 numbers[3] = new BigDecimal("23");
52    }
53   
 
54  1 toggle public static TestSuite suite() {
55  1 return new TestSuite(BigDecimalConverterTestCase.class);
56    }
57   
 
58  17 toggle public void tearDown() throws Exception {
59  17 converter = null;
60    }
61   
62    // ------------------------------------------------------------------------
63   
 
64  39 toggle protected NumberConverter makeConverter() {
65  39 return new BigDecimalConverter();
66    }
67   
 
68  2 toggle protected NumberConverter makeConverter(Object defaultValue) {
69  2 return new BigDecimalConverter(defaultValue);
70    }
71   
 
72  48 toggle protected Class getExpectedType() {
73  48 return BigDecimal.class;
74    }
75   
76    // ------------------------------------------------------------------------
77   
 
78  1 toggle public void testSimpleConversion() throws Exception {
79  1 String[] message= {
80    "from String",
81    "from String",
82    "from String",
83    "from String",
84    "from String",
85    "from Byte",
86    "from Short",
87    "from Integer",
88    "from Long",
89    "from Float",
90    "from Double"
91    };
92   
93  1 Object[] input = {
94    "-17.2",
95    "-1.1",
96    "0.0",
97    "1.1",
98    "17.2",
99    new Byte((byte)7),
100    new Short((short)8),
101    new Integer(9),
102    new Long(10),
103    new Float("11.1"),
104    new Double("12.2")
105    };
106   
107  1 BigDecimal[] expected = {
108    new BigDecimal("-17.2"),
109    new BigDecimal("-1.1"),
110    new BigDecimal("0.0"),
111    new BigDecimal("1.1"),
112    new BigDecimal("17.2"),
113    new BigDecimal("7"),
114    new BigDecimal("8"),
115    new BigDecimal("9"),
116    new BigDecimal("10"),
117    new BigDecimal("11.1"),
118    new BigDecimal("12.2")
119    };
120   
121  12 for(int i=0;i<expected.length;i++) {
122  11 assertEquals(
123    message[i] + " to BigDecimal",
124    expected[i],
125    converter.convert(BigDecimal.class,input[i]));
126  11 assertEquals(
127    message[i] + " to null type",
128    expected[i],
129    converter.convert(null,input[i]));
130    }
131    }
132   
133    }
134