Class SystemInMock
- java.lang.Object
-
- java.io.InputStream
-
- ru.vyarus.dropwizard.guice.test.util.io.SystemInMock
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class SystemInMock extends java.io.InputStreamSystem 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()Create system in substitutor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetReads()voidprovideText(java.lang.String... lines)intread()intread(byte[] buffer, int offset, int len)
-
-
-
Method Detail
-
provideText
public void provideText(java.lang.String... lines)
- Parameters:
lines- mock system in source
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] buffer, int offset, int len) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
getReads
public int getReads()
- Returns:
- count of user input requests
-
-