提交 d960a088 编写于 作者: I igerasim

8142926: OutputAnalyzer's shouldXXX() calls return this

Reviewed-by: alanb, robm
上级 35e5bd95
...@@ -90,13 +90,14 @@ public final class OutputAnalyzer { ...@@ -90,13 +90,14 @@ public final class OutputAnalyzer {
* @throws RuntimeException * @throws RuntimeException
* If the string was not found * If the string was not found
*/ */
public void shouldContain(String expectedString) { public OutputAnalyzer shouldContain(String expectedString) {
if (!stdout.contains(expectedString) if (!stdout.contains(expectedString)
&& !stderr.contains(expectedString)) { && !stderr.contains(expectedString)) {
reportDiagnosticSummary(); reportDiagnosticSummary();
throw new RuntimeException("'" + expectedString throw new RuntimeException("'" + expectedString
+ "' missing from stdout/stderr \n"); + "' missing from stdout/stderr \n");
} }
return this;
} }
/** /**
...@@ -107,12 +108,13 @@ public final class OutputAnalyzer { ...@@ -107,12 +108,13 @@ public final class OutputAnalyzer {
* @throws RuntimeException * @throws RuntimeException
* If the string was not found * If the string was not found
*/ */
public void stdoutShouldContain(String expectedString) { public OutputAnalyzer stdoutShouldContain(String expectedString) {
if (!stdout.contains(expectedString)) { if (!stdout.contains(expectedString)) {
reportDiagnosticSummary(); reportDiagnosticSummary();
throw new RuntimeException("'" + expectedString throw new RuntimeException("'" + expectedString
+ "' missing from stdout \n"); + "' missing from stdout \n");
} }
return this;
} }
/** /**
...@@ -123,24 +125,25 @@ public final class OutputAnalyzer { ...@@ -123,24 +125,25 @@ public final class OutputAnalyzer {
* @throws RuntimeException * @throws RuntimeException
* If the string was not found * If the string was not found
*/ */
public void stderrShouldContain(String expectedString) { public OutputAnalyzer stderrShouldContain(String expectedString) {
if (!stderr.contains(expectedString)) { if (!stderr.contains(expectedString)) {
reportDiagnosticSummary(); reportDiagnosticSummary();
throw new RuntimeException("'" + expectedString throw new RuntimeException("'" + expectedString
+ "' missing from stderr \n"); + "' missing from stderr \n");
} }
return this;
} }
/** /**
* Verify that the stdout and stderr contents of output buffer does not * Verify that the stdout and stderr contents of output buffer does not
* contain the string * contain the string
* *
* @param expectedString * @param notExpectedString
* String that the buffer should not contain * String that the buffer should not contain
* @throws RuntimeException * @throws RuntimeException
* If the string was found * If the string was found
*/ */
public void shouldNotContain(String notExpectedString) { public OutputAnalyzer shouldNotContain(String notExpectedString) {
if (stdout.contains(notExpectedString)) { if (stdout.contains(notExpectedString)) {
reportDiagnosticSummary(); reportDiagnosticSummary();
throw new RuntimeException("'" + notExpectedString throw new RuntimeException("'" + notExpectedString
...@@ -151,23 +154,25 @@ public final class OutputAnalyzer { ...@@ -151,23 +154,25 @@ public final class OutputAnalyzer {
throw new RuntimeException("'" + notExpectedString throw new RuntimeException("'" + notExpectedString
+ "' found in stderr \n"); + "' found in stderr \n");
} }
return this;
} }
/** /**
* Verify that the stdout contents of output buffer does not contain the * Verify that the stdout contents of output buffer does not contain the
* string * string
* *
* @param expectedString * @param notExpectedString
* String that the buffer should not contain * String that the buffer should not contain
* @throws RuntimeException * @throws RuntimeException
* If the string was found * If the string was found
*/ */
public void stdoutShouldNotContain(String notExpectedString) { public OutputAnalyzer stdoutShouldNotContain(String notExpectedString) {
if (stdout.contains(notExpectedString)) { if (stdout.contains(notExpectedString)) {
reportDiagnosticSummary(); reportDiagnosticSummary();
throw new RuntimeException("'" + notExpectedString throw new RuntimeException("'" + notExpectedString
+ "' found in stdout \n"); + "' found in stdout \n");
} }
return this;
} }
/** /**
...@@ -195,7 +200,7 @@ public final class OutputAnalyzer { ...@@ -195,7 +200,7 @@ public final class OutputAnalyzer {
* @throws RuntimeException * @throws RuntimeException
* If the pattern was not found * If the pattern was not found
*/ */
public void shouldMatch(String pattern) { public OutputAnalyzer shouldMatch(String pattern) {
Matcher stdoutMatcher = Pattern.compile(pattern, Pattern.MULTILINE) Matcher stdoutMatcher = Pattern.compile(pattern, Pattern.MULTILINE)
.matcher(stdout); .matcher(stdout);
Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE) Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE)
...@@ -205,6 +210,7 @@ public final class OutputAnalyzer { ...@@ -205,6 +210,7 @@ public final class OutputAnalyzer {
throw new RuntimeException("'" + pattern throw new RuntimeException("'" + pattern
+ "' missing from stdout/stderr \n"); + "' missing from stdout/stderr \n");
} }
return this;
} }
/** /**
...@@ -214,7 +220,7 @@ public final class OutputAnalyzer { ...@@ -214,7 +220,7 @@ public final class OutputAnalyzer {
* @throws RuntimeException * @throws RuntimeException
* If the pattern was not found * If the pattern was not found
*/ */
public void stdoutShouldMatch(String pattern) { public OutputAnalyzer stdoutShouldMatch(String pattern) {
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher( Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
stdout); stdout);
if (!matcher.find()) { if (!matcher.find()) {
...@@ -222,6 +228,7 @@ public final class OutputAnalyzer { ...@@ -222,6 +228,7 @@ public final class OutputAnalyzer {
throw new RuntimeException("'" + pattern throw new RuntimeException("'" + pattern
+ "' missing from stdout \n"); + "' missing from stdout \n");
} }
return this;
} }
/** /**
...@@ -231,7 +238,7 @@ public final class OutputAnalyzer { ...@@ -231,7 +238,7 @@ public final class OutputAnalyzer {
* @throws RuntimeException * @throws RuntimeException
* If the pattern was not found * If the pattern was not found
*/ */
public void stderrShouldMatch(String pattern) { public OutputAnalyzer stderrShouldMatch(String pattern) {
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher( Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
stderr); stderr);
if (!matcher.find()) { if (!matcher.find()) {
...@@ -239,6 +246,7 @@ public final class OutputAnalyzer { ...@@ -239,6 +246,7 @@ public final class OutputAnalyzer {
throw new RuntimeException("'" + pattern throw new RuntimeException("'" + pattern
+ "' missing from stderr \n"); + "' missing from stderr \n");
} }
return this;
} }
/** /**
...@@ -249,7 +257,7 @@ public final class OutputAnalyzer { ...@@ -249,7 +257,7 @@ public final class OutputAnalyzer {
* @throws RuntimeException * @throws RuntimeException
* If the pattern was found * If the pattern was found
*/ */
public void shouldNotMatch(String pattern) { public OutputAnalyzer shouldNotMatch(String pattern) {
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher( Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
stdout); stdout);
if (matcher.find()) { if (matcher.find()) {
...@@ -263,6 +271,7 @@ public final class OutputAnalyzer { ...@@ -263,6 +271,7 @@ public final class OutputAnalyzer {
throw new RuntimeException("'" + pattern + "' found in stderr: '" throw new RuntimeException("'" + pattern + "' found in stderr: '"
+ matcher.group() + "' \n"); + matcher.group() + "' \n");
} }
return this;
} }
/** /**
...@@ -273,13 +282,14 @@ public final class OutputAnalyzer { ...@@ -273,13 +282,14 @@ public final class OutputAnalyzer {
* @throws RuntimeException * @throws RuntimeException
* If the pattern was found * If the pattern was found
*/ */
public void stdoutShouldNotMatch(String pattern) { public OutputAnalyzer stdoutShouldNotMatch(String pattern) {
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher( Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
stdout); stdout);
if (matcher.find()) { if (matcher.find()) {
reportDiagnosticSummary(); reportDiagnosticSummary();
throw new RuntimeException("'" + pattern + "' found in stdout \n"); throw new RuntimeException("'" + pattern + "' found in stdout \n");
} }
return this;
} }
/** /**
...@@ -290,13 +300,14 @@ public final class OutputAnalyzer { ...@@ -290,13 +300,14 @@ public final class OutputAnalyzer {
* @throws RuntimeException * @throws RuntimeException
* If the pattern was found * If the pattern was found
*/ */
public void stderrShouldNotMatch(String pattern) { public OutputAnalyzer stderrShouldNotMatch(String pattern) {
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher( Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
stderr); stderr);
if (matcher.find()) { if (matcher.find()) {
reportDiagnosticSummary(); reportDiagnosticSummary();
throw new RuntimeException("'" + pattern + "' found in stderr \n"); throw new RuntimeException("'" + pattern + "' found in stderr \n");
} }
return this;
} }
/** /**
...@@ -344,12 +355,13 @@ public final class OutputAnalyzer { ...@@ -344,12 +355,13 @@ public final class OutputAnalyzer {
* If the exit value from the process did not match the expected * If the exit value from the process did not match the expected
* value * value
*/ */
public void shouldHaveExitValue(int expectedExitValue) { public OutputAnalyzer shouldHaveExitValue(int expectedExitValue) {
if (getExitValue() != expectedExitValue) { if (getExitValue() != expectedExitValue) {
reportDiagnosticSummary(); reportDiagnosticSummary();
throw new RuntimeException("Expected to get exit value of [" throw new RuntimeException("Expected to get exit value of ["
+ expectedExitValue + "]\n"); + expectedExitValue + "]\n");
} }
return this;
} }
/** /**
...@@ -357,11 +369,12 @@ public final class OutputAnalyzer { ...@@ -357,11 +369,12 @@ public final class OutputAnalyzer {
* - standard input produced by the process under test - standard output - * - standard input produced by the process under test - standard output -
* exit code Note: the command line is printed by the ProcessTools * exit code Note: the command line is printed by the ProcessTools
*/ */
private void reportDiagnosticSummary() { private OutputAnalyzer reportDiagnosticSummary() {
String msg = " stdout: [" + stdout + "];\n" + " stderr: [" + stderr String msg = " stdout: [" + stdout + "];\n" + " stderr: [" + stderr
+ "]\n" + " exitValue = " + getExitValue() + "\n"; + "]\n" + " exitValue = " + getExitValue() + "\n";
System.err.println(msg); System.err.println(msg);
return this;
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册