Package pdp.scrabble.test.board

Source Code of pdp.scrabble.test.board.BoardAccess

package pdp.scrabble.test.board;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import pdp.scrabble.Game;
import pdp.scrabble.game.exception.BoardWrongWordPlace;
import pdp.scrabble.game.Board;
import static org.junit.Assert.fail;
import static pdp.scrabble.Factory.FACTORY;

public class BoardAccess {
    private static final Game GAME = FACTORY.createGame("English", null);

    public BoardAccess() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
  GAME.create();
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    @Test
    public void boardAccessTester() {
  Board board = GAME.board();

  try {
      board.getCase(0, 0);
      System.out.println("Can get 0, 0");
  }
  catch (ArrayIndexOutOfBoundsException e) {
      fail("ArrayIndexOutOfBoundsException was not expected");
  }

  try {
      board.getCase(-1, -1);
      System.out.println("Can get -1, -1; but not recommended (safe border only)");
  }
  catch (ArrayIndexOutOfBoundsException e) {
      fail("ArrayIndexOutOfBoundsException was not expected");
  }

  try {
      board.getCase(-2, -2);
      fail("ArrayIndexOutOfBoundsException was expected");
  }
  catch (ArrayIndexOutOfBoundsException e) {
      System.out.println("Can't get -2, -2");
  }

  System.out.println("Clear board and validate it");
  board.clear();
  try {
      board.validate(true);
      System.out.println("Board check ignored, because no new letter added");
  }
  catch (BoardWrongWordPlace ex) {
      fail("BoardWrongWordPlace was not expected");
  }

  System.out.println("Add new letter at 0, 0");
  board.setCaseLetter(0, 0, FACTORY.createLetter('A', 1, 0), true);
  try {
      board.validate(true);
      fail("BoardWrongWordPlace was expected");
  }
  catch (BoardWrongWordPlace ex) {
      System.out.println("BoardWrongWordPlace error, because center is not used");
  }

  try {
      board.cancel(null);
  }
  catch (NullPointerException ex) {
      fail("NullPointerException was not expected");
  }

  try {
      board.switchCasesLetter(-1, -1, 0, 0);
      System.out.println("Can switch -1, -1 and 0, 0, but not recommended (used as safe area)");
  }
  catch (ArrayIndexOutOfBoundsException e) {
      fail("ArrayIndexOutOfBoundsException was not expected");
  }

  try {
      board.switchCasesLetter(-2, -2, 0, 0);
      fail("ArrayIndexOutOfBoundsException was expected");
  }
  catch (ArrayIndexOutOfBoundsException e) {
      System.out.println("Can't switch -2, -2 and 0, 0");
  }
    }
}
TOP

Related Classes of pdp.scrabble.test.board.BoardAccess

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.