Class SystemInMock

java.lang.Object
java.io.InputStream
ru.vyarus.dropwizard.guice.test.util.io.SystemInMock
All Implemented Interfaces:
Closeable, AutoCloseable

public class SystemInMock extends 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 Details

    • SystemInMock

      public SystemInMock()
      Create system in substitutor.
  • Method Details

    • provideText

      public void provideText(String... lines)
      Parameters:
      lines - mock system in source
    • read

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

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

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