package org.amc.game.chessserver;

import static org.junit.Assert.*;

import org.amc.game.chess.ChessGamePlayer;
import org.amc.game.chess.Colour;
import org.amc.game.chess.HumanPlayer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.web.ModelAndViewAssert;
import org.springframework.web.servlet.ModelAndView;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class StartPageControllerChessAppPageTest {
    private MockHttpSession session;
    private ConcurrentMap<Long, ServerChessGame> gameMap;
    private StartPageController controller;
    private ChessGamePlayer whitePlayer;
    private ServerChessGameFactory scgFactory;

    @Before
    public void setUp() throws Exception {
        scgFactory = new ServerChessGameFactory();
        session = new MockHttpSession();
        gameMap = new ConcurrentHashMap<>();
        controller = new StartPageController(); 
        
        controller.setGameMap(gameMap);
        controller.setServerChessGameFactory(scgFactory);
        whitePlayer = new ChessGamePlayer(new HumanPlayer("Ted"), Colour.WHITE);
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void testPlayerAvailable() {
        session.setAttribute(ServerConstants.PLAYER.toString(), whitePlayer);
        ModelAndView mav = controller.chessGameApplication(session);
        assertNotNull(session.getAttribute(ServerConstants.PLAYER.toString()));
        ModelAndViewAssert.assertModelAttributeAvailable(mav, ServerConstants.GAMEMAP.toString());
        ModelAndViewAssert.assertViewName(mav,
                        StartPageController.CHESS_APPLICATION_PAGE);
    }
}

@@ -61,16 +61,53 @@
 ssert.*;
+%0Aimport static org.mockito.Mockito.*;
 %0A%0Aimport
@@ -397,16 +397,77 @@
 Assert;%0A
+import org.springframework.web.HttpSessionRequiredException;%0A
 import o
@@ -1880,10 +1880,376 @@
 ;%0A    %7D%0A
+    %0A    @Test%0A    public void handleMissingSessionAttributesTest() %7B%0A        HttpSessionRequiredException hsre = mock(HttpSessionRequiredException.class);%0A        when(hsre.getMessage()).thenReturn(%22Mock Exception%22);%0A        String view = controller.handleMissingSessionAttributes(hsre);%0A        assertEquals(StartPageController.TWOVIEW_REDIRECT_PAGE, view);%0A    %7D%0A
 %7D%0A

add test for handleMissingSessionAttributesTest()