Class ConsoleManager


  • public class ConsoleManager
    extends Object
    Extension for adding a fully virtual TTY and I/O for testing. This will forcefully replace standard in, out and err while the test is running, falling back to default (system streams) when completed. This means any test that uses normal system I/O to print ongoing status will not work with this extension.
    
     {@literal@}ExtendWith(ConsoleExtension.class)
     public class MyTest {
         {@literal@}Test
         public void testMyThing(Console console) {
             // use the console I/O or TTY or both.
         }
     }
     
    • Constructor Detail

      • ConsoleManager

        public ConsoleManager()
        Create a console manager.
    • Method Detail

      • getTTY

        public net.morimekta.io.tty.TTY getTTY()
        Returns:
        The fake TTY for the console.
      • getConsole

        public Console getConsole()
        Returns:
        The console interface.
      • setTerminalSize

        public void setTerminalSize​(net.morimekta.io.tty.TTYSize terminalSize)
        Parameters:
        terminalSize - The new terminal size.
      • setInteractive

        public void setInteractive​(boolean interactive)
        Parameters:
        interactive - If the console should be interactive.
      • setDumpErrorOnFailure

        public void setDumpErrorOnFailure​(boolean dumpErrorOnFailure)
        Parameters:
        dumpErrorOnFailure - If standard ERR should be dumped on failures.
      • setForkError

        public void setForkError​(boolean forkError)
        Parameters:
        forkError - If standard ERR should be forked to original output.
      • setDumpOutputOnFailure

        public void setDumpOutputOnFailure​(boolean dumpOutputOnFailure)
        Parameters:
        dumpOutputOnFailure - If standard OUT should be dumped on failures.
      • setForkOutput

        public void setForkOutput​(boolean forkOutput)
        Parameters:
        forkOutput - If standard OUT should be forked to original output.
      • doBeforeEach

        public void doBeforeEach()
        Trigger start of test. Clears IO streams and overrides native IO.
      • onTestFailed

        public void onTestFailed​(String displayName)
        Trigger test failure. Handles eventual printing on test failure, if there is anything to print.
        Parameters:
        displayName - Display name of test.
      • doAfterEach

        public void doAfterEach()
        Trigger end of test. Set native IO streams back to original.