Class MockConsole
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
PrintStream
that allows you to easily capture console output.
Stores output into an internal ByteArrayOutputStream
. Note that this means you could run into memory
constraints if you heavily use this class.
Typically used in conjunction with the RestClient.Builder.console(PrintStream)
to capture console output for
testing purposes.
Example:
See Also:
-
Field Summary
Fields inherited from class java.io.FilterOutputStream
out
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAllows you to perform fluent-style assertions on the contents of this buffer.Allows you to perform fluent-style assertions on the size of this buffer.static MockConsole
create()
Creator.reset()
Resets the contents of this buffer.toString()
Returns the contents of this buffer as a string.Methods inherited from class java.io.PrintStream
append, append, append, charset, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write, write, writeBytes
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
MockConsole
public MockConsole()Constructor.
-
-
Method Details
-
create
Creator.- Returns:
- A new
MockConsole
object.
-
reset
Resets the contents of this buffer.- Returns:
- This object.
-
assertContents
Allows you to perform fluent-style assertions on the contents of this buffer.Example:
MockConsole
console = MockConsole.create (); MockRestClient .create (MyRest.class ) .console(console ) .debug() .json5() .build() .get("/url" ) .run();console .assertContents().isContains("HTTP GET /url" );- Returns:
- A new fluent-style assertion object.
-
assertSize
Allows you to perform fluent-style assertions on the size of this buffer.Example:
MockConsole
console = MockConsole.create (); MockRestClient .create (MyRest.class ) .console(console ) .debug() .json5() .build() .get("/url" ) .run();console .assertSize().isGreaterThan(0);- Returns:
- A new fluent-style assertion object.
-
toString
Returns the contents of this buffer as a string.
-