MapValueGetter { public static BigInteger getAsBigInteger(Map<String, Object> map, String key) { Object value = map.get(key); if (value instanceof BigInteger) { return (BigInteger) value; } if (value == null) { return BigInteger.ZERO; } if (value instanceof String) { return new BigInteger((String) value); } throw new WrongTypeException(key, BigInteger.class, value); } private  MapValueGetter(); static T getAsType(Map<String, Object> map, String key, Class<T> objectType); static BigDecimal getAsBigDecimal(Map<String, Object> map, String key); static BigInteger getAsBigInteger(Map<String, Object> map, String key); static boolean getAsBoolean(Map<String, Object> map, String key); static byte getAsByte(Map<String, Object> map, String key); static char getAsChar(Map<String, Object> map, String key); static double getAsDouble(Map<String, Object> map, String key); static float getAsFloat(Map<String, Object> map, String key); static int getAsInt(Map<String, Object> map, String key); static long getAsLong(Map<String, Object> map, String key); static short getAsShort(Map<String, Object> map, String key); static String getAsString(Map<String, Object> map, String key);  }
@Test public void testBigIntegerAsBigInteger() { map.put("value", BigInteger.valueOf(1)); BigInteger actual = MapValueGetter.getAsBigInteger(map, "value"); BigInteger expected = BigInteger.valueOf(1); assertEquals(expected, actual); }
@Test public void testBigIntegerFromString() { map.put("value", "1"); BigInteger actual = MapValueGetter.getAsBigInteger(map, "value"); BigInteger expected = BigInteger.valueOf(1); assertEquals(expected, actual); }
@Test public void testBigIntegerFromNull() { BigInteger actual = MapValueGetter.getAsBigInteger(map, "value"); BigInteger expected = BigInteger.ZERO; assertEquals(expected, actual); }
@Test(expected = WrongTypeException.class) public void testBigIntegerWrongType() { map.put("value", true); MapValueGetter.getAsBigInteger(map, "value"); }