Polish NumberUtilsTests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,7 @@ import static org.junit.Assert.*;
|
||||
public class NumberUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testParseNumber() {
|
||||
public void parseNumber() {
|
||||
String aByte = "" + Byte.MAX_VALUE;
|
||||
String aShort = "" + Short.MAX_VALUE;
|
||||
String anInteger = "" + Integer.MAX_VALUE;
|
||||
@@ -49,7 +49,7 @@ public class NumberUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseNumberUsingNumberFormat() {
|
||||
public void parseNumberUsingNumberFormat() {
|
||||
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
|
||||
String aByte = "" + Byte.MAX_VALUE;
|
||||
String aShort = "" + Short.MAX_VALUE;
|
||||
@@ -67,7 +67,7 @@ public class NumberUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseWithTrim() {
|
||||
public void parseNumberRequiringTrim() {
|
||||
String aByte = " " + Byte.MAX_VALUE + " ";
|
||||
String aShort = " " + Short.MAX_VALUE + " ";
|
||||
String anInteger = " " + Integer.MAX_VALUE + " ";
|
||||
@@ -84,7 +84,7 @@ public class NumberUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseWithTrimUsingNumberFormat() {
|
||||
public void parseNumberRequiringTrimUsingNumberFormat() {
|
||||
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
|
||||
String aByte = " " + Byte.MAX_VALUE + " ";
|
||||
String aShort = " " + Short.MAX_VALUE + " ";
|
||||
@@ -102,7 +102,7 @@ public class NumberUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseAsHex() {
|
||||
public void parseNumberAsHex() {
|
||||
String aByte = "0x" + Integer.toHexString(new Byte(Byte.MAX_VALUE).intValue());
|
||||
String aShort = "0x" + Integer.toHexString(new Short(Short.MAX_VALUE).intValue());
|
||||
String anInteger = "0x" + Integer.toHexString(Integer.MAX_VALUE);
|
||||
@@ -118,7 +118,7 @@ public class NumberUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseNegativeHex() {
|
||||
public void parseNumberAsNegativeHex() {
|
||||
String aByte = "-0x80";
|
||||
String aShort = "-0x8000";
|
||||
String anInteger = "-0x80000000";
|
||||
@@ -134,47 +134,47 @@ public class NumberUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleToBigInteger() {
|
||||
public void convertDoubleToBigInteger() {
|
||||
Double decimal = new Double(3.14d);
|
||||
assertEquals(new BigInteger("3"), NumberUtils.convertNumberToTargetClass(decimal, BigInteger.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBigDecimalToBigInteger() {
|
||||
public void convertBigDecimalToBigInteger() {
|
||||
String number = "987459837583750387355346";
|
||||
BigDecimal decimal = new BigDecimal(number);
|
||||
assertEquals(new BigInteger(number), NumberUtils.convertNumberToTargetClass(decimal, BigInteger.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonExactBigDecimalToBigInteger() {
|
||||
public void convertNonExactBigDecimalToBigInteger() {
|
||||
BigDecimal decimal = new BigDecimal("987459837583750387355346.14");
|
||||
assertEquals(new BigInteger("987459837583750387355346"), NumberUtils.convertNumberToTargetClass(decimal, BigInteger.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseBigDecimalNumber1() {
|
||||
public void parseBigDecimalNumber1() {
|
||||
String bigDecimalAsString = "0.10";
|
||||
Number bigDecimal = NumberUtils.parseNumber(bigDecimalAsString, BigDecimal.class);
|
||||
assertEquals(new BigDecimal(bigDecimalAsString), bigDecimal);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseBigDecimalNumber2() {
|
||||
public void parseBigDecimalNumber2() {
|
||||
String bigDecimalAsString = "0.001";
|
||||
Number bigDecimal = NumberUtils.parseNumber(bigDecimalAsString, BigDecimal.class);
|
||||
assertEquals(new BigDecimal(bigDecimalAsString), bigDecimal);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseBigDecimalNumber3() {
|
||||
public void parseBigDecimalNumber3() {
|
||||
String bigDecimalAsString = "3.14159265358979323846";
|
||||
Number bigDecimal = NumberUtils.parseNumber(bigDecimalAsString, BigDecimal.class);
|
||||
assertEquals(new BigDecimal(bigDecimalAsString), bigDecimal);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseLocalizedBigDecimalNumber1() {
|
||||
public void parseLocalizedBigDecimalNumber1() {
|
||||
String bigDecimalAsString = "0.10";
|
||||
NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
|
||||
Number bigDecimal = NumberUtils.parseNumber(bigDecimalAsString, BigDecimal.class, numberFormat);
|
||||
@@ -182,7 +182,7 @@ public class NumberUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseLocalizedBigDecimalNumber2() {
|
||||
public void parseLocalizedBigDecimalNumber2() {
|
||||
String bigDecimalAsString = "0.001";
|
||||
NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
|
||||
Number bigDecimal = NumberUtils.parseNumber(bigDecimalAsString, BigDecimal.class, numberFormat);
|
||||
@@ -190,7 +190,7 @@ public class NumberUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseLocalizedBigDecimalNumber3() {
|
||||
public void parseLocalizedBigDecimalNumber3() {
|
||||
String bigDecimalAsString = "3.14159265358979323846";
|
||||
NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
|
||||
Number bigDecimal = NumberUtils.parseNumber(bigDecimalAsString, BigDecimal.class, numberFormat);
|
||||
@@ -198,7 +198,7 @@ public class NumberUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseOverflow() {
|
||||
public void parseOverflow() {
|
||||
String aLong = "" + Long.MAX_VALUE;
|
||||
String aDouble = "" + Double.MAX_VALUE;
|
||||
|
||||
@@ -228,7 +228,7 @@ public class NumberUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseNegativeOverflow() {
|
||||
public void parseNegativeOverflow() {
|
||||
String aLong = "" + Long.MIN_VALUE;
|
||||
String aDouble = "" + Double.MIN_VALUE;
|
||||
|
||||
@@ -258,7 +258,7 @@ public class NumberUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseOverflowUsingNumberFormat() {
|
||||
public void parseOverflowUsingNumberFormat() {
|
||||
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
|
||||
String aLong = "" + Long.MAX_VALUE;
|
||||
String aDouble = "" + Double.MAX_VALUE;
|
||||
@@ -289,7 +289,7 @@ public class NumberUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseNegativeOverflowUsingNumberFormat() {
|
||||
public void parseNegativeOverflowUsingNumberFormat() {
|
||||
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
|
||||
String aLong = "" + Long.MIN_VALUE;
|
||||
String aDouble = "" + Double.MIN_VALUE;
|
||||
@@ -320,7 +320,7 @@ public class NumberUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToNumberInteger() {
|
||||
public void convertToInteger() {
|
||||
assertEquals(Integer.valueOf(Integer.valueOf(-1)), NumberUtils.convertNumberToTargetClass(BigInteger.valueOf(-1), Integer.class));
|
||||
assertEquals(Integer.valueOf(Integer.valueOf(0)), NumberUtils.convertNumberToTargetClass(BigInteger.valueOf(0), Integer.class));
|
||||
assertEquals(Integer.valueOf(Integer.valueOf(1)), NumberUtils.convertNumberToTargetClass(BigInteger.valueOf(1), Integer.class));
|
||||
@@ -367,7 +367,7 @@ public class NumberUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToNumberLong() {
|
||||
public void convertToLong() {
|
||||
assertEquals(Long.valueOf(Long.valueOf(-1)), NumberUtils.convertNumberToTargetClass(BigInteger.valueOf(-1), Long.class));
|
||||
assertEquals(Long.valueOf(Long.valueOf(0)), NumberUtils.convertNumberToTargetClass(BigInteger.valueOf(0), Long.class));
|
||||
assertEquals(Long.valueOf(Long.valueOf(1)), NumberUtils.convertNumberToTargetClass(BigInteger.valueOf(1), Long.class));
|
||||
|
||||
Reference in New Issue
Block a user