I'm trying to test a function that loops forever until QUIT is entered but I can't figure out how to simulate multiple lines of user input from system.
This is what I currently have
String validStartFlow = "START-FLOW\r\nQUIT\r\n";
ByteArrayInputStream in = new ByteArrayInputStream(validStartFlow.getBytes());
System.setIn(in);
CommandLineListener cmdLineListener = new CommandLineListener(eventBus,logger);
cmdLineListener.startCommandLineListener(in);
The method that loops forever is
while (!userCmd.equals("QUIT")) {
userCmd = "";
Scanner scanner = new Scanner(in);
// BufferedReader reader = new BufferedReader(in);
while (userCmd == null || userCmd.equals("")) {
userCmd = scanner.nextLine();
}
...
}
The START-FLOW is read in perfectly but then after that when it reaches scanner.nextLine() it crashes with the following error
No line found java.util.NoSuchElementException: No line found
How can I get it to read in QUIT from the validStartFlow string?
scanner.useDelimiter("\r\n")?