@Override /* package */ <T extends ParseObject> Task<T> fetchAsync( final String sessionToken, final Task<Void> toAwait) { synchronized (mutex) { // Because the Service and the global currentInstallation are different objects, we may not // have the same ObjectID (we never will at bootstrap). The server has a special hack for // _Installation where save with an existing InstallationID will merge Object IDs Task<Void> result; if (getObjectId() == null) { result = saveAsync(sessionToken, toAwait); } else { result = Task.forResult(null); } return result.onSuccessTask(new Continuation<Void, Task<T>>() { @Override public Task<T> then(Task<Void> task) { return ParseInstallation.super.fetchAsync(sessionToken, toAwait); } }); } }
@Test public void testMissingRequiredFieldWhenSaveAsync() throws Exception { String sessionToken = "sessionToken"; Task<Void> toAwait = Task.forResult(null); ParseCurrentInstallationController controller = mockCurrentInstallationController(); ParseObjectController objController = mock(ParseObjectController.class); // mock return task when Installation was deleted on the server Task<ParseObject.State> taskError = Task.forError(new ParseException(ParseException.MISSING_REQUIRED_FIELD_ERROR, "")); // mock return task when Installation was re-saved to the server Task<ParseObject.State> task = Task.forResult(null); when(objController.saveAsync( any(ParseObject.State.class), any(ParseOperationSet.class), eq(sessionToken), any(ParseDecoder.class))) .thenReturn(taskError) .thenReturn(task); ParseCorePlugins.getInstance() .registerObjectController(objController); ParseInstallation installation = ParseInstallation.getCurrentInstallation(); assertNotNull(installation); installation.put("key", "value"); ParseTaskUtils.wait(installation.saveAsync(sessionToken, toAwait)); verify(controller).getAsync(); verify(objController, times(2)).saveAsync( any(ParseObject.State.class), any(ParseOperationSet.class), eq(sessionToken), any(ParseDecoder.class)); }
installation.setState(state); installation.put("key", "value"); ParseTaskUtils.wait(installation.saveAsync(sessionToken, toAwait));