package pdp.scrabble.test.bag;
import pdp.scrabble.Language;
import pdp.scrabble.game.Letter;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import pdp.scrabble.Game;
import pdp.scrabble.game.Bag;
import static pdp.scrabble.Factory.FACTORY;
public class BagAccess {
private static final Game GAME = FACTORY.createGame(Language.init("English"), null);
public BagAccess() {
}
@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 bagAccessTester() {
Bag bag = GAME.bag();
try {
bag.initWithLanguage("");
}
catch (NullPointerException e) {
System.out.println("Language doesn't not exist.");
}
try {
bag.initWithLanguage("English");
System.out.println("Initialize bag");
}
catch (NullPointerException e) {
fail("NullPointerException was not expected");
}
try {
bag.fill();
System.out.println("Fill bag");
}
catch (ArrayIndexOutOfBoundsException e) {
fail("ArrayIndexOutOfBoundsException was not expected");
}
try {
boolean expResult = false;
boolean result = bag.isEmpty();
assertEquals(expResult, result);
System.out.println("Bag is not empty");
}
catch (ArrayIndexOutOfBoundsException e) {
fail("ArrayIndexOutOfBoundsException was not expected");
}
try {
Letter letter = null;
bag.addLetter(letter);
System.out.println("Can add a null letter in bag");
}
catch (NullPointerException ex) {
fail("NullPointerException was not expected");
}
try {
String word = "";
int expResult = 0;
int result = bag.getWordValue(word);
assertEquals(expResult, result);
System.out.println("getWordValue");
}
catch (NullPointerException e) {
fail("NullPointerException was not expected");
}
try {
String letter = "";
int expResult = 0;
int result = bag.getLetterValue(letter);
assertEquals(expResult, result);
System.out.println("getLetterValue");
}
catch (NullPointerException e) {
fail("NullPointerException was not expected");
}
bag.clear();
if (bag.getRandomLetter() == null) {
System.out.println("Can't get a letter from empty bag");
}
else {
fail("null was expected");
}
}
}