Commit d0c0b80ba0b7663aa2e320418d02698cbc40cc6d
1 parent
48a7a2c0
test: Logout
Showing
2 changed files
with
19 additions
and
9 deletions
src/main/java/net/ziemers/swxercise/lg/user/service/UserService.java
... | ... | @@ -24,17 +24,11 @@ public class UserService { |
24 | 24 | |
25 | 25 | public boolean loginUser(UserDto dto) { |
26 | 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 | 30 | public boolean logoutUser() { |
36 | - sessionContext.setUser(null); | |
37 | - return sessionContext.getUser() == null; | |
31 | + return sessionContext.logout(); | |
38 | 32 | } |
39 | 33 | |
40 | 34 | public User findUser(final Long id) { | ... | ... |
src/test/java/net/ziemers/swxercise/ui/UserViewControllerTest.java
... | ... | @@ -93,7 +93,12 @@ public class UserViewControllerTest { |
93 | 93 | |
94 | 94 | @Test |
95 | 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 | 104 | // given |
... | ... | @@ -128,6 +133,12 @@ public class UserViewControllerTest { |
128 | 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 | 142 | // then |
132 | 143 | |
133 | 144 | private UserViewControllerTest then() { |
... | ... | @@ -139,4 +150,9 @@ public class UserViewControllerTest { |
139 | 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 | } | ... | ... |