@Test public void executeAndThrowOnFailureScriptFail() throws Exception { try { externalProcessRunner.executeAndThrowOnFailure(MOCK_FAIL_SCRIPT, SCRIPT_ARGS); } catch (ProcessFailedException e) { assertEquals(PROCESS_FAILED, e.getErrorDeviation().getCode()); } }
public ProcessResult executeAndThrowOnFailure(String command, String... args) throws ProcessNotExecutableException, ProcessFailedException, InterruptedException { ProcessResult processResult = execute(command, args); if (processResult.getExitCode() != 0) { String processOutputString = processOutputToString(processResult.processOutput); String errorMsg = String.format("Failed to run command '%s' with output: %n %s", processResult.commandWithArgs, processOutputString); log.error(errorMsg); throw new ProcessFailedException(errorMsg, processResult.processOutput); } return processResult; }
ExternalProcessRunner { public ProcessResult executeAndThrowOnFailure(String command, String... args) throws ProcessNotExecutableException, ProcessFailedException, InterruptedException { ProcessResult processResult = execute(command, args); if (processResult.getExitCode() != 0) { String processOutputString = processOutputToString(processResult.processOutput); String errorMsg = String.format("Failed to run command '%s' with output: %n %s", processResult.commandWithArgs, processOutputString); log.error(errorMsg); throw new ProcessFailedException(errorMsg, processResult.processOutput); } return processResult; } }
ExternalProcessRunner { public ProcessResult executeAndThrowOnFailure(String command, String... args) throws ProcessNotExecutableException, ProcessFailedException, InterruptedException { ProcessResult processResult = execute(command, args); if (processResult.getExitCode() != 0) { String processOutputString = processOutputToString(processResult.processOutput); String errorMsg = String.format("Failed to run command '%s' with output: %n %s", processResult.commandWithArgs, processOutputString); log.error(errorMsg); throw new ProcessFailedException(errorMsg, processResult.processOutput); } return processResult; }  }
ExternalProcessRunner { public ProcessResult executeAndThrowOnFailure(String command, String... args) throws ProcessNotExecutableException, ProcessFailedException, InterruptedException { ProcessResult processResult = execute(command, args); if (processResult.getExitCode() != 0) { String processOutputString = processOutputToString(processResult.processOutput); String errorMsg = String.format("Failed to run command '%s' with output: %n %s", processResult.commandWithArgs, processOutputString); log.error(errorMsg); throw new ProcessFailedException(errorMsg, processResult.processOutput); } return processResult; }  ProcessResult execute(String command, String... args); ProcessResult executeAndThrowOnFailure(String command, String... args); static String processOutputToString(List<String> processOutput); }
ExternalProcessRunner { public ProcessResult executeAndThrowOnFailure(String command, String... args) throws ProcessNotExecutableException, ProcessFailedException, InterruptedException { ProcessResult processResult = execute(command, args); if (processResult.getExitCode() != 0) { String processOutputString = processOutputToString(processResult.processOutput); String errorMsg = String.format("Failed to run command '%s' with output: %n %s", processResult.commandWithArgs, processOutputString); log.error(errorMsg); throw new ProcessFailedException(errorMsg, processResult.processOutput); } return processResult; }  ProcessResult execute(String command, String... args); ProcessResult executeAndThrowOnFailure(String command, String... args); static String processOutputToString(List<String> processOutput);  }