Commit 0065756cacb352e713f226a09133aec3d5a0459e
1 parent
668dfe4b
test: Controller- und Service-Test angepasst
Showing
2 changed files
with
20 additions
and
3 deletions
src/test/java/net/ziemers/swxercise/lg/user/service/UserServiceTest.java
@@ -311,8 +311,10 @@ public class UserServiceTest extends JpaTestUtils { | @@ -311,8 +311,10 @@ public class UserServiceTest extends JpaTestUtils { | ||
311 | } | 311 | } |
312 | 312 | ||
313 | private UserServiceTest loginUser(final String password) { | 313 | private UserServiceTest loginUser(final String password) { |
314 | + final String SESSION_ID = "testSessionId"; | ||
315 | + | ||
314 | userDto.withPassword(password); | 316 | userDto.withPassword(password); |
315 | - actual = underTest.loginUser(userDto); | 317 | + actual = underTest.loginUser(userDto, SESSION_ID); |
316 | return this; | 318 | return this; |
317 | } | 319 | } |
318 | 320 |
src/test/java/net/ziemers/swxercise/ui/UserViewControllerTest.java
@@ -17,6 +17,9 @@ import org.mockito.Mock; | @@ -17,6 +17,9 @@ import org.mockito.Mock; | ||
17 | import org.mockito.junit.MockitoJUnitRunner; | 17 | import org.mockito.junit.MockitoJUnitRunner; |
18 | import org.slf4j.Logger; | 18 | import org.slf4j.Logger; |
19 | 19 | ||
20 | +import javax.servlet.http.HttpServletRequest; | ||
21 | +import javax.servlet.http.HttpSession; | ||
22 | + | ||
20 | import static org.junit.Assert.*; | 23 | import static org.junit.Assert.*; |
21 | import static org.mockito.Mockito.*; | 24 | import static org.mockito.Mockito.*; |
22 | 25 | ||
@@ -44,6 +47,12 @@ public class UserViewControllerTest { | @@ -44,6 +47,12 @@ public class UserViewControllerTest { | ||
44 | @Mock | 47 | @Mock |
45 | private UserService userService; | 48 | private UserService userService; |
46 | 49 | ||
50 | + @Mock | ||
51 | + private HttpServletRequest request; | ||
52 | + | ||
53 | + @Mock | ||
54 | + private HttpSession session; | ||
55 | + | ||
47 | private UserDto userDto; | 56 | private UserDto userDto; |
48 | 57 | ||
49 | private RestResponse actual; | 58 | private RestResponse actual; |
@@ -256,9 +265,15 @@ public class UserViewControllerTest { | @@ -256,9 +265,15 @@ public class UserViewControllerTest { | ||
256 | } | 265 | } |
257 | 266 | ||
258 | private void loginUser(final boolean result) { | 267 | private void loginUser(final boolean result) { |
259 | - when(userService.loginUser(userDto)).thenReturn(result); | 268 | + final String SESSION_ID = "testSessionId"; |
269 | + | ||
270 | + when(userService.loginUser(userDto, SESSION_ID)).thenReturn(result); | ||
271 | + | ||
272 | + // während der Tests besitzen wir keinen HTTP-Request, also mocken wir ihn weg | ||
273 | + when(request.getSession(false)).thenReturn(session); | ||
274 | + when(session.getId()).thenReturn(SESSION_ID); | ||
260 | 275 | ||
261 | - actual = underTest.loginUser(userDto); | 276 | + actual = underTest.loginUser(request, userDto); |
262 | } | 277 | } |
263 | 278 | ||
264 | private void logoutUser() { | 279 | private void logoutUser() { |