test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java

Print this page
rev 6890 : [mq]: coops

@@ -72,143 +72,152 @@
    * Verify that the stdout and stderr contents of output buffer contains the string
    *
    * @param expectedString String that buffer should contain
    * @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;
   }
 
   /**
    * Verify that the stdout contents of output buffer contains the string
    *
    * @param expectedString String that buffer should contain
    * @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;
   }
 
   /**
    * Verify that the stderr contents of output buffer contains the string
    *
    * @param expectedString String that buffer should contain
    * @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 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 + "' found in stdout \n");
     }
     if (stderr.contains(notExpectedString)) {
         reportDiagnosticSummary();
         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 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;
   }
 
   /**
    * Verify that the stderr contents of output buffer does not contain the string
    *
    * @param expectedString 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 (stderr.contains(notExpectedString)) {
         reportDiagnosticSummary();
         throw new RuntimeException("'" + notExpectedString + "' found in stderr \n");
     }
+    return this;
   }
 
   /**
    * Verify that the stdout and stderr contents of output buffer matches
    * the pattern
    *
    * @param pattern
    * @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).matcher(stderr);
       if (!stdoutMatcher.find() && !stderrMatcher.find()) {
           reportDiagnosticSummary();
           throw new RuntimeException("'" + pattern
                 + "' missing from stdout/stderr \n");
       }
+      return this;
   }
 
   /**
    * Verify that the stdout contents of output buffer matches the
    * pattern
    *
    * @param pattern
    * @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()) {
           reportDiagnosticSummary();
           throw new RuntimeException("'" + pattern
                 + "' missing from stdout \n");
       }
+      return this;
   }
 
   /**
    * Verify that the stderr contents of output buffer matches the
    * pattern
    *
    * @param pattern
    * @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()) {
           reportDiagnosticSummary();
           throw new RuntimeException("'" + pattern
                 + "' missing from stderr \n");
       }
+      return this;
   }
 
   /**
    * Verify that the stdout and stderr contents of output buffer does not
    * match the pattern
    *
    * @param pattern
    * @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()) {
           reportDiagnosticSummary();
           throw new RuntimeException("'" + pattern
                   + "' found in stdout: '" + matcher.group() + "' \n");

@@ -217,42 +226,45 @@
       if (matcher.find()) {
           reportDiagnosticSummary();
           throw new RuntimeException("'" + pattern
                   + "' found in stderr: '" + matcher.group() + "' \n");
       }
+      return this;
   }
 
   /**
    * Verify that the stdout contents of output buffer does not match the
    * pattern
    *
    * @param pattern
    * @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;
   }
 
   /**
    * Verify that the stderr contents of output buffer does not match the
    * pattern
    *
    * @param pattern
    * @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;
   }
 
   /**
    * Get the captured group of the first string matching the pattern.
    * stderr is searched before stdout.

@@ -288,16 +300,17 @@
    * Verify the exit value of the process
    *
    * @param expectedExitValue Expected exit value from process
    * @throws RuntimeException 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;
   }
 
 
   /**
    * Report summary that will help to diagnose the problem