### Question:
JSON { public static Object getNonNull(Map<String,Object> json, String key) throws DataException { if (key == null) { throw new DataException("key is null"); } if (!json.containsKey(key)) { throw new DataException(key + " does not exist in " + json); } final Object o = json.get(key); if (o == null) { throw new DataException("value for " + key + " is null"); } return o; } protected  JSON(); static T getAs(Map<String,Object> json, String key, Class<T> type); static Object getNonNull(Map<String,Object> json, String key);  }### Answer:
@Test public void testGetNonNullOk() throws JSON.DataException { final Map<String,Object> json = new HashMap<String,Object>(); final String key = "foo"; json.put(key, 42); assertTrue(JSON.getNonNull(json, key) != null); }
@Test(expected=JSON.DataException.class) public void testGetNonNullNullKey() throws JSON.DataException { final Map<String,Object> json = new HashMap<String,Object>(); JSON.getNonNull(json, null); }
@Test(expected=JSON.DataException.class) public void testGetNonNullNullValue() throws JSON.DataException { final Map<String,Object> json = new HashMap<String,Object>(); final String key = "foo"; json.put(key, null); JSON.getNonNull(json, key); }
@Test(expected=JSON.DataException.class) public void testGetNonNullMissingKey() throws JSON.DataException { final Map<String,Object> json = new HashMap<String,Object>(); final String key = "foo"; JSON.getNonNull(json, key); }