提交 6a4b66a9 编写于 作者: I igerasim

8142926: OutputAnalyzer's shouldXXX() calls return this

Reviewed-by: alanb, robm
上级 1ea25df6
......@@ -90,13 +90,14 @@ public final class OutputAnalyzer {
* @throws RuntimeException
* If the string was not found
*/
public void shouldContain(String expectedString) {
public OutputAnalyzer shouldContain(String expectedString) {
if (!stdout.contains(expectedString)
&& !stderr.contains(expectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + expectedString
+ "' missing from stdout/stderr \n");
}
return this;
}
/**
......@@ -107,12 +108,13 @@ public final class OutputAnalyzer {
* @throws RuntimeException
* If the string was not found
*/
public void stdoutShouldContain(String expectedString) {
public OutputAnalyzer stdoutShouldContain(String expectedString) {
if (!stdout.contains(expectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + expectedString
+ "' missing from stdout \n");
}
return this;
}
/**
......@@ -123,24 +125,25 @@ public final class OutputAnalyzer {
* @throws RuntimeException
* If the string was not found
*/
public void stderrShouldContain(String expectedString) {
public OutputAnalyzer stderrShouldContain(String expectedString) {
if (!stderr.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 (stdout.contains(notExpectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + notExpectedString
......@@ -151,23 +154,25 @@ 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 (stdout.contains(notExpectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + notExpectedString
+ "' found in stdout \n");
}
return this;
}
/**
......@@ -195,7 +200,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(stdout);
Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE)
......@@ -205,6 +210,7 @@ public final class OutputAnalyzer {
throw new RuntimeException("'" + pattern
+ "' missing from stdout/stderr \n");
}
return this;
}
/**
......@@ -214,7 +220,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(
stdout);
if (!matcher.find()) {
......@@ -222,6 +228,7 @@ public final class OutputAnalyzer {
throw new RuntimeException("'" + pattern
+ "' missing from stdout \n");
}
return this;
}
/**
......@@ -231,7 +238,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(
stderr);
if (!matcher.find()) {
......@@ -239,6 +246,7 @@ public final class OutputAnalyzer {
throw new RuntimeException("'" + pattern
+ "' missing from stderr \n");
}
return this;
}
/**
......@@ -249,7 +257,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(
stdout);
if (matcher.find()) {
......@@ -263,6 +271,7 @@ public final class OutputAnalyzer {
throw new RuntimeException("'" + pattern + "' found in stderr: '"
+ matcher.group() + "' \n");
}
return this;
}
/**
......@@ -273,13 +282,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(
stdout);
if (matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + pattern + "' found in stdout \n");
}
return this;
}
/**
......@@ -290,13 +300,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(
stderr);
if (matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + pattern + "' found in stderr \n");
}
return this;
}
/**
......@@ -344,12 +355,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;
}
/**
......@@ -357,11 +369,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: [" + stdout + "];\n" + " stderr: [" + stderr
+ "]\n" + " exitValue = " + getExitValue() + "\n";
System.err.println(msg);
return this;
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册