Browse Source

new GameRepository with findByGameId-Method and Test

feat-serverGameRepresentation
Steffen Nitschke 4 years ago
parent
commit
1f92e90262
  1. 6
      fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameRepository.java
  2. 23
      fh.fd.ci.server/src/test/java/de/fd/fh/server/game/GameRepositoryTest.java

6
fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameRepository.java

@ -29,4 +29,10 @@ public class GameRepository
{
return datastore.save(access);
}
Game findByGameId(final GameId gameId)
{
return datastore.createQuery(Game.class)
.field("id.identifier").equal(gameId.getIdentifier()).first();
}
}

23
fh.fd.ci.server/src/test/java/de/fd/fh/server/game/GameRepositoryTest.java

@ -71,4 +71,27 @@ class GameRepositoryTest
assertNotNull(result.getId());
assertEquals(2, result.getFields().size());
}
@Test
void findByGameIdTest()
{
final Set<Field> fields = new HashSet<>();
fields.add(new Field(0, 0, Field.Color.BLACK, new Figure(Figure.Type.BISHOP, UserId.of("12345"))));
fields.add(new Field(0, 2, Field.Color.WHITE, new Figure(Figure.Type.BISHOP, UserId.of("98765"))));
final Game game = new Game(GameId.of("4242"), UserId.of("12345"), UserId.of("98765"), UserId.of("12345"), fields, UserId.of("12345"));
ds.save(game);
final Game result = repository.findByGameId(GameId.of("4242"));
assertNotNull(result);
assertEquals("12345", result.getWhitePlayer().getIdentifier());
assertEquals("12345", result.getCurrentPlayer().getIdentifier());
assertEquals("98765", result.getBlackPlayer().getIdentifier());
assertEquals("12345", result.getWinner().getIdentifier());
assertNotNull(result.getId());
assertEquals(2, result.getFields().size());
}
}
Loading…
Cancel
Save