title: Java I/O - Simulate input for System.console()
body: <p>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.<br>
  For the JUnit test I run the program in another <code>Thread</code> and simulate the user input from within the JUnit <code>Thread</code>.</p>
  
  <p>So far, everything works fine if the program reads the user input from <code>System.in</code>, because this stream can easily replaced. But there's also the possiblity that the program interacts with <code>System.console()</code> which currently can not be covered by my test.</p>
  
  <p><strong>Is there any possibility to simulate input for the <code>System.console()</code>, e.g. by replacing its input source with another stream?</strong></p>
  
  <p>(NB: The JUnit test must use Java 6 without any external libraries (except JUnit and Hamcrest).)</p>
  
  <p>Edit: Unfortunately, I can't change the classes of the program to test.</p>