@Test public void testGetAsyncFailureWithConnectionFailure() throws Exception { ParseRequest.setDefaultInitialRetryDelay(1L); ParseHttpClient restClient = mock(ParseHttpClient.class); when(restClient.execute(any(ParseHttpRequest.class))).thenThrow(new IOException()); ParseCurrentConfigController currentConfigController = mockParseCurrentConfigController(); ParseConfigController configController = new ParseConfigController(restClient, currentConfigController); Task<ParseConfig> configTask = configController.getAsync(null); configTask.waitForCompletion(); verify(restClient, times(5)).execute(any(ParseHttpRequest.class)); assertTrue(configTask.isFaulted()); Exception error = configTask.getError(); assertThat(error, instanceOf(ParseException.class)); assertEquals(ParseException.CONNECTION_FAILED, ((ParseException) error).getCode()); verify(currentConfigController, times(0)).setCurrentConfigAsync(any(ParseConfig.class)); }
public Task<ParseConfig> getAsync(String sessionToken) { final ParseRESTCommand command = ParseRESTConfigCommand.fetchConfigCommand(sessionToken); return command.executeAsync(restClient).onSuccessTask(new Continuation<JSONObject, Task<ParseConfig>>() { @Override public Task<ParseConfig> then(Task<JSONObject> task) { JSONObject result = task.getResult(); final ParseConfig config = ParseConfig.decode(result, ParseDecoder.get()); return currentConfigController.setCurrentConfigAsync(config).continueWith(new Continuation<Void, ParseConfig>() { @Override public ParseConfig then(Task<Void> task) { return config; } }); } }); }
ParseConfigController { public Task<ParseConfig> getAsync(String sessionToken) { final ParseRESTCommand command = ParseRESTConfigCommand.fetchConfigCommand(sessionToken); return command.executeAsync(restClient).onSuccessTask(new Continuation<JSONObject, Task<ParseConfig>>() { @Override public Task<ParseConfig> then(Task<JSONObject> task) { JSONObject result = task.getResult(); final ParseConfig config = ParseConfig.decode(result, ParseDecoder.get()); return currentConfigController.setCurrentConfigAsync(config).continueWith(new Continuation<Void, ParseConfig>() { @Override public ParseConfig then(Task<Void> task) { return config; } }); } }); } }
ParseConfigController { public Task<ParseConfig> getAsync(String sessionToken) { final ParseRESTCommand command = ParseRESTConfigCommand.fetchConfigCommand(sessionToken); return command.executeAsync(restClient).onSuccessTask(new Continuation<JSONObject, Task<ParseConfig>>() { @Override public Task<ParseConfig> then(Task<JSONObject> task) { JSONObject result = task.getResult(); final ParseConfig config = ParseConfig.decode(result, ParseDecoder.get()); return currentConfigController.setCurrentConfigAsync(config).continueWith(new Continuation<Void, ParseConfig>() { @Override public ParseConfig then(Task<Void> task) { return config; } }); } }); } ParseConfigController(ParseHttpClient restClient,
                                 ParseCurrentConfigController currentConfigController); }
ParseConfigController { public Task<ParseConfig> getAsync(String sessionToken) { final ParseRESTCommand command = ParseRESTConfigCommand.fetchConfigCommand(sessionToken); return command.executeAsync(restClient).onSuccessTask(new Continuation<JSONObject, Task<ParseConfig>>() { @Override public Task<ParseConfig> then(Task<JSONObject> task) { JSONObject result = task.getResult(); final ParseConfig config = ParseConfig.decode(result, ParseDecoder.get()); return currentConfigController.setCurrentConfigAsync(config).continueWith(new Continuation<Void, ParseConfig>() { @Override public ParseConfig then(Task<Void> task) { return config; } }); } }); } ParseConfigController(ParseHttpClient restClient,
                                 ParseCurrentConfigController currentConfigController); Task<ParseConfig> getAsync(String sessionToken); }
ParseConfigController { public Task<ParseConfig> getAsync(String sessionToken) { final ParseRESTCommand command = ParseRESTConfigCommand.fetchConfigCommand(sessionToken); return command.executeAsync(restClient).onSuccessTask(new Continuation<JSONObject, Task<ParseConfig>>() { @Override public Task<ParseConfig> then(Task<JSONObject> task) { JSONObject result = task.getResult(); final ParseConfig config = ParseConfig.decode(result, ParseDecoder.get()); return currentConfigController.setCurrentConfigAsync(config).continueWith(new Continuation<Void, ParseConfig>() { @Override public ParseConfig then(Task<Void> task) { return config; } }); } }); } ParseConfigController(ParseHttpClient restClient,
                                 ParseCurrentConfigController currentConfigController); Task<ParseConfig> getAsync(String sessionToken);  }