You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB

3 years ago
3 years ago
  1. package de.fd.fh.server.game;
  2. import de.fd.fh.server.user.UserId;
  3. import dev.morphia.Key;
  4. import org.junit.jupiter.api.Test;
  5. import org.mockito.ArgumentCaptor;
  6. import static org.junit.jupiter.api.Assertions.*;
  7. import static org.mockito.ArgumentMatchers.any;
  8. import static org.mockito.Mockito.mock;
  9. import static org.mockito.Mockito.when;
  10. class GameServiceTest
  11. {
  12. @Test
  13. void testCreateGame()
  14. {
  15. final GameRepository repository = when(mock(GameRepository.class).save(any()))
  16. .thenReturn(new Key<>(Game.class, "testCollection", GameId.of("98765")))
  17. .getMock();
  18. final Game game = new Game();
  19. final GameId result = new GameService(repository).createGame(game);
  20. assertNotNull(result);
  21. assertEquals("98765", result.getIdentifier());
  22. }
  23. @Test
  24. void given_twoUserIds_when_initGame_should_initGame()
  25. {
  26. final UserId blackPlayer = UserId.of("12345");
  27. final UserId whitePlayer = UserId.of("98765");
  28. final GameRepository repository = when(mock(GameRepository.class).save(any()))
  29. .thenReturn(new Key<>(Game.class, "testCollection", GameId.of("4242")))
  30. .getMock();
  31. final ArgumentCaptor<Game> captor = ArgumentCaptor.forClass(Game.class);
  32. final GameId result = new GameService(repository).createGame(blackPlayer, whitePlayer);
  33. }
  34. }