package com.adaptionsoft.games.uglytrivia;

import org.junit.Ignore;
import org.junit.Test;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class GameCorrectAnswerTest {

    @Test
    public void correctAnswerShouldGetACoin() {
        Player player = mock(Player.class);
        Game game = createGameWithSinglePlayer(player);

        game.correctAnswer();

        verify(player, times(1)).answeredCorrect();
    }

    private Game createGameWithSinglePlayer(Player player) {
        Players players = new Players();
        players.add(player);
        return new Game(players, null);
    }

    @Test
    public void correctAnswerShouldEndTurn() {
        Players players = mock(Players.class);
        Game game = new Game(players, null);

        game.correctAnswer();

        verify(players).changeCurrentPlayer();
    }

    @Test
    @Ignore("known defect in code")
    public void correctAnswerShouldGetLuckyPlayerOutOfPenaltyBox() {
        Player playerInPenaltyBox = mock(Player.class);
        when(playerInPenaltyBox.isInPenaltyBox()).thenReturn(true);
        boolean lucky = true;
        when(playerInPenaltyBox.isGettingOutOfPenaltyBox()).thenReturn(lucky);
        Game game = createGameWithSinglePlayer(playerInPenaltyBox);

        game.correctAnswer();

        verify(playerInPenaltyBox).exitPenaltyBox();
    }

    @Test
    public void correctAnswerShouldNotGetUnluckyPlayerOutOfPenaltyBox() {
        Player playerInPenaltyBox = mock(Player.class);
        when(playerInPenaltyBox.isInPenaltyBox()).thenReturn(true);
        boolean unlucky = false;
        when(playerInPenaltyBox.isGettingOutOfPenaltyBox()).thenReturn(unlucky);
        Game game = createGameWithSinglePlayer(playerInPenaltyBox);

        game.correctAnswer();

        verify(playerInPenaltyBox, never()).exitPenaltyBox();
    }

    // TODO add test for right answer with enough previous coins ends game
    // TODO add test for output if any
    // TODO refactor duplicated createGameWithSinglePlayer in both test classes
    // TODO verify this are all test cases for correct answer
}
@@ -113,155 +113,86 @@
 org.
-mockito.Mockito.mock;%0D%0Aimport static org.mockito.Mockito.never;%0D%0Aimport static org.mockito.Mockito.times;%0D%0Aimport static org.mockito.Mockito.verify
+hamcrest.CoreMatchers.is;%0D%0Aimport static org.hamcrest.MatcherAssert.assertThat
 ;%0D%0Ai
@@ -224,20 +224,17 @@
 Mockito.
-when
+*
 ;%0D%0A%0D%0Apub
@@ -1202,32 +1202,38 @@
 true);%0D%0A        
+final 
 boolean lucky = 
@@ -1706,16 +1706,22 @@
         
+final 
 boolean 
@@ -2004,78 +2004,533 @@
     
-// TODO add test for right answer with enough previous coins ends game
+@Test%0D%0A    public void correctAnswerWithNotEnoughCoinsDoesNotEndGame() %7B%0D%0A        Player player = new Player(%22unlucky%22);%0D%0A        Game game = createGameWithSinglePlayer(player);%0D%0A%0D%0A        for (int i = 0; i %3C 5; i++) %7B%0D%0A            assertThat(game.correctAnswer(), is(true));%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A    @Test%0D%0A    @Ignore%0D%0A    public void correctAnswerWithEnoughCoinsEndsGame() %7B%0D%0A        Player player = mock(Player.class);%0D%0A        Game game = createGameWithSinglePlayer(player);%0D%0A%0D%0A        game.correctAnswer();%0D%0A%0D%0A%0D%0A    %7D%0D%0A
 %0D%0A  

add test that correct Answer With Not Enough Coins Does Not End Game