// Instead of using System.in just use a different InputStream! new ByteArrayInputStream(("your user inpts" + System.lineSeparator() + "enter is simulated by using System.lineSeparator()").getBytes(StandardCharsets.UTF_8)));