Class MockTerminal


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

      Constructors 
      Constructor Description
      MockTerminal()  
    • Method Summary

      Modifier and Type Method Description
      void addSecretInput​(java.lang.String input)
      Adds an an input that will be return from readText(String).
      void addTextInput​(java.lang.String input)
      Adds an an input that will be return from readText(String).
      java.lang.String getOutput()
      Returns all output written to this terminal.
      java.io.PrintWriter getWriter()  
      char[] readSecret​(java.lang.String prompt)  
      java.lang.String readText​(java.lang.String prompt)  
      void reset()
      Wipes the input and output.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MockTerminal

        public MockTerminal()
    • Method Detail

      • readText

        public java.lang.String readText​(java.lang.String prompt)
        Specified by:
        readText in class Terminal
      • readSecret

        public char[] readSecret​(java.lang.String prompt)
        Specified by:
        readSecret in class Terminal
      • getWriter

        public java.io.PrintWriter getWriter()
        Specified by:
        getWriter in class Terminal
      • addTextInput

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

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

        public java.lang.String getOutput()
                                   throws java.io.UnsupportedEncodingException
        Returns all output written to this terminal.
        Throws:
        java.io.UnsupportedEncodingException
      • reset

        public void reset()
        Wipes the input and output.