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"; } }
public void logout(UserForm userForm) { System.out.println("LoginService.logout " + userForm); // Preconditions checkForm(userForm); // Same user cannot be logged twice String username = userForm.getUsername(); if (!usersLogged.contains(username)) { throw new LoginException(username + " not logged"); } usersLogged.remove(username); }
public void logout(UserForm userForm) { System.out.println("LoginController.logout " + userForm); loginService.logout(userForm); }
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"; } }
public void logout(UserForm userForm) { System.out.println("LoginService.logout " + userForm); // Preconditions checkForm(userForm); // Same user cannot be logged twice String username = userForm.getUsername(); if (!usersLogged.contains(username)) { throw new LoginException(username + " not logged"); } usersLogged.remove(username); }
public void logout(UserForm userForm) { System.out.println("LoginController.logout " + userForm); loginService.logout(userForm); }
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"; } }
public void logout(UserForm userForm) { System.out.println("LoginService.logout " + userForm); // Preconditions checkForm(userForm); // Same user cannot be logged twice String username = userForm.getUsername(); if (!usersLogged.contains(username)) { throw new LoginException(username + " not logged"); } usersLogged.remove(username); }
public void logout(UserForm userForm) { System.out.println("LoginController.logout " + userForm); loginService.logout(userForm); }
@Test void testLoginKo() { // Setting expectations (stubbing methods) when(loginService.login(userForm)).thenReturn(false); // Exercise SUT String reseponseLogin = loginController.login(userForm); // Verification assertEquals("KO", reseponseLogin); verify(loginService).login(userForm); verifyZeroInteractions(loginService); }
public boolean login(UserForm userForm) { System.out.println("LoginService.login " + userForm); // Preconditions checkForm(userForm); // Same user cannot be logged twice String username = userForm.getUsername(); if (usersLogged.contains(username)) { throw new LoginException(username + " already logged"); } // Call to repository to make logic boolean login = loginRepository.login(userForm); if (login) { usersLogged.add(username); } return login; }
@Test void testLoginOk() { // Setting expectations (stubbing methods) when(loginService.login(userForm)).thenReturn(true); // Exercise SUT String reseponseLogin = loginController.login(userForm); // Verification assertEquals("OK", reseponseLogin); verify(loginService).login(userForm); verifyNoMoreInteractions(loginService); }
public boolean login(UserForm userForm) { System.out.println("LoginService.login " + userForm); // Preconditions checkForm(userForm); // Same user cannot be logged twice String username = userForm.getUsername(); if (usersLogged.contains(username)) { throw new LoginException(username + " already logged"); } // Call to repository to make logic boolean login = loginRepository.login(userForm); if (login) { usersLogged.add(username); } return login; }
@Test void testLoginKo() { // Setting expectations (stubbing methods) when(loginService.login(userForm)).thenReturn(false); // Exercise SUT String reseponseLogin = loginController.login(userForm); // Verification assertEquals("KO", reseponseLogin); verify(loginService).login(userForm); verifyZeroInteractions(loginService); }
public boolean login(UserForm userForm) { System.out.println("LoginService.login " + userForm); // Preconditions checkForm(userForm); // Same user cannot be logged twice String username = userForm.getUsername(); if (usersLogged.contains(username)) { throw new LoginException(username + " already logged"); } // Call to repository to make logic boolean login = loginRepository.login(userForm); if (login) { usersLogged.add(username); } return login; }
@Test void testLoginOk() { // Setting expectations (stubbing methods) when(loginService.login(userForm)).thenReturn(true); // Exercise SUT String reseponseLogin = loginController.login(userForm); // Verification assertEquals("OK", reseponseLogin); verify(loginService).login(userForm); verifyNoMoreInteractions(loginService); }
@Test void testLoginException() { // Expectation when(loginService.login(any(UserForm.class))) .thenThrow(IllegalArgumentException.class); // Exercise String response = loginController.login(userForm); // Verify assertEquals("ERROR", response); }
@Test void testLoginException() { // Expectation when(loginService.login(any(UserForm.class))) .thenThrow(IllegalArgumentException.class); // Exercise String response = loginController.login(userForm); // Verify assertEquals("ERROR", response); }