Skip to content

Commit

Permalink
Polish NumberUtilsTests
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Aug 6, 2015
1 parent 15033c1 commit e0392d9
Showing 1 changed file with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -32,7 +32,7 @@
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;
Expand All @@ -49,7 +49,7 @@ public void testParseNumber() {
}

@Test
public void testParseNumberUsingNumberFormat() {
public void parseNumberUsingNumberFormat() {
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
String aByte = "" + Byte.MAX_VALUE;
String aShort = "" + Short.MAX_VALUE;
Expand All @@ -67,7 +67,7 @@ public void testParseNumberUsingNumberFormat() {
}

@Test
public void testParseWithTrim() {
public void parseNumberRequiringTrim() {
String aByte = " " + Byte.MAX_VALUE + " ";
String aShort = " " + Short.MAX_VALUE + " ";
String anInteger = " " + Integer.MAX_VALUE + " ";
Expand All @@ -84,7 +84,7 @@ public void testParseWithTrim() {
}

@Test
public void testParseWithTrimUsingNumberFormat() {
public void parseNumberRequiringTrimUsingNumberFormat() {
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
String aByte = " " + Byte.MAX_VALUE + " ";
String aShort = " " + Short.MAX_VALUE + " ";
Expand All @@ -102,7 +102,7 @@ public void testParseWithTrimUsingNumberFormat() {
}

@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);
Expand All @@ -118,7 +118,7 @@ public void testParseAsHex() {
}

@Test
public void testParseNegativeHex() {
public void parseNumberAsNegativeHex() {
String aByte = "-0x80";
String aShort = "-0x8000";
String anInteger = "-0x80000000";
Expand All @@ -134,71 +134,71 @@ public void testParseNegativeHex() {
}

@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);
assertEquals(new BigDecimal(bigDecimalAsString), bigDecimal);
}

@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);
assertEquals(new BigDecimal(bigDecimalAsString), bigDecimal);
}

@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);
assertEquals(new BigDecimal(bigDecimalAsString), bigDecimal);
}

@Test
public void testParseOverflow() {
public void parseOverflow() {
String aLong = "" + Long.MAX_VALUE;
String aDouble = "" + Double.MAX_VALUE;

Expand Down Expand Up @@ -228,7 +228,7 @@ public void testParseOverflow() {
}

@Test
public void testParseNegativeOverflow() {
public void parseNegativeOverflow() {
String aLong = "" + Long.MIN_VALUE;
String aDouble = "" + Double.MIN_VALUE;

Expand Down Expand Up @@ -258,7 +258,7 @@ public void testParseNegativeOverflow() {
}

@Test
public void testParseOverflowUsingNumberFormat() {
public void parseOverflowUsingNumberFormat() {
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
String aLong = "" + Long.MAX_VALUE;
String aDouble = "" + Double.MAX_VALUE;
Expand Down Expand Up @@ -289,7 +289,7 @@ public void testParseOverflowUsingNumberFormat() {
}

@Test
public void testParseNegativeOverflowUsingNumberFormat() {
public void parseNegativeOverflowUsingNumberFormat() {
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
String aLong = "" + Long.MIN_VALUE;
String aDouble = "" + Double.MIN_VALUE;
Expand Down Expand Up @@ -320,7 +320,7 @@ public void testParseNegativeOverflowUsingNumberFormat() {
}

@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));
Expand Down Expand Up @@ -367,7 +367,7 @@ public void testToNumberInteger() {
}

@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));
Expand Down

0 comments on commit e0392d9

Please sign in to comment.