JSONParser { public long parseLong(JSONObject object, String name) { try { return object.getLong(name); } catch (JSONException e) { if (DEBUG) Log.e(TAG, "No long value for " + name, e); return 0; } }  String parseString(JSONObject object, String name); long parseLong(JSONObject object, String name); boolean parseBoolean(JSONObject object, String name); JSONObject parseJSONObject(JSONObject object, String name); JSONArray parseJSONArray(JSONObject object, String name);  }
@Test public void test_parseLong() throws Exception { JSONObject object = new JSONObject(); object.put("test", 111l); assertEquals(111l, parser.parseLong(object, "test")); }
@Test public void test_parseLong_null() throws Exception { JSONObject object = new JSONObject(); object.put("test", 111l); assertEquals(0, parser.parseLong(object, "not_valid")); }