Browse Source

setup GameControllerTest

feat-serverGameRepresentation
Steffen Nitschke 4 years ago
parent
commit
4bfeaa8b86
  1. 10
      fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameService.java
  2. 43
      fh.fd.ci.server/src/test/java/de/fd/fh/server/game/web/GameControllerTest.java

10
fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameService.java

@ -31,6 +31,11 @@ public class GameService
return repository.findByGameId(gameId); return repository.findByGameId(gameId);
} }
public List<Game> findRunningGamesOfUser(final UserId userId)
{
return repository.findRunningGamesOfPlayer(userId);
}
private Set<Field> initFields(UserId blackUser, UserId whiteUser) private Set<Field> initFields(UserId blackUser, UserId whiteUser)
{ {
final Set<Field> fields = new HashSet<>(); final Set<Field> fields = new HashSet<>();
@ -102,9 +107,4 @@ public class GameService
} }
return null; return null;
} }
public List<Game> findRunningGamesOfUser(final UserId userId)
{
return repository.findRunningGamesOfPlayer(userId);
}
} }

43
fh.fd.ci.server/src/test/java/de/fd/fh/server/game/web/GameControllerTest.java

@ -0,0 +1,43 @@
package de.fd.fh.server.game.web;
import de.fd.fh.server.access.AccessToken;
import de.fd.fh.server.game.GameId;
import de.fd.fh.server.game.GameService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import spark.Request;
import spark.Response;
import spark.Session;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
public class GameControllerTest
{
@Mock
Request request;
@Mock
Response response;
@Mock
Session session;
@Mock
GameService service;
@BeforeEach
void before()
{
MockitoAnnotations.openMocks(this);
}
@Test
void testCreateGameTest()
{
when(request.body()).thenReturn("{\"userName\":\"TestName\",\"password\":\"TestPassword\"}");
when(request.session()).thenReturn(session);
when(service.createGame(any())).thenReturn(GameId.random());
new GameController(service).createGame(request, response);
}
}
Loading…
Cancel
Save