Clover Coverage Report - Commons BeanUtils 1.8.3-kuali-SNAPSHOT
Coverage timestamp: Thu Jun 9 2011 11:19:33 MST
58   263   12   4.83
0   91   0.21   12
12     1  
1    
 
  LongLocaleConverterTestCase       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 LongLocaleConverter 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 LongLocaleConverterTestCase extends BaseLocaleConverterTestCase {
29   
30   
31   
32    // ---------------------------------------------------------- Constructors
33   
 
34  10 toggle public LongLocaleConverterTestCase(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 Long("999");
48  10 expectedValue = new Long(expectedIntegerValue);
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 LongLocaleConverter(defaultValue,
69    localizedLocale,
70    localizedIntegerPattern,
71    true);
72   
73   
74  1 convertValueNoPattern(converter, "(A)", localizedIntegerValue, expectedValue);
75  1 convertValueWithPattern(converter, "(A)", localizedIntegerValue, localizedIntegerPattern, 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" into "1"
84    // I guess this is one of the limitations of DecimalFormat
85    // **************************************************************************
86  1 convertValueNoPattern(converter, "(B)", defaultIntegerValue, new Long("1"));
87   
88   
89    // **************************************************************************
90    // Convert with non-localized pattern - unlike the equivalent BigDecimal Test Case
91    // it doesn't causes an exception in parse() - DecimalFormat parses it
92    // quite happily turning "1,234" into "1"
93    // Again this is one of the limitations of DecimalFormat
94    // **************************************************************************
95  1 convertValueWithPattern(converter, "(B)", localizedIntegerValue, defaultIntegerPattern, new Long("1"));
96   
97   
98    // **************************************************************************
99    // Convert with specified type
100    //
101    // BaseLocaleConverter completely ignores the type - so even if we specify
102    // Double.class here it still returns a Long.
103    // **** SHOULD IMPLEMENT THIS BEHAVIOUR ****
104    // **************************************************************************
105  1 convertValueToType(converter, "(B)", Double.class, localizedIntegerValue, localizedIntegerPattern, expectedValue);
106   
107   
108    // ------------- Construct with non-localized pattern ------------
109  1 converter = new LongLocaleConverter(defaultValue,
110    localizedLocale,
111    defaultIntegerPattern,
112    false);
113   
114   
115  1 convertValueNoPattern(converter, "(C)", localizedIntegerValue, expectedValue);
116  1 convertValueWithPattern(converter, "(C)", localizedIntegerValue, defaultIntegerPattern, expectedValue);
117  1 convertInvalid(converter, "(C)", defaultValue);
118  1 convertNull(converter, "(C)", defaultValue);
119   
120    }
121   
122    /**
123    * Test Converter() constructor
124    *
125    * Uses the default locale, no default value
126    *
127    */
 
128  1 toggle public void testConstructor_2() {
129   
130    // ------------- Construct using default locale ------------
131  1 converter = new LongLocaleConverter();
132   
133    // Perform Tests
134  1 convertValueNoPattern(converter, defaultIntegerValue, expectedValue);
135  1 convertValueWithPattern(converter, defaultIntegerValue, defaultIntegerPattern, expectedValue);
136  1 convertInvalid(converter, null);
137  1 convertNull(converter, null);
138   
139    }
140   
141    /**
142    * Test Converter(locPattern) constructor
143    *
144    * Uses the default locale, no default value
145    *
146    */
 
147  1 toggle public void testConstructor_3() {
148   
149    // ------------- Construct using localized pattern (default locale) --------
150  1 converter = new LongLocaleConverter(true);
151   
152    // Perform Tests
153  1 convertValueNoPattern(converter, defaultIntegerValue, expectedValue);
154  1 convertValueWithPattern(converter, defaultIntegerValue, defaultIntegerPattern, expectedValue);
155  1 convertInvalid(converter, null);
156  1 convertNull(converter, null);
157   
158   
159    }
160   
161    /**
162    * Test Converter(Locale) constructor
163    */
 
164  1 toggle public void testConstructor_4() {
165   
166    // ------------- Construct using specified Locale --------
167  1 converter = new LongLocaleConverter(localizedLocale);
168   
169    // Perform Tests
170  1 convertValueNoPattern(converter, localizedIntegerValue, expectedValue);
171  1 convertValueWithPattern(converter, localizedIntegerValue, defaultIntegerPattern, expectedValue);
172  1 convertInvalid(converter, null);
173  1 convertNull(converter, null);
174   
175   
176    }
177   
178   
179    /**
180    * Test Converter(Locale, locPattern) constructor
181    */
 
182  1 toggle public void testConstructor_5() {
183   
184    // ------------- Construct using specified Locale --------
185  1 converter = new LongLocaleConverter(localizedLocale, true);
186   
187    // Perform Tests
188  1 convertValueNoPattern(converter, localizedIntegerValue, expectedValue);
189  1 convertValueWithPattern(converter, localizedIntegerValue, localizedIntegerPattern, expectedValue);
190  1 convertInvalid(converter, null);
191  1 convertNull(converter, null);
192   
193   
194    }
195   
196    /**
197    * Test Converter(Locale, pattern) constructor
198    */
 
199  1 toggle public void testConstructor_6() {
200   
201    // ------------- Construct using specified Locale --------
202  1 converter = new LongLocaleConverter(localizedLocale, defaultIntegerPattern);
203   
204    // Perform Tests
205  1 convertValueNoPattern(converter, localizedIntegerValue, expectedValue);
206  1 convertValueWithPattern(converter, localizedIntegerValue, defaultIntegerPattern, expectedValue);
207  1 convertInvalid(converter, null);
208  1 convertNull(converter, null);
209   
210    }
211   
212    /**
213    * Test Converter(Locale, pattern, locPattern) constructor
214    */
 
215  1 toggle public void testConstructor_7() {
216   
217    // ------------- Construct using specified Locale --------
218  1 converter = new LongLocaleConverter(localizedLocale, localizedIntegerPattern, true);
219   
220    // Perform Tests
221  1 convertValueNoPattern(converter, localizedIntegerValue, expectedValue);
222  1 convertValueWithPattern(converter, localizedIntegerValue, localizedIntegerPattern, expectedValue);
223  1 convertInvalid(converter, null);
224  1 convertNull(converter, null);
225   
226    }
227   
228    /**
229    * Test Converter(defaultValue) constructor
230    */
 
231  1 toggle public void testConstructor_8() {
232   
233    // ------------- Construct using specified Locale --------
234  1 converter = new LongLocaleConverter(defaultValue);
235   
236    // Perform Tests
237  1 convertValueNoPattern(converter, defaultIntegerValue, expectedValue);
238  1 convertValueWithPattern(converter, defaultIntegerValue, defaultIntegerPattern, expectedValue);
239  1 convertInvalid(converter, defaultValue);
240  1 convertNull(converter, defaultValue);
241   
242    }
243   
244    /**
245    * Test Converter(defaultValue, locPattern) constructor
246    */
 
247  1 toggle public void testConstructor_9() {
248   
249    // ------------- Construct using specified Locale --------
250  1 converter = new LongLocaleConverter(defaultValue, true);
251   
252    // Perform Tests
253  1 convertValueNoPattern(converter, defaultIntegerValue, expectedValue);
254  1 convertValueWithPattern(converter, defaultIntegerValue, defaultIntegerPattern, expectedValue);
255  1 convertInvalid(converter, defaultValue);
256  1 convertNull(converter, defaultValue);
257   
258    }
259   
260   
261   
262    }
263