NCMBFileService extends NCMBService { public void updateFileInBackground(String fileName, JSONObject aclJson, ExecuteServiceCallback callback) { if (!validateFileName(fileName)) { if (callback != null) { callback.done(null, new NCMBException(NCMBException.REQUIRED, "fileName is must not be null or empty")); } } JSONObject content = new JSONObject(); try { content.put("acl", aclJson); } catch (JSONException e) { if (callback != null) { callback.done(null, new NCMBException(NCMBException.INVALID_JSON, e.getMessage())); } } String url = createURL(fileName); try { sendRequestAsync(url, NCMBRequest.HTTP_METHOD_PUT, content.toString(), null, new FileServiceCallback(this, callback) { @Override public void handleResponse(NCMBResponse response) { ExecuteServiceCallback callback = (ExecuteServiceCallback) mCallback; if (callback != null) { callback.done(response.responseData, null); } } @Override public void handleError(NCMBException e) { ExecuteServiceCallback callback = (ExecuteServiceCallback) mCallback; if (callback != null) { callback.done(null, e); } } }); } catch (NCMBException e) { if (callback != null) { callback.done(null, e); } } } NCMBFileService(NCMBContext context); JSONObject saveFile(String fileName, byte[] fileData, JSONObject aclJson); void saveFileInBackground(String fileName, byte[] fileData, JSONObject aclJson, ExecuteServiceCallback callback); JSONObject updateFile(String fileName, JSONObject aclJson); void updateFileInBackground(String fileName, JSONObject aclJson, ExecuteServiceCallback callback); JSONObject deleteFile(String fileName); void deleteFileInBackground(String fileName, ExecuteServiceCallback callback); byte[] fetchFile(String fileName); void fetchFileInBackground(String fileName, FetchFileCallback callback); List searchFile(JSONObject conditions); void searchFileInBackground(JSONObject conditions, SearchFileCallback callback); static final String SERVICE_PATH; }
@Test public void updateFileInBackground() throws Exception { NCMBFileService fileService = (NCMBFileService) NCMB.factory(NCMB.ServiceType.FILE); fileService.updateFileInBackground("Sample.txt", new JSONObject(), new ExecuteServiceCallback() { @Override public void done(JSONObject json, NCMBException e) { callbackFlag = true; } }); Robolectric.flushBackgroundThreadScheduler(); ShadowLooper.runUiThreadTasks(); Assert.assertTrue(callbackFlag); }