MapValueGetter { public static float getAsFloat(Map<String, Object> map, String key) { Object value = map.get(key); if (value instanceof Float) { return (float) value; } if (value == null) { return 0; } if (value instanceof String) { return Float.valueOf((String) value); } throw new WrongTypeException(key, "float", 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 testFloatAsFloat() { map.put("value", 1.1f); Float actual = MapValueGetter.getAsFloat(map, "value"); Float expected = 1.1f; assertEquals(expected, actual); }
@Test public void testFloatFromString() { map.put("value", "1.1"); Float actual = MapValueGetter.getAsFloat(map, "value"); Float expected = 1.1f; assertEquals(expected, actual); }
@Test public void testFloatFromNull() { Float actual = MapValueGetter.getAsFloat(map, "value"); Float expected = 0f; assertEquals(expected, actual); }
@Test(expected = WrongTypeException.class) public void testFloatWrongType() { map.put("value", true); MapValueGetter.getAsFloat(map, "value"); }