Browse Source

refactor createGame-Method to return GameId instead of Game

feat-serverGameRepresentation
Steffen Nitschke 4 years ago
parent
commit
21ddd27c13
  1. 8
      fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameService.java
  2. 10
      fh.fd.ci.server/src/test/java/de/fd/fh/server/game/GameServiceTest.java

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

@ -1,10 +1,14 @@
package de.fd.fh.server.game; package de.fd.fh.server.game;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public class GameService public class GameService
{ {
private final GameRepository repository;
public Game createGame()
public GameId createGame(final Game game)
{ {
return null;
return (GameId) repository.save(game).getId();
} }
} }

10
fh.fd.ci.server/src/test/java/de/fd/fh/server/game/GameServiceTest.java

@ -1,17 +1,25 @@
package de.fd.fh.server.game; package de.fd.fh.server.game;
import dev.morphia.Key;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class GameServiceTest class GameServiceTest
{ {
@Test @Test
void testCreateGame() void testCreateGame()
{ {
final GameRepository repository = when(mock(GameRepository.class).save(any()))
.thenReturn(new Key<>(Game.class, "testCollection", GameId.random()))
.getMock();
final Game game = new Game(); final Game game = new Game();
final Game result = new GameService().createGame();
final GameId result = new GameService(repository).createGame(game);
assertNotNull(result); assertNotNull(result);
} }
Loading…
Cancel
Save