Commit 0065756cacb352e713f226a09133aec3d5a0459e

Authored by Thomas Ziemer
1 parent 668dfe4b

test: Controller- und Service-Test angepasst

src/test/java/net/ziemers/swxercise/lg/user/service/UserServiceTest.java
... ... @@ -311,8 +311,10 @@ public class UserServiceTest extends JpaTestUtils {
311 311 }
312 312  
313 313 private UserServiceTest loginUser(final String password) {
  314 + final String SESSION_ID = "testSessionId";
  315 +
314 316 userDto.withPassword(password);
315   - actual = underTest.loginUser(userDto);
  317 + actual = underTest.loginUser(userDto, SESSION_ID);
316 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 17 import org.mockito.junit.MockitoJUnitRunner;
18 18 import org.slf4j.Logger;
19 19  
  20 +import javax.servlet.http.HttpServletRequest;
  21 +import javax.servlet.http.HttpSession;
  22 +
20 23 import static org.junit.Assert.*;
21 24 import static org.mockito.Mockito.*;
22 25  
... ... @@ -44,6 +47,12 @@ public class UserViewControllerTest {
44 47 @Mock
45 48 private UserService userService;
46 49  
  50 + @Mock
  51 + private HttpServletRequest request;
  52 +
  53 + @Mock
  54 + private HttpSession session;
  55 +
47 56 private UserDto userDto;
48 57  
49 58 private RestResponse actual;
... ... @@ -256,9 +265,15 @@ public class UserViewControllerTest {
256 265 }
257 266  
258 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 279 private void logoutUser() {
... ...