MapValueGetter { public static String getAsString(Map<String, Object> map, String key) { Object value = map.get(key); if (value instanceof String) { return (String) value; } if (value == null) { return null; } return value.toString(); } 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 testStringAsString() { map.put("value", "R2-D2"); String actual = MapValueGetter.getAsString(map, "value"); String expected = "R2-D2"; assertEquals(expected, actual); }
@Test public void testStringFromNull() { String actual = MapValueGetter.getAsString(map, "value"); String expected = null; assertEquals(expected, actual); }
@Test public void testStringFromOtherType() { map.put("value", 1); String actual = MapValueGetter.getAsString(map, "value"); String expected = "1"; assertEquals(expected, actual); }