MapValueGetter { public static long getAsLong(Map<String, Object> map, String key) { Object value = map.get(key); if (value instanceof Long) { return (long) value; } if (value == null) { return 0; } if (value instanceof String) { return Long.valueOf((String) value); } throw new WrongTypeException(key, "long", 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 testLongAsLong() { map.put("value", 1L); Long actual = MapValueGetter.getAsLong(map, "value"); Long expected = 1L; assertEquals(expected, actual); }
@Test public void testLongFromString() { map.put("value", "1"); Long actual = MapValueGetter.getAsLong(map, "value"); Long expected = 1L; assertEquals(expected, actual); }
@Test public void testLongFromNull() { Long actual = MapValueGetter.getAsLong(map, "value"); Long expected = 0L; assertEquals(expected, actual); }
@Test(expected = WrongTypeException.class) public void testLongWrongType() { map.put("value", true); MapValueGetter.getAsLong(map, "value"); }