tests for gameStateList() and gameStateGet()

This commit is contained in:
djmil 2023-10-03 10:01:58 +02:00
parent 7fe2898eef
commit 5589c8ebe6
2 changed files with 39 additions and 6 deletions

View File

@ -41,7 +41,7 @@ public class GameProposalTests {
assertThat(issuerGameView.opponentName()).isEqualToIgnoringCase(acquier); assertThat(issuerGameView.opponentName()).isEqualToIgnoringCase(acquier);
assertThat(issuerGameView.opponentColor()).isEqualByComparingTo(acquierColor); assertThat(issuerGameView.opponentColor()).isEqualByComparingTo(acquierColor);
assertThat(issuerGameView.board()).containsAllEntriesOf(GameState.defaultGameBoard); assertThat(issuerGameView.board()).containsAllEntriesOf(GameState.defaultGameBoard);
assertThat(issuerGameView.previousMove()).isEmpty(); assertThat(issuerGameView.previousMove()).isNull();
assertThat(issuerGameView.moveNumber() == 0); assertThat(issuerGameView.moveNumber() == 0);
assertThat(issuerGameView.message()).isEqualToIgnoringCase(message); assertThat(issuerGameView.message()).isEqualToIgnoringCase(message);
assertThat(issuerGameView.uuid()).isNotNull(); assertThat(issuerGameView.uuid()).isNotNull();
@ -52,7 +52,7 @@ public class GameProposalTests {
GameState acquierGameView = assertDoesNotThrow( () -> { GameState acquierGameView = assertDoesNotThrow( () -> {
return cordaClient.gameStateList(hiAcquier) return cordaClient.gameStateList(hiAcquier)
.stream() .stream()
.filter(gameView -> gameView.uuid().equals(issuerGameView.uuid())) .filter(gameView -> gameView.uuid().compareTo(issuerGameView.uuid()) == 0)
.reduce((a, b) -> {throw new IllegalStateException("Duplicate");}) .reduce((a, b) -> {throw new IllegalStateException("Duplicate");})
.get(); .get();
}); });

View File

@ -1,5 +1,8 @@
package djmil.cordacheckers.cordaclient; package djmil.cordacheckers.cordaclient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -8,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import djmil.cordacheckers.cordaclient.dao.GameState; import djmil.cordacheckers.cordaclient.dao.GameState;
import djmil.cordacheckers.cordaclient.dao.Stone.Color;
import djmil.cordacheckers.user.HoldingIdentityResolver; import djmil.cordacheckers.user.HoldingIdentityResolver;
@SpringBootTest @SpringBootTest
@ -24,21 +28,50 @@ public class GameStateTests {
@Test @Test
void testList() { void testList() {
final var hiPlayer1 = holdingIdentityResolver.getByUsername(player1); final var hiPlayer1 = holdingIdentityResolver.getByUsername(player1);
final var hiPlayer2 = holdingIdentityResolver.getByUsername(player2);
List<GameState> gsList = cordaClient.gameStateList(hiPlayer1); final GameState p1GameView = cordaClient.gameProposalCreate(
hiPlayer1, hiPlayer2, Color.BLACK, "GameState List test");
System.out.println(gsList); final UUID gameUuid = p1GameView.uuid();
/*
* Both players shall be able to find newly created GameProposal aka GameList
*/
final List<GameState> p1GameList = cordaClient.gameStateList(hiPlayer1);
final List<GameState> p2GameList = cordaClient.gameStateList(hiPlayer2);
assertThat(findGameStateById(p1GameList, gameUuid)).isNotNull();
assertThat(findGameStateById(p2GameList, gameUuid)).isNotNull();
} }
@Test @Test
void testGet() { void testGet() {
final var hiPlayer1 = holdingIdentityResolver.getByUsername(player1);
final var hiPlayer2 = holdingIdentityResolver.getByUsername(player2); final var hiPlayer2 = holdingIdentityResolver.getByUsername(player2);
GameState gameStateView = cordaClient.gameStateGet(hiPlayer2, assertThatThrownBy(() -> { // trying to get GameState with nonexisting UUID
cordaClient.gameStateGet(hiPlayer2,
UUID.fromString("cf357d0a-8f64-4599-b9b5-d263163812d4") UUID.fromString("cf357d0a-8f64-4599-b9b5-d263163812d4")
); );
});
System.out.println(gameStateView); final GameState p1GameView = cordaClient.gameProposalCreate(
hiPlayer1, hiPlayer2, Color.WHITE, "GameState Get test");
final UUID gameUuid = p1GameView.uuid();
final GameState p2GameView = cordaClient.gameStateGet(hiPlayer2, gameUuid);
assertThat(p1GameView.message()).isEqualTo(p2GameView.message());
}
GameState findGameStateById(List<GameState> gameStateList, UUID gameUuid) {
return gameStateList
.stream()
.filter(gameView -> gameView.uuid().compareTo(gameUuid) == 0)
.reduce((a, b) -> {throw new IllegalStateException("Duplicate");})
.get();
} }
} }