|
|
@ -1,5 +1,6 @@ |
|
|
|
package de.fd.fh.server.game.web; |
|
|
|
|
|
|
|
import de.fd.fh.server.game.Game; |
|
|
|
import de.fd.fh.server.game.GameId; |
|
|
|
import de.fd.fh.server.game.GameService; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
@ -38,8 +39,8 @@ public class GameControllerTest |
|
|
|
when(request.body()).thenReturn("{\"whiteUserId\":\"12345\",\"blackUserId\":\"98765\"}"); |
|
|
|
when(service.createGame(any(), any())).thenReturn(GameId.of("56789")); |
|
|
|
|
|
|
|
ArgumentCaptor<String> bodyCaptor = ArgumentCaptor.forClass(String.class); |
|
|
|
ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
|
final ArgumentCaptor<String> bodyCaptor = ArgumentCaptor.forClass(String.class); |
|
|
|
final ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
|
|
|
|
|
new GameController(service).createGame(request, response); |
|
|
|
|
|
|
@ -59,7 +60,7 @@ public class GameControllerTest |
|
|
|
when(request.body()).thenReturn("{\"whiteUserId\":\"12345\",\"blackUserId\":\"98765\"}"); |
|
|
|
when(service.createGame(any(), any())).thenReturn(null); |
|
|
|
|
|
|
|
ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
|
final ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
|
|
|
|
|
new GameController(service).createGame(request, response); |
|
|
|
|
|
|
@ -68,4 +69,40 @@ public class GameControllerTest |
|
|
|
assertNotNull(statusCaptor.getValue()); |
|
|
|
assertEquals(400, statusCaptor.getValue()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testFindGameById() throws IOException |
|
|
|
{ |
|
|
|
when(request.params(any())).thenReturn("12345"); |
|
|
|
when(service.findGameById(any())).thenReturn(new Game()); |
|
|
|
|
|
|
|
final ArgumentCaptor<String> bodyCaptor = ArgumentCaptor.forClass(String.class); |
|
|
|
final ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
|
|
|
|
|
new GameController(service).finGameById(request, response); |
|
|
|
|
|
|
|
verify(response).body(bodyCaptor.capture()); |
|
|
|
verify(response).status(statusCaptor.capture()); |
|
|
|
|
|
|
|
assertNotNull(bodyCaptor.getValue()); |
|
|
|
|
|
|
|
assertNotNull(statusCaptor.getValue()); |
|
|
|
assertEquals(200, statusCaptor.getValue()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testFailedFindGameById() throws IOException |
|
|
|
{ |
|
|
|
when(request.params(any())).thenReturn("12345"); |
|
|
|
when(service.findGameById(any())).thenReturn(null); |
|
|
|
|
|
|
|
final ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
|
|
|
|
|
new GameController(service).finGameById(request, response); |
|
|
|
|
|
|
|
verify(response).status(statusCaptor.capture()); |
|
|
|
|
|
|
|
assertNotNull(statusCaptor.getValue()); |
|
|
|
assertEquals(400, statusCaptor.getValue()); |
|
|
|
} |
|
|
|
} |