Clover Coverage Report - Commons BeanUtils 1.8.3-kuali-SNAPSHOT
Coverage timestamp: Thu Jun 9 2011 14:31:17 EDT
58   264   12   4.83
0   91   0.21   12
12     1  
1    
 
  DoubleLocaleConverterTestCase       Line # 28 58 0% 12 0 100% 1.0
 
  (9)
 
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.locale.converters;
19   
20   
21    /**
22    * Test Case for the DoubleLocaleConverter class.
23    *
24    * @author Niall Pemberton
25    * @version $Revision: 469728 $ $Date: 2006-10-31 20:08:34 -0500 (Tue, 31 Oct 2006) $
26    */
27   
 
28    public class DoubleLocaleConverterTestCase extends BaseLocaleConverterTestCase {
29   
30   
31   
32    // ---------------------------------------------------------- Constructors
33   
 
34  10 toggle public DoubleLocaleConverterTestCase(String name) {
35  10 super(name);
36    }
37   
38    // -------------------------------------------------- Overall Test Methods
39   
40    /**
41    * Set up instance variables required by this test case.
42    */
 
43  10 toggle public void setUp() throws Exception {
44   
45  10 super.setUp();
46   
47  10 defaultValue = new Double("9.99");
48  10 expectedValue = new Double(expectedDecimalValue);
49   
50    }
51   
52    /**
53    * Tear down instance variables required by this test case.
54    */
 
55  10 toggle public void tearDown() {
56  10 super.tearDown();
57    }
58   
59   
60    // ------------------------------------------------------------------------
61   
62    /**
63    * Test Converter(defaultValue, locale, pattern, localizedPattern) constructor
64    */
 
65  1 toggle public void testConstructorMain() {
66   
67    // ------------- Construct with localized pattern ------------
68  1 converter = new DoubleLocaleConverter(defaultValue,
69    localizedLocale,
70    localizedDecimalPattern,
71    true);
72   
73   
74  1 convertValueNoPattern(converter, "(A)", localizedDecimalValue, expectedValue);
75  1 convertValueWithPattern(converter, "(A)", localizedDecimalValue, localizedDecimalPattern, expectedValue);
76  1 convertInvalid(converter, "(A)", defaultValue);
77  1 convertNull(converter, "(A)", defaultValue);
78   
79   
80    // **************************************************************************
81    // Convert value in the wrong format - maybe you would expect it to throw an
82    // exception and return the default - it doesn't, DecimalFormat parses it
83    // quite happily turning "1,234.56" into "1.234"
84    // I guess this is one of the limitations of DecimalFormat
85    // **************************************************************************
86  1 convertValueNoPattern(converter, "(B)", defaultDecimalValue, new Double("1.234"));
87   
88   
89    // **************************************************************************
90    // Convert with non-localized pattern - this causes an exception in parse()
91    // but it gets swallowed in convert() method and returns default.
92    // **** IS THIS THE EXPECTED BEHAVIOUR? ****
93    // Maybe if the pattern is no good, we should use a default pattern rather
94    // than just returning the default value.
95    // **************************************************************************
96  1 convertValueWithPattern(converter, "(B)", localizedDecimalValue, defaultDecimalPattern, defaultValue);
97   
98   
99    // **************************************************************************
100    // Convert with specified type
101    //
102    // BaseLocaleConverter completely ignores the type - so even if we specify
103    // Double.class here it still returns a Double.
104    // **** SHOULD IMPLEMENT THIS BEHAVIOUR ****
105    // **************************************************************************
106  1 convertValueToType(converter, "(B)", Integer.class, localizedDecimalValue, localizedDecimalPattern, expectedValue);
107   
108   
109    // ------------- Construct with non-localized pattern ------------
110  1 converter = new DoubleLocaleConverter(defaultValue,
111    localizedLocale,
112    defaultDecimalPattern,
113    false);
114   
115   
116  1 convertValueNoPattern(converter, "(C)", localizedDecimalValue, expectedValue);
117  1 convertValueWithPattern(converter, "(C)", localizedDecimalValue, defaultDecimalPattern, expectedValue);
118  1 convertInvalid(converter, "(C)", defaultValue);
119  1 convertNull(converter, "(C)", defaultValue);
120   
121    }
122   
123    /**
124    * Test Converter() constructor
125    *
126    * Uses the default locale, no default value
127    *
128    */
 
129  1 toggle public void testConstructor_2() {
130   
131    // ------------- Construct using default locale ------------
132  1 converter = new DoubleLocaleConverter();
133   
134    // Perform Tests
135  1 convertValueNoPattern(converter, defaultDecimalValue, expectedValue);
136  1 convertValueWithPattern(converter, defaultDecimalValue, defaultDecimalPattern, expectedValue);
137  1 convertInvalid(converter, null);
138  1 convertNull(converter, null);
139   
140    }
141   
142    /**
143    * Test Converter(locPattern) constructor
144    *
145    * Uses the default locale, no default value
146    *
147    */
 
148  1 toggle public void testConstructor_3() {
149   
150    // ------------- Construct using localized pattern (default locale) --------
151  1 converter = new DoubleLocaleConverter(true);
152   
153    // Perform Tests
154  1 convertValueNoPattern(converter, defaultDecimalValue, expectedValue);
155  1 convertValueWithPattern(converter, defaultDecimalValue, defaultDecimalPattern, expectedValue);
156  1 convertInvalid(converter, null);
157  1 convertNull(converter, null);
158   
159   
160    }
161   
162    /**
163    * Test Converter(Locale) constructor
164    */
 
165  1 toggle public void testConstructor_4() {
166   
167    // ------------- Construct using specified Locale --------
168  1 converter = new DoubleLocaleConverter(localizedLocale);
169   
170    // Perform Tests
171  1 convertValueNoPattern(converter, localizedDecimalValue, expectedValue);
172  1 convertValueWithPattern(converter, localizedDecimalValue, defaultDecimalPattern, expectedValue);
173  1 convertInvalid(converter, null);
174  1 convertNull(converter, null);
175   
176   
177    }
178   
179   
180    /**
181    * Test Converter(Locale, locPattern) constructor
182    */
 
183  1 toggle public void testConstructor_5() {
184   
185    // ------------- Construct using specified Locale --------
186  1 converter = new DoubleLocaleConverter(localizedLocale, true);
187   
188    // Perform Tests
189  1 convertValueNoPattern(converter, localizedDecimalValue, expectedValue);
190  1 convertValueWithPattern(converter, localizedDecimalValue, localizedDecimalPattern, expectedValue);
191  1 convertInvalid(converter, null);
192  1 convertNull(converter, null);
193   
194   
195    }
196   
197    /**
198    * Test Converter(Locale, pattern) constructor
199    */
 
200  1 toggle public void testConstructor_6() {
201   
202    // ------------- Construct using specified Locale --------
203  1 converter = new DoubleLocaleConverter(localizedLocale, defaultDecimalPattern);
204   
205    // Perform Tests
206  1 convertValueNoPattern(converter, localizedDecimalValue, expectedValue);
207  1 convertValueWithPattern(converter, localizedDecimalValue, defaultDecimalPattern, expectedValue);
208  1 convertInvalid(converter, null);
209  1 convertNull(converter, null);
210   
211    }
212   
213    /**
214    * Test Converter(Locale, pattern, locPattern) constructor
215    */
 
216  1 toggle public void testConstructor_7() {
217   
218    // ------------- Construct using specified Locale --------
219  1 converter = new DoubleLocaleConverter(localizedLocale, localizedDecimalPattern, true);
220   
221    // Perform Tests
222  1 convertValueNoPattern(converter, localizedDecimalValue, expectedValue);
223  1 convertValueWithPattern(converter, localizedDecimalValue, localizedDecimalPattern, expectedValue);
224  1 convertInvalid(converter, null);
225  1 convertNull(converter, null);
226   
227    }
228   
229    /**
230    * Test Converter(defaultValue) constructor
231    */
 
232  1 toggle public void testConstructor_8() {
233   
234    // ------------- Construct using specified Locale --------
235  1 converter = new DoubleLocaleConverter(defaultValue);
236   
237    // Perform Tests
238  1 convertValueNoPattern(converter, defaultDecimalValue, expectedValue);
239  1 convertValueWithPattern(converter, defaultDecimalValue, defaultDecimalPattern, expectedValue);
240  1 convertInvalid(converter, defaultValue);
241  1 convertNull(converter, defaultValue);
242   
243    }
244   
245    /**
246    * Test Converter(defaultValue, locPattern) constructor
247    */
 
248  1 toggle public void testConstructor_9() {
249   
250    // ------------- Construct using specified Locale --------
251  1 converter = new DoubleLocaleConverter(defaultValue, true);
252   
253    // Perform Tests
254  1 convertValueNoPattern(converter, defaultDecimalValue, expectedValue);
255  1 convertValueWithPattern(converter, defaultDecimalValue, defaultDecimalPattern, expectedValue);
256  1 convertInvalid(converter, defaultValue);
257  1 convertNull(converter, defaultValue);
258   
259    }
260   
261   
262   
263    }
264