### Question:
LoginService { public boolean login(UserForm userForm) { System.out.println("LoginService.login " + userForm); checkForm(userForm); String username = userForm.getUsername(); if (usersLogged.contains(username)) { throw new LoginException(username + " already logged"); } boolean login = loginRepository.login(userForm); if (login) { usersLogged.add(username); } return login; }  boolean login(UserForm userForm); void logout(UserForm userForm); int getUserLoggedCount();  }### Answer:
@Test void testLoginKo() { when(loginRepository.login(any(UserForm.class))).thenReturn(false); assertFalse(loginService.login(userForm)); verify(loginRepository, times(1)).login(userForm); }
@Test void testLoginTwice() { when(loginRepository.login(userForm)).thenReturn(true); assertThrows(LoginException.class, () -> { loginService.login(userForm); loginService.login(userForm); }); }
@Test public void testServiceLoginOk() { when(loginRepository.login(any(UserForm.class))).thenReturn(true); assertTrue(loginService.login(userForm)); verify(loginRepository, atLeast(1)).login(userForm); verifyNoMoreInteractions(loginRepository); }
@Test public void testServiceLoginBad() { when(loginRepository.login(any(UserForm.class))).thenReturn(false); assertFalse(loginService.login(userForm)); verify(loginRepository, times(1)).login(userForm); verifyNoMoreInteractions(loginRepository); }
@Test(expected = LoginException.class) public void testServiceLoginTwice() { when(loginRepository.login(userForm)).thenReturn(true); loginService.login(userForm); loginService.login(userForm); }
@Test void testLoginOk() { when(loginRepository.login(any(UserForm.class))).thenReturn(true); assertTrue(loginService.login(userForm)); verify(loginRepository, atLeast(1)).login(userForm); }