MapValueGetter { public static byte getAsByte(Map<String, Object> map, String key) { Object value = map.get(key); if (value instanceof Byte) { return (byte) value; } if (value == null) { return 0; } if (value instanceof String) { return Byte.valueOf((String) value); } throw new WrongTypeException(key, "byte", 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 testByteAsByte() { map.put("value", (byte) 1); Byte actual = MapValueGetter.getAsByte(map, "value"); Byte expected = 1; assertEquals(expected, actual); }
@Test public void testByteFromString() { map.put("value", "1"); Byte actual = MapValueGetter.getAsByte(map, "value"); Byte expected = 1; assertEquals(expected, actual); }
@Test public void testByteFromNull() { Byte actual = MapValueGetter.getAsByte(map, "value"); Byte expected = 0; assertEquals(expected, actual); }
@Test(expected = WrongTypeException.class) public void testByteWrongType() { map.put("value", true); MapValueGetter.getAsByte(map, "value"); }
@Test(expected = NumberFormatException.class) public void testByteBadString() { map.put("value", "bob"); MapValueGetter.getAsByte(map, "value"); }