コード例 #1
0
 public void testToTypes() throws Exception {
   assertEquals(
       "Integer.class", Integer.class, StringToNumberConverter.toInteger(false).getToType());
   assertEquals("Integer.TYPE", Integer.TYPE, StringToNumberConverter.toInteger(true).getToType());
   assertEquals("Double.class", Double.class, StringToNumberConverter.toDouble(false).getToType());
   assertEquals("Double.TYPE", Double.TYPE, StringToNumberConverter.toDouble(true).getToType());
   assertEquals("Long.class", Long.class, StringToNumberConverter.toLong(false).getToType());
   assertEquals("Long.TYPE", Long.TYPE, StringToNumberConverter.toLong(true).getToType());
   assertEquals("Float.class", Float.class, StringToNumberConverter.toFloat(false).getToType());
   assertEquals("Float.TYPE", Float.TYPE, StringToNumberConverter.toFloat(true).getToType());
   assertEquals(
       "BigInteger.TYPE", BigInteger.class, StringToNumberConverter.toBigInteger().getToType());
   assertEquals(
       "BigDecimal.TYPE", BigDecimal.class, StringToNumberConverter.toBigDecimal().getToType());
   assertEquals("Short.class", Short.class, StringToNumberConverter.toShort(false).getToType());
   assertEquals("Short.TYPE", Short.TYPE, StringToNumberConverter.toShort(true).getToType());
   assertEquals("Byte.class", Byte.class, StringToNumberConverter.toByte(false).getToType());
   assertEquals("Byte.TYPE", Byte.TYPE, StringToNumberConverter.toByte(true).getToType());
 }
コード例 #2
0
  public void testConvertsToBigDecimal() throws Exception {
    StringToNumberConverter converter = StringToNumberConverter.toBigDecimal();
    // Test 1: Decimal
    BigDecimal input = new BigDecimal("100.23");
    BigDecimal result = (BigDecimal) converter.convert(formatBigDecimal(input));
    assertEquals("Non-integer BigDecimal", input, result);

    // Test 2: Long
    input = new BigDecimal(Integer.MAX_VALUE + 100L);
    result = (BigDecimal) converter.convert(formatBigDecimal(input));
    assertEquals("Integral BigDecimal in long range", input, result);

    // Test 3: BigInteger range
    input = new BigDecimal("92233720368547990480");
    result = (BigDecimal) converter.convert(formatBigDecimal(input));
    assertEquals("Integral BigDecimal in long range", input, result);

    // Test 4: Very high precision Decimal.
    input = new BigDecimal("100404101.23345678345678893456789345678923198200134567823456789");
    result = (BigDecimal) converter.convert(formatBigDecimal(input));
    assertEquals("Non-integer BigDecimal", input, result);
  }