Class MockTerminal

java.lang.Object
org.elasticsearch.cli.Terminal
org.elasticsearch.cli.MockTerminal

public class MockTerminal extends org.elasticsearch.cli.Terminal
A terminal for tests which captures all output, and can be plugged with fake input.
  • Constructor Details

    • MockTerminal

      public MockTerminal()
  • Method Details

    • readText

      public String readText(String prompt)
      Specified by:
      readText in class org.elasticsearch.cli.Terminal
    • readSecret

      public char[] readSecret(String prompt)
      Specified by:
      readSecret in class org.elasticsearch.cli.Terminal
    • getWriter

      public PrintWriter getWriter()
      Specified by:
      getWriter in class org.elasticsearch.cli.Terminal
    • getOutputStream

      public OutputStream getOutputStream()
      Specified by:
      getOutputStream in class org.elasticsearch.cli.Terminal
    • getErrorWriter

      public PrintWriter getErrorWriter()
      Overrides:
      getErrorWriter in class org.elasticsearch.cli.Terminal
    • setHasOutputStream

      public void setHasOutputStream(boolean hasOutputStream)
    • addTextInput

      public void addTextInput(String input)
      Adds an an input that will be return from readText(String). Values are read in FIFO order.
    • addSecretInput

      public void addSecretInput(String input)
      Adds an an input that will be return from readSecret(String). Values are read in FIFO order.
    • getOutput

      public String getOutput() throws UnsupportedEncodingException
      Returns all output written to this terminal.
      Throws:
      UnsupportedEncodingException
    • getOutputBytes

      public byte[] getOutputBytes()
      Returns all bytes written to this terminal.
    • getErrorOutput

      public String getErrorOutput() throws UnsupportedEncodingException
      Returns all output written to this terminal.
      Throws:
      UnsupportedEncodingException
    • reset

      public void reset()
      Wipes the input and output.