Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking Java InputStream

Tags:

java

mocking

Please provide pointers to help me mock that java InputStream object. This is the line of code that I would wish to Mock:

InputStreamReader inputData = new InputStreamReader(System.in); bufferdReader = new BufferedReader(inputData); bufferdReader.readLine();  
like image 518
Reji Avatar asked Jun 16 '11 11:06

Reji


People also ask

How do you create an InputStream string?

We can convert a String to an InputStream object by using the ByteArrayInputStream class. This class constructor takes the string byte array which can be done by calling the getBytes() method of a String class.


1 Answers

You could use commons-io to create some stub input streams:

InputStream stubInputStream =       IOUtils.toInputStream("some test data for my input stream", "UTF-8"); 
like image 77
Eric Avatar answered Oct 14 '22 10:10

Eric