Package pdp.scrabble.test.rack

Source Code of pdp.scrabble.test.rack.LetterGetter

package pdp.scrabble.test.rack;

import pdp.scrabble.Language;
import pdp.scrabble.Game;
import java.util.List;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import pdp.scrabble.game.Rack;
import pdp.scrabble.game.Letter;
import pdp.scrabble.game.Player;
import static org.junit.Assert.*;
import static pdp.scrabble.Factory.FACTORY;

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

    public LetterGetter() {
    }

    @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 letterGetterTester() {
  Player player = FACTORY.createPlayer(GAME, "test", 0, false, null);

  System.out.println("Test standard letter access (nomal access [0-6]):");

  try {
      player.getLetter(-1);
      fail("ArrayIndexOutOfBoundsException was expected");
  }
  catch (ArrayIndexOutOfBoundsException e) {
      System.out.println("Can't get -1");
  }

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

  try {
      player.getLetter(6);
      System.out.println("Can get 6");
  }
  catch (ArrayIndexOutOfBoundsException e) {
      fail("ArrayIndexOutOfBoundsException was not expected");
  }

  try {
      player.getLetter(7);
      fail("ArrayIndexOutOfBoundsException was expected");
  }
  catch (ArrayIndexOutOfBoundsException e) {
      System.out.println("Can't get 7");
  }

  try {
      player.getLetter(-64);
      fail("ArrayIndexOutOfBoundsException was expected");
  }
  catch (ArrayIndexOutOfBoundsException e) {
      System.out.println("Can't get -64");
  }

  try {
      player.getLetter(99);
      fail("ArrayIndexOutOfBoundsException was expected");
  }
  catch (ArrayIndexOutOfBoundsException e) {
      System.out.println("Can't get 99");
  }

  System.out.println("Get from a list");
  List<Letter> letters = player.getLetters();
  int len = letters.size();

  if (len != Rack.MAX_RACK_LETTERS) {
      fail("Number of returned letter different of expected number (" + len + " instead of " + Rack.MAX_RACK_LETTERS + " )");
  }

  for (int i = 0; i < len; i++) {
      try {
    player.getLetter(i);
    System.out.println("Can get " + i);
      }
      catch (ArrayIndexOutOfBoundsException e) {
    fail("ArrayIndexOutOfBoundsException was not expected");
      }
  }
    }
}
TOP

Related Classes of pdp.scrabble.test.rack.LetterGetter

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.