NCMBBase { public Date getDate(String key) { SimpleDateFormat sdf = NCMBDateFormat.getIso8601(); try { if (mFields.has(key)) { JSONObject dateJson = this.getJSONObject(key); if (dateJson != null) { if (dateJson.has("iso")) { return sdf.parse(dateJson.getString("iso")); } } } return null; } catch (JSONException | ParseException e) { return null; } } NCMBBase(String className);   NCMBBase(String className, JSONObject params); void setObjectId(String objectId); String getObjectId(); Date getCreateDate(); Date getUpdateDate(); void setAcl(NCMBAcl acl); NCMBAcl getAcl(); String getClassName(); void remove(String key); boolean containsKey(String key); void put(String key, String value); void put(String key, boolean value); void put(String key, int value); void put(String key, long value); void put(String key, float value); void put(String key, double value); void put(String key, Date value); void put(String key, Location value); void put(String key, JSONObject value); void put(String key, JSONArray value); void put(String key, Map value); void put(String key, List value); void put(String key, NCMBObject object); String getString(String key); boolean getBoolean(String key); int getInt(String key); long getLong(String key); double getDouble(String key); Date getDate(String key); Location getGeolocation(String key); JSONObject getJSONObject(String key); JSONArray getJSONArray(String key); List getList(String key); Map getMap(String key); T getIncludeObject(String key); List allKeys();  }
@Test public void get_date_value() throws Exception { NCMBBase obj = new NCMBBase("testClass", new JSONObject("{\"date\":{\"__type\":\"Date\",\"iso\":\"2015-07-29T10:10:10.000Z\"}}")); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); df.setTimeZone(new SimpleTimeZone(0, "UTC")); Assert.assertTrue(df.parse("2015-07-29 10:10:10").equals(obj.getDate("date"))); }
@Test public void get_date_from_non_exist_key() throws Exception { NCMBBase obj = new NCMBBase("testClass"); Assert.assertNull(obj.getDate("nonExistKey")); }
@Test public void get_date_null_object() throws Exception { NCMBBase obj = new NCMBBase("testClass", new JSONObject("{\"date\":null}")); Assert.assertNull(obj.getDate("date")); }