8142926: OutputAnalyzer's shouldXXX() calls return this
Reviewed-by: alanb
This commit is contained in:
parent
39cb0e2223
commit
0793aa183c
@ -45,7 +45,7 @@ public final class OutputAnalyzer {
|
||||
* value from a Process.
|
||||
* <p>
|
||||
* OutputAnalyzer should never be instantiated directly -
|
||||
* use {@linkplain ProcessTools#executeProcess(p)} instead
|
||||
* use {@linkplain ProcessTools#executeProcess(ProcessBuilder)} instead
|
||||
*
|
||||
* @param process
|
||||
* Process to analyze
|
||||
@ -93,13 +93,14 @@ public final class OutputAnalyzer {
|
||||
* @throws RuntimeException
|
||||
* If the string was not found
|
||||
*/
|
||||
public void shouldContain(String expectedString) {
|
||||
public OutputAnalyzer shouldContain(String expectedString) {
|
||||
if (!getStdout().contains(expectedString)
|
||||
&& !getStderr().contains(expectedString)) {
|
||||
reportDiagnosticSummary();
|
||||
throw new RuntimeException("'" + expectedString
|
||||
+ "' missing from stdout/stderr \n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,12 +111,13 @@ public final class OutputAnalyzer {
|
||||
* @throws RuntimeException
|
||||
* If the string was not found
|
||||
*/
|
||||
public void stdoutShouldContain(String expectedString) {
|
||||
public OutputAnalyzer stdoutShouldContain(String expectedString) {
|
||||
if (!getStdout().contains(expectedString)) {
|
||||
reportDiagnosticSummary();
|
||||
throw new RuntimeException("'" + expectedString
|
||||
+ "' missing from stdout \n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,24 +128,25 @@ public final class OutputAnalyzer {
|
||||
* @throws RuntimeException
|
||||
* If the string was not found
|
||||
*/
|
||||
public void stderrShouldContain(String expectedString) {
|
||||
public OutputAnalyzer stderrShouldContain(String expectedString) {
|
||||
if (!getStderr().contains(expectedString)) {
|
||||
reportDiagnosticSummary();
|
||||
throw new RuntimeException("'" + expectedString
|
||||
+ "' missing from stderr \n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the stdout and stderr contents of output buffer does not
|
||||
* contain the string
|
||||
*
|
||||
* @param expectedString
|
||||
* @param notExpectedString
|
||||
* String that the buffer should not contain
|
||||
* @throws RuntimeException
|
||||
* If the string was found
|
||||
*/
|
||||
public void shouldNotContain(String notExpectedString) {
|
||||
public OutputAnalyzer shouldNotContain(String notExpectedString) {
|
||||
if (getStdout().contains(notExpectedString)) {
|
||||
reportDiagnosticSummary();
|
||||
throw new RuntimeException("'" + notExpectedString
|
||||
@ -154,40 +157,43 @@ public final class OutputAnalyzer {
|
||||
throw new RuntimeException("'" + notExpectedString
|
||||
+ "' found in stderr \n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the stdout contents of output buffer does not contain the
|
||||
* string
|
||||
*
|
||||
* @param expectedString
|
||||
* @param notExpectedString
|
||||
* String that the buffer should not contain
|
||||
* @throws RuntimeException
|
||||
* If the string was found
|
||||
*/
|
||||
public void stdoutShouldNotContain(String notExpectedString) {
|
||||
public OutputAnalyzer stdoutShouldNotContain(String notExpectedString) {
|
||||
if (getStdout().contains(notExpectedString)) {
|
||||
reportDiagnosticSummary();
|
||||
throw new RuntimeException("'" + notExpectedString
|
||||
+ "' found in stdout \n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the stderr contents of output buffer does not contain the
|
||||
* string
|
||||
*
|
||||
* @param expectedString
|
||||
* @param notExpectedString
|
||||
* String that the buffer should not contain
|
||||
* @throws RuntimeException
|
||||
* If the string was found
|
||||
*/
|
||||
public void stderrShouldNotContain(String notExpectedString) {
|
||||
public OutputAnalyzer stderrShouldNotContain(String notExpectedString) {
|
||||
if (getStderr().contains(notExpectedString)) {
|
||||
reportDiagnosticSummary();
|
||||
throw new RuntimeException("'" + notExpectedString
|
||||
+ "' found in stderr \n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,7 +204,7 @@ public final class OutputAnalyzer {
|
||||
* @throws RuntimeException
|
||||
* If the pattern was not found
|
||||
*/
|
||||
public void shouldMatch(String pattern) {
|
||||
public OutputAnalyzer shouldMatch(String pattern) {
|
||||
Matcher stdoutMatcher = Pattern.compile(pattern, Pattern.MULTILINE)
|
||||
.matcher(getStdout());
|
||||
Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE)
|
||||
@ -208,6 +214,7 @@ public final class OutputAnalyzer {
|
||||
throw new RuntimeException("'" + pattern
|
||||
+ "' missing from stdout/stderr \n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -217,7 +224,7 @@ public final class OutputAnalyzer {
|
||||
* @throws RuntimeException
|
||||
* If the pattern was not found
|
||||
*/
|
||||
public void stdoutShouldMatch(String pattern) {
|
||||
public OutputAnalyzer stdoutShouldMatch(String pattern) {
|
||||
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
|
||||
getStdout());
|
||||
if (!matcher.find()) {
|
||||
@ -225,6 +232,7 @@ public final class OutputAnalyzer {
|
||||
throw new RuntimeException("'" + pattern
|
||||
+ "' missing from stdout \n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -234,7 +242,7 @@ public final class OutputAnalyzer {
|
||||
* @throws RuntimeException
|
||||
* If the pattern was not found
|
||||
*/
|
||||
public void stderrShouldMatch(String pattern) {
|
||||
public OutputAnalyzer stderrShouldMatch(String pattern) {
|
||||
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
|
||||
getStderr());
|
||||
if (!matcher.find()) {
|
||||
@ -242,6 +250,7 @@ public final class OutputAnalyzer {
|
||||
throw new RuntimeException("'" + pattern
|
||||
+ "' missing from stderr \n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -252,7 +261,7 @@ public final class OutputAnalyzer {
|
||||
* @throws RuntimeException
|
||||
* If the pattern was found
|
||||
*/
|
||||
public void shouldNotMatch(String pattern) {
|
||||
public OutputAnalyzer shouldNotMatch(String pattern) {
|
||||
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
|
||||
getStdout());
|
||||
if (matcher.find()) {
|
||||
@ -266,6 +275,7 @@ public final class OutputAnalyzer {
|
||||
throw new RuntimeException("'" + pattern + "' found in stderr: '"
|
||||
+ matcher.group() + "' \n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,13 +286,14 @@ public final class OutputAnalyzer {
|
||||
* @throws RuntimeException
|
||||
* If the pattern was found
|
||||
*/
|
||||
public void stdoutShouldNotMatch(String pattern) {
|
||||
public OutputAnalyzer stdoutShouldNotMatch(String pattern) {
|
||||
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
|
||||
getStdout());
|
||||
if (matcher.find()) {
|
||||
reportDiagnosticSummary();
|
||||
throw new RuntimeException("'" + pattern + "' found in stdout \n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -293,13 +304,14 @@ public final class OutputAnalyzer {
|
||||
* @throws RuntimeException
|
||||
* If the pattern was found
|
||||
*/
|
||||
public void stderrShouldNotMatch(String pattern) {
|
||||
public OutputAnalyzer stderrShouldNotMatch(String pattern) {
|
||||
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
|
||||
getStderr());
|
||||
if (matcher.find()) {
|
||||
reportDiagnosticSummary();
|
||||
throw new RuntimeException("'" + pattern + "' found in stderr \n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -347,12 +359,13 @@ public final class OutputAnalyzer {
|
||||
* If the exit value from the process did not match the expected
|
||||
* value
|
||||
*/
|
||||
public void shouldHaveExitValue(int expectedExitValue) {
|
||||
public OutputAnalyzer shouldHaveExitValue(int expectedExitValue) {
|
||||
if (getExitValue() != expectedExitValue) {
|
||||
reportDiagnosticSummary();
|
||||
throw new RuntimeException("Expected to get exit value of ["
|
||||
+ expectedExitValue + "]\n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -360,11 +373,12 @@ public final class OutputAnalyzer {
|
||||
* - standard input produced by the process under test - standard output -
|
||||
* exit code Note: the command line is printed by the ProcessTools
|
||||
*/
|
||||
private void reportDiagnosticSummary() {
|
||||
private OutputAnalyzer reportDiagnosticSummary() {
|
||||
String msg = " stdout: [" + getStdout() + "];\n" + " stderr: [" + getStderr()
|
||||
+ "]\n" + " exitValue = " + getExitValue() + "\n";
|
||||
|
||||
System.err.println(msg);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user