Commit 7c0c2ad7ffe457c37da7b4b7fb898d017aea1299
1 parent
6d2000bf
test: Tests für Login und Logout verbessert
Showing
1 changed file
with
27 additions
and
1 deletions
src/test/java/net/ziemers/swxercise/lg/user/service/UserServiceTest.java
... | ... | @@ -45,6 +45,9 @@ public class UserServiceTest extends JpaTestUtils { |
45 | 45 | private UserDao userDao; |
46 | 46 | |
47 | 47 | @Inject |
48 | + private SessionContext sessionContext; | |
49 | + | |
50 | + @Inject | |
48 | 51 | private UserService underTest; |
49 | 52 | |
50 | 53 | @Before |
... | ... | @@ -75,8 +78,18 @@ public class UserServiceTest extends JpaTestUtils { |
75 | 78 | } |
76 | 79 | |
77 | 80 | @Test |
81 | + @InRequestScope | |
78 | 82 | public void testLogoutUserSuccess() { |
79 | - // TODO Test ist noch zu implementieren | |
83 | + | |
84 | + given() | |
85 | + .userDto(EXISTING_USERNAME_TEST) | |
86 | + .loginUser(EXISTING_PASSWORD_TEST); | |
87 | + | |
88 | + when() | |
89 | + .logoutUser(); | |
90 | + | |
91 | + then() | |
92 | + .assertLogoutSuccess(); | |
80 | 93 | } |
81 | 94 | |
82 | 95 | @Test |
... | ... | @@ -193,6 +206,11 @@ public class UserServiceTest extends JpaTestUtils { |
193 | 206 | return this; |
194 | 207 | } |
195 | 208 | |
209 | + private UserServiceTest logoutUser() { | |
210 | + actual = underTest.logoutUser(); | |
211 | + return this; | |
212 | + } | |
213 | + | |
196 | 214 | private UserServiceTest createUser() { |
197 | 215 | txBegin(); |
198 | 216 | actual = underTest.createUser(userDto); |
... | ... | @@ -226,7 +244,15 @@ public class UserServiceTest extends JpaTestUtils { |
226 | 244 | } |
227 | 245 | |
228 | 246 | private void assertLoginSuccess() { |
247 | + // die Login-Methode lieferte Erfolg zurück, und es gibt einen angemeldeten Benutzer | |
248 | + assertTrue(actual); | |
249 | + assertNotNull(sessionContext.getUser()); | |
250 | + } | |
251 | + | |
252 | + private void assertLogoutSuccess() { | |
253 | + // die Logout-Methode lieferte Erfolg zurück, und es gibt keinen angemeldeten Benutzer | |
229 | 254 | assertTrue(actual); |
255 | + assertNull(sessionContext.getUser()); | |
230 | 256 | } |
231 | 257 | |
232 | 258 | private void assertFindUserByIdSuccess(final Long expectedId) { | ... | ... |