package org.amc.game.chessserver;

import static org.amc.game.chess.ChessBoard.Coordinate.*;
import static org.junit.Assert.*;

import org.amc.game.chess.ChessBoard;
import org.amc.game.chess.ChessBoardFactory;
import org.amc.game.chess.ChessBoardFactoryImpl;
import org.amc.game.chess.ChessGame;
import org.amc.game.chess.ChessGamePlayer;
import org.amc.game.chess.Colour;
import org.amc.game.chess.HumanPlayer;
import org.amc.game.chess.IllegalMoveException;
import org.amc.game.chess.Location;
import org.amc.game.chess.Move;
import org.amc.game.chess.RealChessGamePlayer;
import org.amc.game.chess.SimpleChessBoardSetupNotation;
import org.amc.game.chess.view.ChessBoardView;
import org.amc.game.chessserver.ServerChessGame;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * Bug Jira CG-42: Chess game didn't end when checkmate was achieved
 * 
 * Test ServerChessGame for ServerChessGame.status.FINISHED
 * 
 * @author Adrian Mclaughlin
 *
 */
public class BugCG42ServerChessGameDidntEndWhenCheckmateWasAchieved {

    private ChessGame chessGame;
    private ServerChessGame serverChessGame;
    private ChessBoard board;
    private ChessGamePlayer whitePlayer;
    private ChessGamePlayer blackPlayer;
    private static ChessBoardFactory boardFactory;

    @BeforeClass
    public static void setUpFactory() {
        boardFactory = new ChessBoardFactoryImpl(new SimpleChessBoardSetupNotation());
    }

    @Before
    public void setUp() throws Exception {
        whitePlayer = new RealChessGamePlayer(new HumanPlayer("White Player"), Colour.WHITE);
        blackPlayer = new RealChessGamePlayer(new HumanPlayer("Black Player"), Colour.BLACK);
        board = boardFactory
                        .getChessBoard("ra8:nc8:rc6:pd3:pb2:pe2:pf2:ph2:nb1:ke1:Pf7:Pg6:Ph6:Ka5:Pc3");
        new ChessBoardView(board);
        
        chessGame = new ChessGame(board, whitePlayer, blackPlayer);
        chessGame.setChessBoard(board);
        serverChessGame = new TwoViewServerChessGame(0l, chessGame);
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void test() throws IllegalMoveException {
        Move move = new Move(new Location(C, 6), new Location(B, 6));
        serverChessGame.move(whitePlayer, move);
        assertTrue(serverChessGame.getCurrentStatus() == ServerChessGame.ServerGameStatus.FINISHED);
    }

}

@@ -253,16 +253,63 @@
 ryImpl;%0A
+import org.amc.game.chess.ChessBoardUtilities;%0A
 import o
@@ -505,76 +505,8 @@
 on;%0A
-import org.amc.game.chess.Location;%0Aimport org.amc.game.chess.Move;%0A
 impo
@@ -722,91 +722,9 @@
 nit.
-After;%0Aimport org.junit.Before;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test
+*
 ;%0A%0A/
@@ -974,41 +974,8 @@
  %7B%0A%0A
-    private ChessGame chessGame;%0A
     
@@ -1019,38 +1019,8 @@
 me;%0A
-    private ChessBoard board;%0A
     
@@ -1060,49 +1060,8 @@
 er;%0A
-    private ChessGamePlayer blackPlayer;%0A
     
@@ -1106,16 +1106,57 @@
 Factory;
+%0A    private ChessBoardUtilities cbUtils;
 %0A%0A    @B
@@ -1457,16 +1457,32 @@
         
+ChessGamePlayer 
 blackPla
@@ -1563,24 +1563,35 @@
 K);%0A        
+ChessBoard 
 board = boar
@@ -1745,24 +1745,85 @@
         
-%0A       
+cbUtils = new ChessBoardUtilities(board); %0A        %0A        ChessGame
  chessGa
@@ -1995,72 +1995,8 @@
  %7D%0A%0A
-    @After%0A    public void tearDown() throws Exception %7B%0A    %7D%0A%0A
     
@@ -2058,78 +2058,8 @@
 n %7B%0A
-        Move move = new Move(new Location(C, 6), new Location(B, 6));%0A
     
@@ -2096,20 +2096,46 @@
 Player, 
-move
+cbUtils.createMove(%22C6%22, %22B6%22)
 );%0A     

remove unused tearDownMethod and used ChessBoardUtilities