JSONObjectWrapper extends JSONObject { @Override public JSONObjectWrapper put(String key, Object value) { try{ super.put(key, value); return this; } catch (JSONException e) { throw new NullPointerException(e.getMessage()); } }  @Override JSONObjectWrapper put(String key, Object value);  }
@Test public void testExceptionWrapping() { JSONObjectWrapper wrapper = new JSONObjectWrapper(); try{ wrapper.put(null, "foo"); } catch (NullPointerException e) { assertEquals("Null key.", e.getMessage()); } }