Commit 6d2000bfc38794d899db73ad43bbe69363b0ecbf
1 parent
e49ac6a1
test: Tests im UserService erweitert
Showing
1 changed file
with
33 additions
and
2 deletions
src/test/java/net/ziemers/swxercise/lg/user/service/UserServiceTest.java
@@ -39,6 +39,8 @@ public class UserServiceTest extends JpaTestUtils { | @@ -39,6 +39,8 @@ public class UserServiceTest extends JpaTestUtils { | ||
39 | 39 | ||
40 | private boolean actual; | 40 | private boolean actual; |
41 | 41 | ||
42 | + private User actualUser; | ||
43 | + | ||
42 | @Inject | 44 | @Inject |
43 | private UserDao userDao; | 45 | private UserDao userDao; |
44 | 46 | ||
@@ -79,12 +81,27 @@ public class UserServiceTest extends JpaTestUtils { | @@ -79,12 +81,27 @@ public class UserServiceTest extends JpaTestUtils { | ||
79 | 81 | ||
80 | @Test | 82 | @Test |
81 | public void testFindUserById() { | 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 | @Test | 92 | @Test |
93 | + @InRequestScope | ||
86 | public void testFindUser() { | 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 | @Test | 107 | @Test |
@@ -192,6 +209,16 @@ public class UserServiceTest extends JpaTestUtils { | @@ -192,6 +209,16 @@ public class UserServiceTest extends JpaTestUtils { | ||
192 | return this; | 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 | // then | 222 | // then |
196 | 223 | ||
197 | private UserServiceTest then() { | 224 | private UserServiceTest then() { |
@@ -202,6 +229,10 @@ public class UserServiceTest extends JpaTestUtils { | @@ -202,6 +229,10 @@ public class UserServiceTest extends JpaTestUtils { | ||
202 | assertTrue(actual); | 229 | assertTrue(actual); |
203 | } | 230 | } |
204 | 231 | ||
232 | + private void assertFindUserByIdSuccess(final Long expectedId) { | ||
233 | + assertEquals(expectedId, actualUser.getId()); | ||
234 | + } | ||
235 | + | ||
205 | private void assertCreateSuccess() { | 236 | private void assertCreateSuccess() { |
206 | // wir suchen den soeben erstellten Benutzer; wenn er existiert, ist alles gut | 237 | // wir suchen den soeben erstellten Benutzer; wenn er existiert, ist alles gut |
207 | final User user = userDao.findByUsername(USERNAME_TEST); | 238 | final User user = userDao.findByUsername(USERNAME_TEST); |