### Question:
LoginController { public String login(UserForm userForm) { System.out.println("LoginController.login " + userForm); try { if (userForm == null) { return "ERROR"; } else if (loginService.login(userForm)) { return "OK"; } else { return "KO"; } } catch (Exception e) { return "ERROR"; } }  String login(UserForm userForm); void logout(UserForm userForm); public LoginService loginService; }### Answer:
@Test public void testLogin() { loginController.login(userForm); verify(loginService).login(userForm); verifyNoMoreInteractions(loginService); }
@Test public void testLoginOk() { when(loginService.login(userForm)).thenReturn(true); assertEquals("OK", loginController.login(userForm)); verify(loginService).login(userForm); verifyNoMoreInteractions(loginService); }
@Test public void testLoginKo() { when(loginService.login(userForm)).thenReturn(false); assertEquals("KO", loginController.login(userForm)); }
@Test public void testLoginError() { assertEquals("ERROR", loginController.login(null)); }
@Test public void testLoginWithException() { when(loginService.login(userForm)) .thenThrow(IllegalArgumentException.class); assertEquals("ERROR", loginController.login(userForm)); }