@Test(expected = RuntimeException.class) public void testInstallationObjectIdCannotBeChanged() { boolean hasException = false; ParseInstallation installation = new ParseInstallation(); try { installation.put("objectId", "abc"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("Cannot modify")); hasException = true; } assertTrue(hasException); installation.setObjectId("abc"); }
@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)); }
assertNotNull(installation); installation.setState(state); installation.put("key", "value"); ParseTaskUtils.wait(installation.saveAsync(sessionToken, toAwait));
@Test public void testHandleSaveResultAsync() throws Exception { // Mock currentInstallationController to make setAsync work ParseCurrentInstallationController controller = mock(ParseCurrentInstallationController.class); when(controller.setAsync(any(ParseInstallation.class))).thenReturn(Task.<Void>forResult(null)); ParseCorePlugins.getInstance().registerCurrentInstallationController(controller); // Mock return state ParseInstallation.State state = new ParseInstallation.State.Builder("_Installation") .put("key", "value") .build(); ParseInstallation installation = new ParseInstallation(); installation.put("keyAgain", "valueAgain"); ParseOperationSet operationSet = installation.startSave(); ParseTaskUtils.wait(installation.handleSaveResultAsync(state, operationSet)); // Make sure the installation data is correct assertEquals("value", installation.get("key")); assertEquals("valueAgain", installation.get("keyAgain")); // Make sure we set the currentInstallation verify(controller, times(1)).setAsync(installation); }