|
@ -1,5 +1,6 @@ |
|
|
package de.fd.fh.server.game.web; |
|
|
package de.fd.fh.server.game.web; |
|
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
import de.fd.fh.server.game.Game; |
|
|
import de.fd.fh.server.game.Game; |
|
|
import de.fd.fh.server.game.GameId; |
|
|
import de.fd.fh.server.game.GameId; |
|
|
import de.fd.fh.server.game.GameService; |
|
|
import de.fd.fh.server.game.GameService; |
|
@ -12,6 +13,7 @@ import spark.Request; |
|
|
import spark.Response; |
|
|
import spark.Response; |
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
import static org.mockito.ArgumentMatchers.any; |
|
@ -79,7 +81,7 @@ public class GameControllerTest |
|
|
final ArgumentCaptor<String> bodyCaptor = ArgumentCaptor.forClass(String.class); |
|
|
final ArgumentCaptor<String> bodyCaptor = ArgumentCaptor.forClass(String.class); |
|
|
final ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
final ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
|
|
|
|
|
|
new GameController(service).finGameById(request, response); |
|
|
|
|
|
|
|
|
new GameController(service).findGameById(request, response); |
|
|
|
|
|
|
|
|
verify(response).body(bodyCaptor.capture()); |
|
|
verify(response).body(bodyCaptor.capture()); |
|
|
verify(response).status(statusCaptor.capture()); |
|
|
verify(response).status(statusCaptor.capture()); |
|
@ -98,11 +100,47 @@ public class GameControllerTest |
|
|
|
|
|
|
|
|
final ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
final ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
|
|
|
|
|
|
new GameController(service).finGameById(request, response); |
|
|
|
|
|
|
|
|
new GameController(service).findGameById(request, response); |
|
|
|
|
|
|
|
|
verify(response).status(statusCaptor.capture()); |
|
|
verify(response).status(statusCaptor.capture()); |
|
|
|
|
|
|
|
|
assertNotNull(statusCaptor.getValue()); |
|
|
assertNotNull(statusCaptor.getValue()); |
|
|
assertEquals(400, statusCaptor.getValue()); |
|
|
|
|
|
|
|
|
assertEquals(404, statusCaptor.getValue()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void testFindRunningGamesOfUser() throws JsonProcessingException |
|
|
|
|
|
{ |
|
|
|
|
|
when(request.params(any())).thenReturn("12345"); |
|
|
|
|
|
when(service.findRunningGamesOfUser(any())).thenReturn(List.of(new Game(), new Game())); |
|
|
|
|
|
|
|
|
|
|
|
final ArgumentCaptor<String> bodyCaptor = ArgumentCaptor.forClass(String.class); |
|
|
|
|
|
final ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
|
|
|
|
|
|
|
|
|
new GameController(service).findRunningGamesOfUser(request, response); |
|
|
|
|
|
|
|
|
|
|
|
verify(response).body(bodyCaptor.capture()); |
|
|
|
|
|
verify(response).status(statusCaptor.capture()); |
|
|
|
|
|
|
|
|
|
|
|
assertNotNull(bodyCaptor.getValue()); |
|
|
|
|
|
|
|
|
|
|
|
assertNotNull(statusCaptor.getValue()); |
|
|
|
|
|
assertEquals(200, statusCaptor.getValue()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void testFailedFindRunningGamesOfUser() throws JsonProcessingException |
|
|
|
|
|
{ |
|
|
|
|
|
when(request.params(any())).thenReturn("12345"); |
|
|
|
|
|
when(service.findRunningGamesOfUser(any())).thenReturn(null); |
|
|
|
|
|
|
|
|
|
|
|
final ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
|
|
|
|
|
|
|
|
|
new GameController(service).findRunningGamesOfUser(request, response); |
|
|
|
|
|
|
|
|
|
|
|
verify(response).status(statusCaptor.capture()); |
|
|
|
|
|
|
|
|
|
|
|
assertNotNull(statusCaptor.getValue()); |
|
|
|
|
|
assertEquals(404, statusCaptor.getValue()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |