@Test
// test getNumber with a valid input.
public void getNumberValidInput() {
// When the getNumber calls Scanner.nextLine() return "496" via
// the mocked Scanner.
// declare a mock Scanner object.
Scanner mockScanner = mock(Scanner.class);
when (mockScanner.nextLine()).thenReturn("496");
int val = PrimeOrPerfect.getNumber(mockScanner);
assertEquals(496, val);
}
When I run my code as a maven install I get an error on the line Scanner mockScanner = mock(Scanner.class);. I don’t understand why and I can’t contact my professor.
I expect the test to run but I keep getting an illegalstate error.
New contributor
SigEp479 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.