I am writing a JUnit for a program created in an exercise. That means the test needs to cover as many cases as possible and I don't have any influence on how certain things in the program are implemented. Also, the program runs an infinite loop where at one point, it requires the user to input something.
For the JUnit test I run the program in another Thread
and simulate the user input from within the JUnit Thread
.
So far, everything works fine if the program reads the user input from System.in
, because this stream can easily replaced. But there's also the possiblity that the program interacts with System.console()
which currently can not be covered by my test.
Is there any possibility to simulate input for the System.console()
, e.g. by replacing its input source with another stream?
(NB: The JUnit test must use Java 6 without any external libraries (except JUnit and Hamcrest).)
Edit: Unfortunately, I can't change the classes of the program to test.