I want to test the mainMenu of a program which receives user input and calls a function/method depending on the input.
public void mainMenu() {
System.out.println("1. Schedule a meeting");
System.out.println("2. Book vacation dates");
System.out.println("3. Check room availability");
try {
int userInput = Integer.parseInt(inputOutput("Please enter the number that corresponds to the option that you want to proceed with."));
if (userInput >= 0 && userInput <=6) {
if (userInput == 1) {
this.scheduleMeeting();
}
if (userInput == 2){
this.scheduleVacation();
}
if (userInput == 3){
this.checkRoomAvailability();
} else {
System.out.println("Please enter a number from 0 - 6");
this.mainMenu();
}
} catch (NumberFormatException e) {
System.out.println("Please enter a number from 0 - 6");
this.mainMenu();
}
}
To test the userInput I think it would be something like:
ByteArrayInputStream in = new ByteArrayInputStream("2".getBytes());
System.setIn(in);
But how would I test the expected result when it's a function call? Should I be using Mockito and how would I implement it?