Skip to content

Commit c67448a

Browse files
committed
Update test case and nit changes
1 parent 259e78b commit c67448a

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

Parse/src/main/java/com/parse/ParseFileController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public ParseFile.State then(Task<JSONObject> task) throws Exception {
114114

115115
return newState;
116116
}
117-
}, Task.BACKGROUND_EXECUTOR);
117+
}, ParseExecutors.io());
118118
}
119119

120120
public Task<ParseFile.State> saveAsync(
@@ -161,7 +161,7 @@ public ParseFile.State then(Task<JSONObject> task) throws Exception {
161161

162162
return newState;
163163
}
164-
}, Task.BACKGROUND_EXECUTOR);
164+
}, ParseExecutors.io());
165165
}
166166

167167
public Task<File> fetchAsync(

Parse/src/main/java/com/parse/ParseRESTFileCommand.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public ParseRESTFileCommand build() {
6262

6363
public ParseRESTFileCommand(Builder builder) {
6464
super(builder);
65+
if (builder.file != null && builder.data != null) {
66+
throw new IllegalArgumentException("File and data can not be set at the same time");
67+
}
6568
this.data = builder.data;
6669
this.contentType = builder.contentType;
6770
this.file = builder.file;

Parse/src/test/java/com/parse/ParseFileControllerTest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,12 @@ public void testSaveAsyncSuccessWithFile() throws Exception {
186186
assertEquals("http://example.com", result.url());
187187
File cachedFile = new File(root, "new_file_name");
188188
assertTrue(cachedFile.exists());
189+
assertTrue(file.exists());
189190
assertEquals("content", ParseFileUtils.readFileToString(cachedFile, "UTF-8"));
190191
}
191192

192193
@Test
193-
public void testSaveAsyncFailure() throws Exception {
194+
public void testSaveAsyncFailureWithByteArray() throws Exception {
194195
// TODO(grantland): Remove once we no longer rely on retry logic.
195196
ParseRequest.setDefaultInitialRetryDelay(1L);
196197

@@ -215,6 +216,34 @@ public void testSaveAsyncFailure() throws Exception {
215216
assertEquals(0, root.listFiles().length);
216217
}
217218

219+
@Test
220+
public void testSaveAsyncFailureWithFile() throws Exception {
221+
// TODO(grantland): Remove once we no longer rely on retry logic.
222+
ParseRequest.setDefaultInitialRetryDelay(1L);
223+
224+
ParseHttpClient restClient = mock(ParseHttpClient.class);
225+
when(restClient.execute(any(ParseHttpRequest.class))).thenThrow(new IOException());
226+
227+
File root = temporaryFolder.getRoot();
228+
ParseFileController controller = new ParseFileController(restClient, root);
229+
230+
File file = temporaryFolder.newFile("test");
231+
ParseFile.State state = new ParseFile.State.Builder()
232+
.build();
233+
Task<ParseFile.State> task = controller.saveAsync(state, file, null, null, null);
234+
task.waitForCompletion();
235+
236+
// TODO(grantland): Abstract out command runner so we don't have to account for retries.
237+
verify(restClient, times(5)).execute(any(ParseHttpRequest.class));
238+
assertTrue(task.isFaulted());
239+
Exception error = task.getError();
240+
assertThat(error, instanceOf(ParseException.class));
241+
assertEquals(ParseException.CONNECTION_FAILED, ((ParseException) error).getCode());
242+
// Make sure the original file is not deleted and there is no cache file in the folder
243+
assertEquals(1, root.listFiles().length);
244+
assertTrue(file.exists());
245+
}
246+
218247
//endregion
219248

220249
//region testFetchAsync

0 commit comments

Comments
 (0)