src/test/java/com/webcheckers/ui/GetGameRouteTest.java
/**
     * Test for joining an existing game.
     */
Test for joining an existing game.
Test for joining an existing game .
@Test
    public void join_game() {
        final Game game = new Game(player, otherPlayer);
        when(session.attribute(SessionAttributes.PLAYER)).thenReturn(player);
        when(gameCenter.getGameByPlayer(player)).thenReturn(game);
        final TemplateEngineTester testHelper = new TemplateEngineTester();
        when(engine.render(any(ModelAndView.class))).thenAnswer(testHelper.makeAnswer());
        try {
            CuT.handle(request, response);
        } catch (InterruptedException e) {
        }
        testHelper.assertViewModelExists();
        testHelper.assertViewModelIsaMap();
         attributes
        testHelper.assertViewModelAttribute(VMAttributes.TITLE, GetGameRoute.GAME_TITLE);
        testHelper.assertViewModelAttribute(VMAttributes.MESSAGE, GetGameRoute.WELCOME_MSG);
        testHelper.assertViewModelAttribute(VMAttributes.CURRENT_USER, player);
        testHelper.assertViewModelAttribute(VMAttributes.RED_PLAYER, game.getRedPlayer());
        testHelper.assertViewModelAttribute(VMAttributes.WHITE_PLAYER, game.getWhitePlayer());
        testHelper.assertViewModelAttribute(VMAttributes.VIEW_MODE, Game.ViewMode.PLAY);
        testHelper.assertViewModelAttribute(VMAttributes.BOARD, game.getBoardView());
        testHelper.assertViewModelAttribute(VMAttributes.ACTIVE_COLOR, game.getActiveColor());
    }
@ Test public void join_game ( ) { final Game game = new Game ( player , otherPlayer ) ; when ( session . attribute ( SessionAttributes . PLAYER ) ) . thenReturn ( player ) ; when ( gameCenter . getGameByPlayer ( player ) ) . thenReturn ( game ) ; final TemplateEngineTester testHelper = new TemplateEngineTester ( ) ; when ( engine . render ( any ( ModelAndView . class ) ) ) . thenAnswer ( testHelper . makeAnswer ( ) ) ; try { CuT . handle ( request , response ) ; } catch ( InterruptedException e ) { } testHelper . assertViewModelExists ( ) ; testHelper . assertViewModelIsaMap ( ) ; testHelper . assertViewModelAttribute ( VMAttributes . TITLE , GetGameRoute . GAME_TITLE ) ; testHelper . assertViewModelAttribute ( VMAttributes . MESSAGE , GetGameRoute . WELCOME_MSG ) ; testHelper . assertViewModelAttribute ( VMAttributes . CURRENT_USER , player ) ; testHelper . assertViewModelAttribute ( VMAttributes . RED_PLAYER , game . getRedPlayer ( ) ) ; testHelper . assertViewModelAttribute ( VMAttributes . WHITE_PLAYER , game . getWhitePlayer ( ) ) ; testHelper . assertViewModelAttribute ( VMAttributes . VIEW_MODE , Game . ViewMode . PLAY ) ; testHelper . assertViewModelAttribute ( VMAttributes . BOARD , game . getBoardView ( ) ) ; testHelper . assertViewModelAttribute ( VMAttributes . ACTIVE_COLOR , game . getActiveColor ( ) ) ; }
Test for joining an existing game.
Test for joining an existing game .
//Create a game instance with two mock players for testing //Mock call to playerLobby //Template engine tester //Call handle on the CuT //Test viewmodel //Test viewmodel attributes