JDK-8222713 : Add OutputAnalyzer(Path) constructor
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 13
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-04-18
  • Updated: 2019-11-02
  • Resolved: 2019-04-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 13
13 b18Fixed
Related Reports
Duplicate :  
Relates :  
Description
This is useful for looking for patterns in logging files that can grow quite large.
This is taken from code from 

    /**
     * Verify that the contents of the file contains the given the set of strings
     *
     * @param file File to check for expectedStrings
     * @param expectedStrings Strings that file should contain
     * @throws RuntimeException If the string was not found
     * @throws IOException If the file cannot be opened
     */
    public OutputAnalyzer shouldContain(File file, String ... expectedStrings) throws IOException {

Comments
import java.nio.file.Files; ... OutputAnalyzer fileContents = new OutputAnalyzer(Files.readString(<file Path>)); So no need for a new API unless you want to add a shouldContain(String ... expected) to process multiple strings.
18-04-2019

OutputAnalyzer can be created using a process, from which the output streams are extracted and the contents analyzed; or from a String (which is presumed to be the captured output of a process), so a natural extension to that could be to create one using a File that contains the process output. Though you can also convert a file's contents into a String and use the existing OutputAnalyzer(String) constructor. I don't think an instance method, shouldContain, that takes a file and only operates on that file makes sense for OutputAnalyzer.
18-04-2019