BigIntegerConverter implements IStringConverter<BigInteger> { @Override public BigInteger convert(String value) { try { if (value.startsWith("0x")) { return new BigInteger(value.substring(2), 16); } else { return new BigInteger(value); } } catch (IllegalArgumentException e) { throw new ParameterException("Value " + value + " cannot be converted to a BigInteger. " + "The value can be hexadecimal (starting with 0x) or decimal."); } }  @Override BigInteger convert(String value);  }
@Test public void testConvert() { String testString = "0"; assertEquals(new BigInteger("0"), converter.convert(testString)); testString = "0x1"; assertEquals(new BigInteger("1"), converter.convert(testString)); testString = Integer.toString(Integer.MAX_VALUE); assertEquals(new BigInteger(Integer.toString(Integer.MAX_VALUE)), converter.convert(testString)); testString = "0xFFFFFFFFFFFFFFFF"; assertEquals(new BigInteger("FFFFFFFFFFFFFFFF", 16), converter.convert(testString)); }
@Test(expected = ParameterException.class) public void testConvertError() { converter.convert("hello world"); }