BigIntegerConverter extends AbstractIntegerConverter<BigInteger> { @Override public BigInteger convertToObject(final String value, final Locale locale) { if (Strings.isEmpty(value)) { return null; } final Number number = parse(value, -Double.MAX_VALUE, Double.MAX_VALUE, locale); if (number instanceof BigInteger) { return (BigInteger) number; } else if (number instanceof Long) { return BigInteger.valueOf(number.longValue()); } else if (number instanceof Integer) { return BigInteger.valueOf(number.intValue()); } else { return new BigInteger(value); } }  @Override BigInteger convertToObject(final String value, final Locale locale);  }
@Test public void positiveInteger() { BigIntegerConverter converter = new BigIntegerConverter(); BigInteger bigInteger = converter.convertToObject("12345", Locale.GERMAN); assertEquals(12345, bigInteger.intValue()); }
@Test public void negativeInteger() { BigIntegerConverter converter = new BigIntegerConverter(); BigInteger bigInteger = converter.convertToObject("-12345", Locale.GERMAN); assertEquals(-12345, bigInteger.intValue()); }
@Test public void positiveLong() { BigIntegerConverter converter = new BigIntegerConverter(); BigInteger bigInteger = converter.convertToObject("1234567890987654321", Locale.GERMAN); assertEquals(1234567890987654321L, bigInteger.longValue()); }
@Test public void negativeLong() { BigIntegerConverter converter = new BigIntegerConverter(); BigInteger bigInteger = converter.convertToObject("-1234567890987654321", Locale.GERMAN); assertEquals(-1234567890987654321L, bigInteger.longValue()); }
@Test public void positiveVeryLong() { BigIntegerConverter converter = new BigIntegerConverter(); BigInteger bigInteger = converter.convertToObject("1234567890987654321234567890987654321234567890987654321", Locale.GERMAN); assertEquals("1234567890987654321234567890987654321234567890987654321", bigInteger.toString()); }
@Test public void negativeVeryLong() { BigIntegerConverter converter = new BigIntegerConverter(); BigInteger bigInteger = converter.convertToObject("-1234567890987654321234567890987654321234567890987654321", Locale.GERMAN); assertEquals("-1234567890987654321234567890987654321234567890987654321", bigInteger.toString()); }
@Test(expected = ConversionException.class) public void nan() { BigIntegerConverter converter = new BigIntegerConverter(); converter.convertToObject("a12345a", Locale.GERMAN); }