CoincheGame extends RedBlueRotatingPlayersGame<Player> { protected GameResult<Team> moveWasApplied() { GameResult<Team> result = currentRound.moveWasApplied(); if (!result.isFinished()) { newRound = false; return GameResult.unfinishedResult(); } if (result.isDraw()) { startNextRound(); return GameResult.unfinishedResult(); } for (Entry<Team, Integer> entry : result.getTeamsPoints().entrySet()) { entry.getKey().addPoints(entry.getValue()); } if (isFinished()) { return GameResult.finishedResult( Map.of((Team) redTeam, redTeam.getPoints(), (Team) blueTeam, blueTeam.getPoints())); } startNextRound(); return GameResult.unfinishedResult(); } CoincheGame(Team redTeam, Team blueTeam); CoincheGameRound getCurrentRound(); static int getMaxTricksPoints(); static int getWinningPoints(); boolean isNewRound(); Player getPlayer(String username);  }
@Test public void moveWasApplied() { CoincheGameRound currentRound = coincheGame.getCurrentRound(); CoincheGameRound spyRound = spy(currentRound); coincheGame.setCurrentRound(spyRound); GameResult<Team> roundResult = GameResult.unfinishedResult(); doReturn(roundResult).when(spyRound).moveWasApplied(); GameResult<Team> gameResult = coincheGame.moveWasApplied(); assertThat(gameResult.isFinished()) .as("UNFINISHED ROUND - Check game hasn't finished yet") .isFalse(); assertThat(coincheGame.getCurrentPlayerIndex()) .as("UNFINISHED ROUND - Check player index is still 0") .isEqualTo(0); assertThat(coincheGame.getCurrentRound()) .as("UNFINISHED ROUND - Check round is still the same") .isEqualTo(spyRound); roundResult = GameResult.finishedResult(Map.of(t1, 0, t2, 0)); doReturn(roundResult).when(spyRound).moveWasApplied(); gameResult = coincheGame.moveWasApplied(); assertThat(gameResult.isFinished()) .as("FINISHED ROUND - Check that the game hasn't finished yet") .isFalse(); assertThat(coincheGame.getCurrentPlayerIndex()) .as("FINISHED ROUND - Check new player index is 1") .isEqualTo(1); assertThat(coincheGame.getCurrentRound()) .as("FINISHED ROUND - Check new round isn't null") .isNotNull(); assertThat(coincheGame.getCurrentRound()) .as("FINISHED ROUND - Check round has changed") .isNotEqualTo(spyRound); assertThat(coincheGame.getCurrentRound().getState()) .as("FINISHED ROUND - Check new state isn't null") .isNotNull(); assertThat(coincheGame.getCurrentRound().getState().getCurrentPlayer()) .as("FINISHED ROUND - Check first player of new state is p2") .isEqualTo(p2); currentRound = coincheGame.getCurrentRound(); spyRound = spy(currentRound); coincheGame.setCurrentRound(spyRound); roundResult = GameResult.finishedResult(Map.of(t1, 42000, t2, 0)); doReturn(roundResult).when(spyRound).moveWasApplied(); gameResult = coincheGame.moveWasApplied(); assertThat(gameResult.isFinished()) .as("FINISHED GAME - Check that the game has finished") .isTrue(); }