### Question:
Game { public void play(Player player) { player.chooseWeapon(); Weapon weapon = player.getChosenWeapon(); validateIfFinished(); validateIfPlayerValid(player); validationIfWeaponValid(weapon); validateIfPlayerAlreadyPlayed(player); playerSelectedWeaponMap.put(player, weapon); if (hasEveryPlayerPlayed()) { winner = gameEngine.findWinner(playerSelectedWeaponMap); state = GameState.FINISHED; } else { state = GameState.WAITING_FOR_MOVE; } } Game(GameEngine gameEngine, Player player1, Player player2);  Game(GameEngine gameEngine, Set<Player> players); void play(Player player); String getId(); boolean isFinished(); Optional<Player> findWinner();  }### Answer:
@Test public void throwExceptionWhenMakeMoveAfterGameIsFinished() { Weapons weapons = new RockPaperScissorsWeapons(); GameEngine engine = new GameEngine(weapons); Player player1 = mock(HumanPlayer.class); doNothing().when(player1).chooseWeapon(); when(player1.getName()).thenReturn("Alex"); when(player1.getChosenWeapon()).thenReturn(weapons.get("Rock")); Player player2 = mock(HumanPlayer.class); doNothing().when(player2).chooseWeapon(); when(player2.getName()).thenReturn("Bart"); when(player2.getChosenWeapon()).thenReturn(weapons.get("Paper")); Game game = new Game(engine, player1, player2); game.play(player1); game.play(player2); thrown.expect(GameFinishedException.class); thrown.expectMessage("Game is finished."); game.play(player2); }
@Test public void throwExceptionWhenUnknownPlayerMakeMove() { Weapons weapons = new RockPaperScissorsWeapons(); GameEngine engine = new GameEngine(weapons); Player unknownPlayer = mock(HumanPlayer.class); doNothing().when(unknownPlayer).chooseWeapon(); when(unknownPlayer.getName()).thenReturn("Unknown"); when(unknownPlayer.getChosenWeapon()).thenReturn(weapons.get("Rock")); Player player1 = new HumanPlayer("Alex"); Player player2 = new HumanPlayer("Bart"); Game game = new Game(engine, player1, player2); thrown.expect(UnknownPlayerException.class); thrown.expectMessage("Player is not part of this game."); game.play(unknownPlayer); }
@Test public void throwExceptionWhenUnknownWeaponUsed() { Weapons weapons = new RockPaperScissorsWeapons(); GameEngine engine = new GameEngine(weapons); Player player1 = mock(HumanPlayer.class); doNothing().when(player1).chooseWeapon(); when(player1.getName()).thenReturn("Alex"); when(player1.getChosenWeapon()).thenReturn(new BasicWeapon("UnknownWeapon", "XYZ")); Player player2 = new HumanPlayer("Bart"); Game game = new Game(engine, player1, player2); thrown.expect(UnknownWeaponException.class); thrown.expectMessage("Unknown weapon."); game.play(player1); }
@Test public void throwExceptionWhenPlayerAlreadyMadeMove() { Weapons weapons = new RockPaperScissorsWeapons(); GameEngine engine = new GameEngine(weapons); Player player1 = mock(HumanPlayer.class); doNothing().when(player1).chooseWeapon(); when(player1.getName()).thenReturn("Alex"); when(player1.getChosenWeapon()).thenReturn(weapons.get("Rock")); Player player2 = new HumanPlayer("Bart"); Game game = new Game(engine, player1, player2); thrown.expect(PlayerAlreadyMadeMoveException.class); thrown.expectMessage("Player already made his/her move."); game.play(player1); game.play(player1); }