ParseFile implements Parcelable { public void cancel() { Set<TaskCompletionSource<?>> tasks = new HashSet<>(currentTasks); for (TaskCompletionSource<?> tcs : tasks) { tcs.trySetCancelled(); } currentTasks.removeAll(tasks); } ParseFile(File file);  ParseFile(File file, String contentType);  ParseFile(String name, byte[] data, String contentType);  ParseFile(byte[] data);  ParseFile(String name, byte[] data);  ParseFile(byte[] data, String contentType); protected  ParseFile(Parcel source);   ParseFile(Parcel source, ParseParcelDecoder decoder);   ParseFile(State state); @SuppressWarnings("unused")  ParseFile(JSONObject json, ParseDecoder decoder); String getName(); boolean isDirty(); boolean isDataAvailable(); String getUrl(); void save(); Task<Void> saveInBackground(final ProgressCallback uploadProgressCallback); Task<Void> saveInBackground(); void saveInBackground(final SaveCallback saveCallback,
                                 ProgressCallback progressCallback); void saveInBackground(SaveCallback callback); byte[] getData(); Task<byte[]> getDataInBackground(final ProgressCallback progressCallback); Task<byte[]> getDataInBackground(); void getDataInBackground(GetDataCallback dataCallback,
                                    final ProgressCallback progressCallback); void getDataInBackground(GetDataCallback dataCallback); File getFile(); Task<File> getFileInBackground(final ProgressCallback progressCallback); Task<File> getFileInBackground(); void getFileInBackground(GetFileCallback fileCallback,
                                    final ProgressCallback progressCallback); void getFileInBackground(GetFileCallback fileCallback); InputStream getDataStream(); Task<InputStream> getDataStreamInBackground(final ProgressCallback progressCallback); Task<InputStream> getDataStreamInBackground(); void getDataStreamInBackground(GetDataStreamCallback dataStreamCallback,
                                          final ProgressCallback progressCallback); void getDataStreamInBackground(GetDataStreamCallback dataStreamCallback); void cancel(); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); final static Creator<ParseFile> CREATOR; }
@Test public void testCancel() { ParseFile file = new ParseFile(new ParseFile.State.Builder().build()); TaskQueueTestHelper queueHelper = new TaskQueueTestHelper(file.taskQueue); queueHelper.enqueue(); List<Task<Void>> saveTasks = Arrays.asList( file.saveInBackground(), file.saveInBackground(), file.saveInBackground()); List<Task<byte[]>> getDataTasks = Arrays.asList( file.getDataInBackground(), file.getDataInBackground(), file.getDataInBackground()); file.cancel(); queueHelper.dequeue(); for (int i = 0; i < saveTasks.size(); i++) { assertTrue("Task #" + i + " was not cancelled", saveTasks.get(i).isCancelled()); } for (int i = 0; i < getDataTasks.size(); i++) { assertTrue("Task #" + i + " was not cancelled", getDataTasks.get(i).isCancelled()); } }