Commit d0c0b80ba0b7663aa2e320418d02698cbc40cc6d

Authored by Thomas Ziemer
1 parent 48a7a2c0

test: Logout

src/main/java/net/ziemers/swxercise/lg/user/service/UserService.java
@@ -24,17 +24,11 @@ public class UserService { @@ -24,17 +24,11 @@ public class UserService {
24 24
25 public boolean loginUser(UserDto dto) { 25 public boolean loginUser(UserDto dto) {
26 final User user = dao.findByUsername(dto.getUsername()); 26 final User user = dao.findByUsername(dto.getUsername());
27 -  
28 - if (user != null && user.getProfile().isValidPassword(dto.getPassword())) {  
29 - sessionContext.setUser(user);  
30 - return true;  
31 - }  
32 - return false; 27 + return user != null && user.getProfile().isValidPassword(dto.getPassword()) && sessionContext.login(user);
33 } 28 }
34 29
35 public boolean logoutUser() { 30 public boolean logoutUser() {
36 - sessionContext.setUser(null);  
37 - return sessionContext.getUser() == null; 31 + return sessionContext.logout();
38 } 32 }
39 33
40 public User findUser(final Long id) { 34 public User findUser(final Long id) {
src/test/java/net/ziemers/swxercise/ui/UserViewControllerTest.java
@@ -93,7 +93,12 @@ public class UserViewControllerTest { @@ -93,7 +93,12 @@ public class UserViewControllerTest {
93 93
94 @Test 94 @Test
95 public void testLogoutUserReturnsSuccess() { 95 public void testLogoutUserReturnsSuccess() {
96 - // TODO Test ist noch zu implementieren 96 +
  97 + doing()
  98 + .logoutUser();
  99 +
  100 + then()
  101 + .assertLogoutSuccess();
97 } 102 }
98 103
99 // given 104 // given
@@ -128,6 +133,12 @@ public class UserViewControllerTest { @@ -128,6 +133,12 @@ public class UserViewControllerTest {
128 actual = underTest.loginUser(userDto); 133 actual = underTest.loginUser(userDto);
129 } 134 }
130 135
  136 + private void logoutUser() {
  137 + when(userService.logoutUser()).thenReturn(true);
  138 +
  139 + actual = underTest.logoutUser();
  140 + }
  141 +
131 // then 142 // then
132 143
133 private UserViewControllerTest then() { 144 private UserViewControllerTest then() {
@@ -139,4 +150,9 @@ public class UserViewControllerTest { @@ -139,4 +150,9 @@ public class UserViewControllerTest {
139 assertEquals(expected, actual); 150 assertEquals(expected, actual);
140 } 151 }
141 152
  153 + private void assertLogoutSuccess() {
  154 + final RestResponse expected = new RestResponse();
  155 + assertEquals(expected, actual);
  156 + }
  157 +
142 } 158 }