I am trying to build JUnit tests for the following code:
import java.util.InputMismatchException;
import java.util.Scanner;
public class Console {
static Scanner sc1 = new Scanner(System.in);
static Scanner sc2 = new Scanner(System.in);
public static void main (String[] args) {
readIntegerFromStdin ();
}
public static void readIntegerFromStdin () {
try {
System.out.println("Enter number here: ");
int a=sc1.nextInt();
} catch (InputMismatchException e) {
System.out.println("Enter number here: ");
sc2.nextInt();
}
}
}
The problem is, I don't know how to use the input from the Scanner
in the test. How do I get access to the Scanner's input?