/*
 * Copyright (c) 2015 Justin White <jw@justinwhite.net>
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  1. Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *
 *  2. Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 *  3. Neither the name of the copyright holder nor the names of its
 *  contributors may be used to endorse or promote products derived from this
 *  software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 */

package net.justinwhite.score_model;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

@SuppressWarnings("FieldCanBeLocal")
public class GameModelTest {
    private final int numPlayers;
    private final String[] playerNames;
    private final String gameName;
    private final PlayerModel[] playersArray;
    private final String newPlayerName;
    private String newPlayerInitials;
    private GameModel<PlayerModel> game;

    {
        numPlayers = 4;
        playerNames = new String[]{"Justin W", "Lauren K", "Timmay C", "Denise B"};
        gameName = "JWLKTCDB";
        newPlayerName = "Foo Bar";
        newPlayerInitials = "FB";

        playersArray = new PlayerModel[numPlayers];
    }

    @Before
    public void setUp() {
        game = new GameModel<PlayerModel>(PlayerModel.class, numPlayers);
        for (int i = 0; i < numPlayers; i++) {
            playersArray[i] = game.getPlayer(i);
            game.renamePlayer(String.format("Player %d", i + 1), playerNames[i]);

        }
    }

    @Test
    public void testToString() throws Exception {
        assertEquals(String.format("Game: %s\nUUID: %s\nPlayer count: %d\nPlayers: %s\nPlayerMap: %s",
                        game.getName(),
                        game.getID(),
                        game.getNumPlayers(),
                        game.getPlayerList(),
                        game.getPlayerMap()
                ), game.toString()
        );

    }

    @Test
    public void testBuildName() throws Exception {
        game.addPlayer(newPlayerName);
        game.buildName();
        assertEquals(gameName + newPlayerInitials, game.getName());
    }

    @Test
    public void testSetNumPlayers() throws Exception {
        game.setNumPlayers(numPlayers + 1);
        assertEquals(gameName + "P" + (numPlayers + 1), game.getName());
    }

    @Test
    public void testGetPlayerByIndex() throws Exception {
        assertSame(playersArray[0], game.getPlayer(0));
    }

    @Test
    public void testGetPlayerByName() throws Exception {
        assertSame(playersArray[0], game.getPlayerByName(playerNames[0]));
    }

    @Test
    public void testCheckPlayer() throws Exception {
        assertTrue(game.checkPlayer(playerNames[0]));
        assertFalse(game.checkPlayer("Some Player"));
    }

    @Test
    public void testAddPlayer() throws Exception {
        game.addPlayer();
        assertEquals(gameName + "P" + (numPlayers + 1), game.getName());
    }

    @Test
    public void testAddPlayerWithName() throws Exception {
        game.addPlayer(newPlayerName);
        assertEquals(gameName + newPlayerInitials, game.getName());
    }

    @Test
    public void testRenamePlayerByIndex() throws Exception {
        game.renamePlayer(0, newPlayerName);
        assertEquals(newPlayerName, game.getPlayer(0).getName());
    }

    @Test
    public void testRenamePlayerByName() throws Exception {
        game.renamePlayer(playerNames[0], newPlayerName);
        assertEquals(newPlayerName, game.getPlayerByName(newPlayerName).getName());
    }

    // TODO
    @Test
    public void testGetScores() throws Exception {

    }

    // TODO
    @Test
    public void testFindWinner() throws Exception {

    }

    // TODO
    @Test
    public void testHasWinner() throws Exception {

    }

}
@@ -1833,48 +1833,8 @@
 rs;%0A
-    private final String%5B%5D playerNames;%0A
     
@@ -2064,92 +2064,8 @@
  4;%0A
-        playerNames = new String%5B%5D%7B%22Justin W%22, %22Lauren K%22, %22Timmay C%22, %22Denise B%22%7D;%0A
     
@@ -2084,16 +2084,16 @@
  = %22
-JWLKTCDB
+P1P2P3P4
 %22;%0A 
@@ -2395,44 +2395,48 @@
     
-playersArray%5Bi%5D = game.getPlayer(i);
+// populate array for comparisons later.
 %0A   
@@ -2448,75 +2448,42 @@
     
-game.renamePlayer(String.format(%22Player %25d%22, i + 1), playerNames%5Bi%5D
+playersArray%5Bi%5D = game.getPlayer(i
 );%0A%0A
@@ -3188,32 +3188,76 @@
 ows Exception %7B%0A
+        int newNumPlayers = numPlayers + 1;%0A
         game.set
@@ -3268,16 +3268,19 @@
 layers(n
+ewN
 umPlayer
@@ -3280,20 +3280,75 @@
 mPlayers
- + 1
+);%0A        assertEquals(newNumPlayers, game.getNumPlayers()
 );%0A     
@@ -3372,34 +3372,36 @@
 ameName + %22P%22 + 
-(
 n
+ewN
 umPlayers + 1), 
@@ -3389,35 +3389,124 @@
 ewNumPlayers
- + 1)
 , game
+.getName());%0A        assertEquals(%22Player %22 + newNumPlayers, game.getPlayer(newNumPlayers - 1)
 .getName());
@@ -3633,24 +3633,65 @@
 Player(0));%0A
+        assertNull(game.getPlayer(100));%0A
     %7D%0A%0A    @
@@ -3809,30 +3809,80 @@
 rByName(
-p
+%22P
 layer
-Names%5B0%5D
+ 1%22));%0A        assertNull(game.getPlayerByName(%22Player X%22
 ));%0A    
@@ -3983,30 +3983,26 @@
 kPlayer(
-p
+%22P
 layer
-Names%5B0%5D
+ 1%22
 ));%0A    
@@ -4697,22 +4697,18 @@
 yer(
-p
+%22P
 layer
-Names%5B0%5D
+ 1%22
 , ne

Simplify and add more tests to GameModelTest