1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/chess/src/test/java/org/apidesign/html/demo/chess/BoardModelTest.java Thu Jul 25 17:14:55 2013 +0200
1.3 @@ -0,0 +1,65 @@
1.4 +/**
1.5 + * The MIT License (MIT)
1.6 + *
1.7 + * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.8 + *
1.9 + * Permission is hereby granted, free of charge, to any person obtaining a copy
1.10 + * of this software and associated documentation files (the "Software"), to deal
1.11 + * in the Software without restriction, including without limitation the rights
1.12 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1.13 + * copies of the Software, and to permit persons to whom the Software is
1.14 + * furnished to do so, subject to the following conditions:
1.15 + *
1.16 + * The above copyright notice and this permission notice shall be included in
1.17 + * all copies or substantial portions of the Software.
1.18 + *
1.19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1.20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1.21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1.22 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1.23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1.24 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1.25 + * THE SOFTWARE.
1.26 + */
1.27 +package org.apidesign.html.demo.chess;
1.28 +
1.29 +import static org.testng.Assert.*;
1.30 +import org.testng.annotations.Test;
1.31 +
1.32 +/**
1.33 + *
1.34 + * @author Jaroslav Tulach <jtulach@netbeans.org>
1.35 + */
1.36 +public class BoardModelTest {
1.37 +
1.38 + public BoardModelTest() {
1.39 + }
1.40 +
1.41 +
1.42 + @Test public void e2e4() {
1.43 + Board b = BoardModel.createBoard();
1.44 + Square e2 = BoardModel.findSquare(b, 'E', 2);
1.45 + assertNotNull(e2);
1.46 + BoardModel.selected(b, e2);
1.47 + assertEquals(BoardModel.findSelectedSquare(b), e2, "E2 is selected");
1.48 +
1.49 + Square e4 = BoardModel.findSquare(b, 'E', 4);
1.50 + assertNotNull(e4);
1.51 +
1.52 + BoardModel.selected(b, e4);
1.53 +
1.54 + assertNull(e2.getPiece(), "No pawn at e2");
1.55 + assertEquals(e4.getPiece(), BoardModel.PieceType.PAWN, "Pawn moved successfully");
1.56 + assertNull(BoardModel.findSelectedSquare(b), "No square selected");
1.57 +
1.58 + }
1.59 +
1.60 + @Test public void cantSelectEmptySquare() {
1.61 + Board b = BoardModel.createBoard();
1.62 + Square e3 = BoardModel.findSquare(b, 'E', 3);
1.63 + assertNotNull(e3);
1.64 + BoardModel.selected(b, e3);
1.65 + assertNull(BoardModel.findSelectedSquare(b), "No square is selected");
1.66 + }
1.67 +
1.68 +}