357 * @throws RuntimeException If the exit value from the process did not match the expected value
358 */
359 public OutputAnalyzer shouldHaveExitValue(int expectedExitValue) {
360 if (getExitValue() != expectedExitValue) {
361 reportDiagnosticSummary();
362 throw new RuntimeException("Expected to get exit value of ["
363 + expectedExitValue + "]\n");
364 }
365 return this;
366 }
367
368
369 /**
370 * Report summary that will help to diagnose the problem
371 * Currently includes:
372 * - standard input produced by the process under test
373 * - standard output
374 * - exit code
375 * Note: the command line is printed by the ProcessTools
376 */
377 private void reportDiagnosticSummary() {
378 String msg =
379 " stdout: [" + stdout + "];\n" +
380 " stderr: [" + stderr + "]\n" +
381 " exitValue = " + getExitValue() + "\n";
382
383 System.err.println(msg);
384 }
385
386
387 /**
388 * Get the contents of the output buffer (stdout and stderr)
389 *
390 * @return Content of the output buffer
391 */
392 public String getOutput() {
393 return stdout + stderr;
394 }
395
396 /**
397 * Get the contents of the stdout buffer
|
357 * @throws RuntimeException If the exit value from the process did not match the expected value
358 */
359 public OutputAnalyzer shouldHaveExitValue(int expectedExitValue) {
360 if (getExitValue() != expectedExitValue) {
361 reportDiagnosticSummary();
362 throw new RuntimeException("Expected to get exit value of ["
363 + expectedExitValue + "]\n");
364 }
365 return this;
366 }
367
368
369 /**
370 * Report summary that will help to diagnose the problem
371 * Currently includes:
372 * - standard input produced by the process under test
373 * - standard output
374 * - exit code
375 * Note: the command line is printed by the ProcessTools
376 */
377 public void reportDiagnosticSummary() {
378 String msg =
379 " stdout: [" + stdout + "];\n" +
380 " stderr: [" + stderr + "]\n" +
381 " exitValue = " + getExitValue() + "\n";
382
383 System.err.println(msg);
384 }
385
386
387 /**
388 * Get the contents of the output buffer (stdout and stderr)
389 *
390 * @return Content of the output buffer
391 */
392 public String getOutput() {
393 return stdout + stderr;
394 }
395
396 /**
397 * Get the contents of the stdout buffer
|