|
| 1 | +package domain; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.BeforeEach; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | + |
| 6 | +import java.util.ArrayList; |
| 7 | +import java.util.Arrays; |
| 8 | +import java.util.List; |
| 9 | + |
| 10 | +import static org.assertj.core.api.Assertions.assertThat; |
| 11 | +import static org.junit.jupiter.api.Assertions.assertAll; |
| 12 | + |
| 13 | +public class BowlingMatchTest { |
| 14 | + |
| 15 | + private static final int INDEX_OF_FIRST_PLAYER = 0; |
| 16 | + private static final int INDEX_OF_SECOND_PLAYER = 1; |
| 17 | + private List<Player> players; |
| 18 | + private BowlingMatch bowlingMatch; |
| 19 | + |
| 20 | + @BeforeEach |
| 21 | + void setUp() { |
| 22 | + Player player1 = Player.from("hjs"); |
| 23 | + Player player2 = Player.from("pje"); |
| 24 | + Player player3 = Player.from("jek"); |
| 25 | + players = new ArrayList<>(Arrays.asList(player1, player2, player3)); |
| 26 | + bowlingMatch = BowlingMatch.start(players); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + void 플레이어들을_입력하여_볼링경기를_생성한다() { |
| 31 | + assertThat(bowlingMatch).isNotNull(); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + void 현재_플레이중인_플레이어를_반환한다() { |
| 36 | + //when |
| 37 | + BowlingGame bowlingGame = bowlingMatch.getOngoingGame(); |
| 38 | + |
| 39 | + //then |
| 40 | + assertThat(bowlingGame.getPlayer()) |
| 41 | + .isEqualTo(players.get(INDEX_OF_FIRST_PLAYER)); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + void 현재_플레이중인_프레임이_종료되면_다음_플레이어가_플레이한다() { |
| 46 | + //when |
| 47 | + BowlingGame bowlingGame = bowlingMatch.getOngoingGame(); |
| 48 | + bowlingGame.play(Pins.STRIKE); |
| 49 | + |
| 50 | + BowlingGame ongoingGame = bowlingMatch.getOngoingGame(); |
| 51 | + |
| 52 | + //then |
| 53 | + assertAll( |
| 54 | + () -> assertThat(bowlingGame.getFirstFrame().getState().isClosed()).isTrue(), |
| 55 | + () -> assertThat(ongoingGame.getPlayer()).isEqualTo(players.get(INDEX_OF_SECOND_PLAYER)) |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void 모든_볼링게임이_종료되면_볼링경기가_종료된다() { |
| 61 | + //given |
| 62 | + int numberOfPlaysForPerfectGame = players.size() * 12; |
| 63 | + |
| 64 | + //when |
| 65 | + for (int i = 0; i < numberOfPlaysForPerfectGame; i++) { |
| 66 | + BowlingGame ongoingGame = bowlingMatch.getOngoingGame(); |
| 67 | + ongoingGame.play(Pins.STRIKE); |
| 68 | + } |
| 69 | + |
| 70 | + //then |
| 71 | + assertThat(bowlingMatch.isOver()).isTrue(); |
| 72 | + } |
| 73 | +} |
0 commit comments