/*
 * 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.phase_10;

import net.justinwhite.score_model.Version;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

@SuppressWarnings("FieldCanBeLocal")
public class Phase10PlayerTest {
    private final String name = "Test Phase10Player";
    private final Integer score = 11;
    private final Integer phase = 1;
    private Phase10Player player;

    @Before
    public void setUp() throws Exception {
        player = new Phase10Player(name);
    }

    @Test
    public void testConstructors() throws Exception {
        System.out.println("Testing: " + Version.getVersion() + ": Phase10Player");
        player = new Phase10Player(name, Phase10Game.PhaseSet.EVEN);
        player.completeCurrentPhase();
        assertEquals(Integer.valueOf(2), player.currentPhaseNumber());
        player.completeCurrentPhase();
        assertEquals(Integer.valueOf(4), player.currentPhaseNumber());
        player = new Phase10Player(name, Phase10Game.PhaseSet.ODD);
        player.completeCurrentPhase();
        assertEquals(Integer.valueOf(1), player.currentPhaseNumber());
        player.completeCurrentPhase();
        assertEquals(Integer.valueOf(3), player.currentPhaseNumber());
    }

    @Test
    public void testToString() throws Exception {
        player.addScore(score);
        player.completeCurrentPhase();
        assertEquals(String.format(
                "Name '%s'; Score %s; Phase %d",
                name,
                score,
                phase
                ), player.toString()
        );
    }

    @Test
    public void testSetPhases() throws Exception {
        player.setPhases(Phase10Game.getPhasePreset(Phase10Game.PhaseSet.ALL));
        player.completeCurrentPhase();
        assertEquals(Integer.valueOf(1), player.currentPhaseNumber());
    }

    @Test
    public void testAddScore() throws Exception {
        player.addScore(score);
        assertEquals(score, player.getScore());
        player.addScore(score);
        assertEquals(Integer.valueOf(score * 2), player.getScore());
    }

    @Test
    public void testCompleteCurrentPhase() throws Exception {
        player.completeCurrentPhase();
        for (Integer i = phase + 1; i <= Phase10Game.MAX_PHASE; i++) {
            player.completeCurrentPhase();
            assertEquals(i, player.currentPhaseNumber());
        }
        assertEquals(Phase10Game.MAX_PHASE, player.currentPhaseNumber());
        player.completeCurrentPhase();
        player.completeCurrentPhase();
        assertEquals(Phase10Game.MAX_PHASE, player.currentPhaseNumber());
    }
}

@@ -1747,16 +1747,66 @@
 .Test;%0A%0A
+import static org.junit.Assert.assertArrayEquals;%0A
 import s
@@ -2167,20 +2167,16 @@
 0Player(
-name
 );%0A    %7D
@@ -2337,284 +2337,96 @@
     
-player = new Phase10Player(name, Phase10Game.PhaseSet.EVEN);%0A        player.completeCurrentPhase();%0A        assertEquals(Integer.valueOf(2), player.currentPhaseNumber());%0A        player.completeCurrentPhase();%0A        assertEquals(Integer.valueOf(4), player.currentPhaseNumber
+assertArrayEquals(Phase10Game.getPhasePreset(Phase10Game.PhaseSet.ALL), player.getPhases
 ());
@@ -2492,11 +2492,12 @@
 Set.
-ODD
+EVEN
 );%0A 
@@ -2507,215 +2507,97 @@
     
-player.completeCurrentPhase();%0A        assertEquals(Integer.valueOf(1), player.currentPhaseNumber());%0A        player.completeCurrentPhase();%0A        assertEquals(Integer.valueOf(3), player.currentPhaseNumber
+assertArrayEquals(Phase10Game.getPhasePreset(Phase10Game.PhaseSet.EVEN), player.getPhases
 ());
@@ -2656,32 +2656,62 @@
 ows Exception %7B%0A
+        player.setName(name);%0A
         player.a
@@ -3051,16 +3051,22 @@
 ayer.set
+Active
 Phases(P
@@ -3206,34 +3206,367 @@
  player.
-currentPhaseNumber
+getCurrentPhase());%0A        player.setActivePhases(Phase10Game.getPhasePreset(Phase10Game.PhaseSet.ODD));%0A        player.resetCurrentPhase();%0A        player.completeCurrentPhase();%0A        assertEquals(Integer.valueOf(1), player.getCurrentPhase());%0A        player.completeCurrentPhase();%0A        assertEquals(Integer.valueOf(3), player.getCurrentPhase
 ());%0A   
@@ -4069,33 +4069,36 @@
 quals(i, player.
-c
+getC
 urrentPhaseNumbe
@@ -4084,38 +4084,32 @@
 .getCurrentPhase
-Number
 ());%0A        %7D%0A 
@@ -4150,33 +4150,36 @@
 X_PHASE, player.
-c
+getC
 urrentPhaseNumbe
@@ -4165,38 +4165,32 @@
 .getCurrentPhase
-Number
 ());%0A        pla
@@ -4307,17 +4307,20 @@
  player.
-c
+getC
 urrentPh
@@ -4326,14 +4326,8 @@
 hase
-Number
 ());

Add & update tests.