Class SystemInMock

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class SystemInMock
    extends java.io.InputStream
    System in mock implementation. Should be used to substitute system input stream in order to mock user input in tests. SystemInMock in = new SystemInMock(); System.setIn(in); in.provideText(..);.

    Error would be thrown in case of not enough user inputs provided.

    Original code taken from System rules library (see TextFromStandardInputStream) with some modifications.

    Since:
    20.11.2023
    • Constructor Summary

      Constructors 
      Constructor Description
      SystemInMock()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getReads()  
      void provideText​(java.lang.String... lines)  
      int read()  
      int read​(byte[] buffer, int offset, int len)  
      • Methods inherited from class java.io.InputStream

        available, close, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

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

      • SystemInMock

        public SystemInMock()
    • Method Detail

      • provideText

        public void provideText​(java.lang.String... lines)
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] buffer,
                        int offset,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • getReads

        public int getReads()
        Returns:
        count of user input requests