NCMBObject extends NCMBBase { public void fetch() throws NCMBException { NCMBObjectService objService = (NCMBObjectService) NCMB.factory(NCMB.ServiceType.OBJECT); NCMBObject obj = objService.fetchObject(mClassName, getObjectId()); mFields = obj.mFields; } NCMBObject(String className);   NCMBObject(String className, JSONObject params); void save(); void saveInBackground(final DoneCallback callback); void fetch(); void fetchInBackground(); void fetchInBackground(final FetchCallback callback); void deleteObject(); void deleteObjectInBackground(final DoneCallback callback); void increment(String key, int amount); void addToList(String key, List objects); void addUniqueToList(String key, List objects); void removeFromList(String key, List objects);  }
@Test public void fetch_object() throws Exception { NCMBObject obj = new NCMBObject("TestClass"); obj.setObjectId("getTestObjectId"); obj.fetch(); Assert.assertEquals("7FrmPTBKSNtVjajm", obj.getObjectId()); Assert.assertEquals("value", obj.getString("key")); SimpleDateFormat df = NCMBDateFormat.getIso8601(); Assert.assertTrue(obj.getCreateDate().equals(df.parse("2014-06-03T11:28:30.348Z"))); Assert.assertTrue(obj.getUpdateDate().equals(df.parse("2014-06-03T11:28:30.348Z"))); JSONAssert.assertEquals("{}", obj.getAcl().toJson().toString(), false); }
@Test public void fetchObject_non_object_id() { NCMBObject obj = new NCMBObject("testClass"); try { obj.fetch(); } catch (NCMBException e) { Assert.assertEquals(NCMBException.REQUIRED, e.getCode()); } }
@Test public void fetchObject_non_exist_object() { NCMBObject obj = new NCMBObject("TestClass"); try { obj.setObjectId("NonExistObject"); obj.fetch(); } catch (NCMBException e) { Assert.assertEquals(NCMBException.DATA_NOT_FOUND, e.getCode()); } }