Hello, I am having trouble using the Java scanner inputstream as a rigged input for my java game that I am trying to test using cucumber. My issue can be summarized as:
Below are two testing functions I am using to test my game. My issue is that, my input will work for the first run of playMelee which is repeatedly called by playGame taking 3 inputs at a time, showing that I want it to take 3 rounds of inputs of 3 '1's here.
My issue is that it will work for the first round of inputs but no subsequent ones showing a no line found error for my Scanner instance which is created inside my playMelee function.
I have tried creating a general scanner in the class and creating a scanner which is input as a parameter to no avail.
Essentially: I am giving the input 9 different inputs of '1' and it is only receiving the first 3 as the function playMelee takes 3 at a time as it is called 3 times by playGame showing it does not work for subsequent inputs. Any help is appreciated
private void provideTestInput(String input) {
InputStream inputStream = new ByteArrayInputStream(input.getBytes());
System.setIn(inputStream);
System.setOut(printStream);
}
private void runMelee() {
String input2 = "1\n1\n1\n1\n1\n11\n1\n1\n";
provideTestInput(input2);
game.playGame(); // this function repeatedly calls playMelee which takes 3 inputs at a time
}
// in Game class
void playGame() {
for(int=0;i<3;i++){
playMelee()
}
}
void playMelee() {
input = new Scanner(System.in);
for(int=0;i<3;i++){
String valueInput = input.nextLine();
}
// determine winner of game etc.
}```