MapValueGetter { public static boolean getAsBoolean(Map<String, Object> map, String key) { Object value = map.get(key); if (value instanceof Boolean) { return (boolean) value; } if (value == null) { return false; } if (value instanceof String) { return Boolean.valueOf((String) value); } throw new WrongTypeException(key, "boolean", 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 testBooleanFromNull() { Boolean actual = MapValueGetter.getAsBoolean(map, "value"); Boolean expected = false; assertEquals(expected, actual); }
@Test(expected = WrongTypeException.class) public void testBooleanWrongType() { map.put("value", 25); MapValueGetter.getAsBoolean(map, "value"); }
@Test public void testBooleanAsBoolean() { map.put("value", true); Boolean actual = MapValueGetter.getAsBoolean(map, "value"); Boolean expected = true; assertEquals(expected, actual); }
@Test public void testBooleanFromString() { map.put("value", "true"); Boolean actual = MapValueGetter.getAsBoolean(map, "value"); Boolean expected = true; assertEquals(expected, actual); }