Commit 7c0c2ad7ffe457c37da7b4b7fb898d017aea1299

Authored by Thomas Ziemer
1 parent 6d2000bf

test: Tests für Login und Logout verbessert

src/test/java/net/ziemers/swxercise/lg/user/service/UserServiceTest.java
@@ -45,6 +45,9 @@ public class UserServiceTest extends JpaTestUtils { @@ -45,6 +45,9 @@ public class UserServiceTest extends JpaTestUtils {
45 private UserDao userDao; 45 private UserDao userDao;
46 46
47 @Inject 47 @Inject
  48 + private SessionContext sessionContext;
  49 +
  50 + @Inject
48 private UserService underTest; 51 private UserService underTest;
49 52
50 @Before 53 @Before
@@ -75,8 +78,18 @@ public class UserServiceTest extends JpaTestUtils { @@ -75,8 +78,18 @@ public class UserServiceTest extends JpaTestUtils {
75 } 78 }
76 79
77 @Test 80 @Test
  81 + @InRequestScope
78 public void testLogoutUserSuccess() { 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 @Test 95 @Test
@@ -193,6 +206,11 @@ public class UserServiceTest extends JpaTestUtils { @@ -193,6 +206,11 @@ public class UserServiceTest extends JpaTestUtils {
193 return this; 206 return this;
194 } 207 }
195 208
  209 + private UserServiceTest logoutUser() {
  210 + actual = underTest.logoutUser();
  211 + return this;
  212 + }
  213 +
196 private UserServiceTest createUser() { 214 private UserServiceTest createUser() {
197 txBegin(); 215 txBegin();
198 actual = underTest.createUser(userDto); 216 actual = underTest.createUser(userDto);
@@ -226,7 +244,15 @@ public class UserServiceTest extends JpaTestUtils { @@ -226,7 +244,15 @@ public class UserServiceTest extends JpaTestUtils {
226 } 244 }
227 245
228 private void assertLoginSuccess() { 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 assertTrue(actual); 254 assertTrue(actual);
  255 + assertNull(sessionContext.getUser());
230 } 256 }
231 257
232 private void assertFindUserByIdSuccess(final Long expectedId) { 258 private void assertFindUserByIdSuccess(final Long expectedId) {