In our application, we expect user input within a Thread as follows :
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
My solution currently (in 2018) is:
final byte[] passCode = "12343434".getBytes();
final ByteArrayInputStream inStream = new ByteArrayInputStream(passCode);
System.setIn(inStream);
[Update in 2019] For JUnit4 Tests there is a framework for these tasks: https://stefanbirkner.github.io/system-rules/ (the upgrade to JUnit5 is on going: https://github.com/stefanbirkner/system-rules/issues/55)