Browse Source

add color to fields

feat-serverGameRepresentation
Steffen Nitschke 4 years ago
parent
commit
e4d2131c7a
  1. 7
      fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameService.java
  2. 11
      fh.fd.ci.server/src/test/java/de/fd/fh/server/game/GameServiceTest.java

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

@ -32,9 +32,14 @@ public class GameService
{ {
for (int y = 0; y < 8; y++) for (int y = 0; y < 8; y++)
{ {
fields.add(new Field(x, y, null , null));
fields.add(new Field(x, y, getColor(x, y) , null));
} }
} }
return fields; return fields;
} }
private Field.Color getColor(final int x, final int y)
{
return (x + y) % 2 != 1 ? Field.Color.WHITE : Field.Color.BLACK;
}
} }

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

@ -5,6 +5,8 @@ import dev.morphia.Key;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import java.util.Set;
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;
import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.then;
@ -54,6 +56,15 @@ class GameServiceTest
assertEquals("98765", savedGame.getCurrentPlayer().getIdentifier()); assertEquals("98765", savedGame.getCurrentPlayer().getIdentifier());
assertEquals(64, savedGame.getFields().size()); assertEquals(64, savedGame.getFields().size());
final Set<Field> fields = savedGame.getFields();
fields.forEach(field -> {
final Field.Color expected = (field.getX() + field.getY()) % 2 != 1 ? Field.Color.WHITE : Field.Color.BLACK;
assertEquals(expected, field.getColor());
});
then(repository).should().save(any(Game.class)); then(repository).should().save(any(Game.class));
then(repository).shouldHaveNoMoreInteractions(); then(repository).shouldHaveNoMoreInteractions();
} }
Loading…
Cancel
Save