<commit_before>package au.com.aitcollaboration.chessgame.game;

import au.com.aitcollaboration.chessgame.board.Board;
import au.com.aitcollaboration.chessgame.player.Color;
import au.com.aitcollaboration.chessgame.player.Players;
import au.com.aitcollaboration.chessgame.support.In;
import au.com.aitcollaboration.chessgame.support.Utils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.List;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;

@RunWith(PowerMockRunner.class)
@PrepareForTest({Utils.class, In.class})
public class GameTest {

    @Mock
    private Board board;
    @Mock
    private Rules rules;
    @Mock
    private Players players;

    private Game game;

    @Before
    public void setUp() throws Exception {
        initMocks(this);
        mockStatic(Utils.class);
        mockStatic(In.class);

        game = new Game(board, rules, players);

        when(In.nextLine(anyString())).thenReturn("answer");
    }

    @Test
    public void testAddPlayerMethodHaveBeenCalledForMultiplePlayers() {
        when(In.nextInt(anyString())).thenReturn(3);

        game.playersSetUp();

        verify(players, times(2)).addHumanPlayer(anyString(), any(Color.class));
    }

    @Test
    public void testAddPlayerMethodHaveBeenCalledForSinglePlayer() {
        when(In.nextInt(anyString())).thenReturn(1);

        game.playersSetUp();

        verify(players, times(1)).addHumanPlayer(anyString(), any(Color.class));
        verify(players, times(1)).addComputerPlayer(any(Color.class));
    }

    @Test
    public void testShouldNotCallRunGameWhenGameOverIsTrue() {
        game.setGameOver(true);
        game.runGame();

        verify(players, times(0)).play();
    }

    @Test
    public void testShouldCallRunGameWhenGameOverIsFalse() {
        when(rules.isCheckMate(board)).thenReturn(false);
        when(rules.isMatchDraw(any(List.class))).thenReturn(true);

        game.runGame();

        verify(players, times(1)).play();
    }

    @Test
    public void testShouldReturnGameOverTrueWhenIsCheckMateOrIsMatchDraw() {
        when(rules.isCheckMate(board)).thenReturn(false);
        when(rules.isMatchDraw(any(List.class))).thenReturn(true);

        boolean gameOver = game.isGameOver();

        assertThat(gameOver, is(true));
    }<commit_msg>[Dev][Enrico] Fixed bug in GameTest.java<commit_after>package au.com.aitcollaboration.chessgame.game;

import au.com.aitcollaboration.chessgame.board.Board;
import au.com.aitcollaboration.chessgame.player.*;
import au.com.aitcollaboration.chessgame.support.In;
import au.com.aitcollaboration.chessgame.support.Utils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.List;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;

@RunWith(PowerMockRunner.class)
@PrepareForTest({Utils.class, In.class})
public class GameTest {

    @Mock
    private Board board;
    @Mock
    private Rules rules;
    @Mock
    private Players players;

    private Game game;

    @Before
    public void setUp() throws Exception {
        initMocks(this);
        mockStatic(Utils.class);
        mockStatic(In.class);

        game = new Game(board, rules, players);

        when(In.nextLine(anyString())).thenReturn("answer");
    }

    @Test
    public void testAddPlayerMethodHaveBeenCalled() {
        when(In.nextInt(anyString())).thenReturn(3);

        game.playersSetUp();

        verify(players, times(2)).add(any(Player.class));
    }

    @Test
    public void testAddPlayerMethodHaveBeenCalledForSinglePlayer() {
        when(In.nextInt(anyString())).thenReturn(1);

        game.playersSetUp();

        verify(players, times(2)).add(any(Player.class));
    }

    @Test
    public void testShouldNotCallRunGameWhenGameOverIsTrue() {
        game.setGameOver(true);
        game.runGame();

        verify(players, times(0)).play();
    }

    @Test
    public void testShouldCallRunGameWhenGameOverIsFalse() {
        when(rules.isCheckMate(board)).thenReturn(false);
        when(rules.isMatchDraw(any(List.class))).thenReturn(true);

        game.runGame();

        verify(players, times(1)).play();
    }

    @Test
    public void testShouldReturnGameOverTrueWhenIsCheckMateOrIsMatchDraw() {
        when(rules.isCheckMate(board)).thenReturn(false);
        when(rules.isMatchDraw(any(List.class))).thenReturn(true);

        boolean gameOver = game.isGameOver();

        assertThat(gameOver, is(true));
    }
{'fraction_non_alphanumeric': 0.12175832260437741, 'fraction_numerical': 0.0027588743792532648, 'mean_word_length': 3.8510258697591437, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '16252', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1689, 'n_words': 264}