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