Commit 6d2000bfc38794d899db73ad43bbe69363b0ecbf

Authored by Thomas Ziemer
1 parent e49ac6a1

test: Tests im UserService erweitert

src/test/java/net/ziemers/swxercise/lg/user/service/UserServiceTest.java
... ... @@ -39,6 +39,8 @@ public class UserServiceTest extends JpaTestUtils {
39 39  
40 40 private boolean actual;
41 41  
  42 + private User actualUser;
  43 +
42 44 @Inject
43 45 private UserDao userDao;
44 46  
... ... @@ -79,12 +81,27 @@ public class UserServiceTest extends JpaTestUtils {
79 81  
80 82 @Test
81 83 public void testFindUserById() {
82   - // TODO Test ist noch zu implementieren
  84 +
  85 + when()
  86 + .findUser(EXISTING_USER_ID);
  87 +
  88 + then()
  89 + .assertFindUserByIdSuccess(EXISTING_USER_ID);
83 90 }
84 91  
85 92 @Test
  93 + @InRequestScope
86 94 public void testFindUser() {
87   - // TODO Test ist noch zu implementieren
  95 +
  96 + given()
  97 + .userDto(EXISTING_USERNAME_TEST)
  98 + .loginUser(EXISTING_PASSWORD_TEST);
  99 +
  100 + when()
  101 + .findUser();
  102 +
  103 + then()
  104 + .assertFindUserByIdSuccess(EXISTING_USER_ID);
88 105 }
89 106  
90 107 @Test
... ... @@ -192,6 +209,16 @@ public class UserServiceTest extends JpaTestUtils {
192 209 return this;
193 210 }
194 211  
  212 + private UserServiceTest findUser(final Long id) {
  213 + actualUser = underTest.findUser(id);
  214 + return this;
  215 + }
  216 +
  217 + private UserServiceTest findUser() {
  218 + actualUser = underTest.findUser();
  219 + return this;
  220 + }
  221 +
195 222 // then
196 223  
197 224 private UserServiceTest then() {
... ... @@ -202,6 +229,10 @@ public class UserServiceTest extends JpaTestUtils {
202 229 assertTrue(actual);
203 230 }
204 231  
  232 + private void assertFindUserByIdSuccess(final Long expectedId) {
  233 + assertEquals(expectedId, actualUser.getId());
  234 + }
  235 +
205 236 private void assertCreateSuccess() {
206 237 // wir suchen den soeben erstellten Benutzer; wenn er existiert, ist alles gut
207 238 final User user = userDao.findByUsername(USERNAME_TEST);
... ...