I have a createUser() method which i am trying to write a test for. It starts like this
Scanner input = new Scanner(System.in);
System.out.println("—Welcome to the Task Management System—");
if (currentUser == null) {
System.out.println("If you are an existing user press 1 to login, if you are a new user press 2 to register. By typing -1 when entered into any menu you can go back to main menu");
String choice = input.nextLine();
if (choice.equals("2")) {```
and i am trying to pass some inputs as if they are user inputs with mockito like this
```public void testUserRegistration() throws SQLException {
// Create a mock DatabaseService
DatabaseService dbService = mock(DatabaseService.class);
// Create a new Service with the mocked DatabaseService
Service service = new Service(dbService,true);
// Create a mock Scanner with predefined user inputs
Scanner scanner = mock(Scanner.class);
Person registeredUser = service.createUser(scanner);
when(scanner.next()).thenReturn("2");
when(scanner.nextLine()).thenReturn("testUser");
when(scanner.nextLine()).thenReturn("testPassword");
// Test the registration process
// Verify that the createUser() method returns the expected output
assertEquals("testUser", registeredUser.getName());
}```
But still i think there is a problem cause test is not failing or anything. Can anyone help?