KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > util > NumberUtilsTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
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.springframework.util;
18
19 import junit.framework.TestCase;
20
21 /**
22  * @author Rob Harrop
23  */

24 public class NumberUtilsTests extends TestCase{
25
26     public void testParseNumber() {
27         String JavaDoc aByte = "" + Byte.MAX_VALUE;
28         String JavaDoc aShort = "" + Short.MAX_VALUE;
29         String JavaDoc anInteger = "" + Integer.MAX_VALUE;
30         String JavaDoc aLong = "" + Long.MAX_VALUE;
31         String JavaDoc aFloat = "" + Float.MAX_VALUE;
32         String JavaDoc aDouble = "" + Double.MAX_VALUE;
33
34         assertEquals("Byte did not parse", new Byte JavaDoc(Byte.MAX_VALUE), NumberUtils.parseNumber(aByte, Byte JavaDoc.class));
35         assertEquals("Short did not parse", new Short JavaDoc(Short.MAX_VALUE), NumberUtils.parseNumber(aShort, Short JavaDoc.class));
36         assertEquals("Integer did not parse", new Integer JavaDoc(Integer.MAX_VALUE), NumberUtils.parseNumber(anInteger, Integer JavaDoc.class));
37         assertEquals("Long did not parse", new Long JavaDoc(Long.MAX_VALUE), NumberUtils.parseNumber(aLong, Long JavaDoc.class));
38         assertEquals("Float did not parse", new Float JavaDoc(Float.MAX_VALUE), NumberUtils.parseNumber(aFloat, Float JavaDoc.class));
39         assertEquals("Double did not parse", new Double JavaDoc(Double.MAX_VALUE), NumberUtils.parseNumber(aDouble, Double JavaDoc.class));
40     }
41
42     public void testParseWithTrim() {
43         String JavaDoc aByte = " " + Byte.MAX_VALUE + " ";
44         String JavaDoc aShort = " " + Short.MAX_VALUE + " ";
45         String JavaDoc anInteger = " " + Integer.MAX_VALUE + " ";
46         String JavaDoc aLong = " " + Long.MAX_VALUE + " ";
47         String JavaDoc aFloat = " " + Float.MAX_VALUE + " ";
48         String JavaDoc aDouble = " " + Double.MAX_VALUE + " ";
49
50         assertEquals("Byte did not parse", new Byte JavaDoc(Byte.MAX_VALUE), NumberUtils.parseNumber(aByte, Byte JavaDoc.class));
51         assertEquals("Short did not parse", new Short JavaDoc(Short.MAX_VALUE), NumberUtils.parseNumber(aShort, Short JavaDoc.class));
52         assertEquals("Integer did not parse", new Integer JavaDoc(Integer.MAX_VALUE), NumberUtils.parseNumber(anInteger, Integer JavaDoc.class));
53         assertEquals("Long did not parse", new Long JavaDoc(Long.MAX_VALUE), NumberUtils.parseNumber(aLong, Long JavaDoc.class));
54         assertEquals("Float did not parse", new Float JavaDoc(Float.MAX_VALUE), NumberUtils.parseNumber(aFloat, Float JavaDoc.class));
55         assertEquals("Double did not parse", new Double JavaDoc(Double.MAX_VALUE), NumberUtils.parseNumber(aDouble, Double JavaDoc.class));
56     }
57
58 }
59
Popular Tags