Package games.gofish.state

Source Code of games.gofish.state.TestPlayerTurnState

package games.gofish.state;
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import game.Card;
import game.Player;
import games.gofish.GoFish;
import org.junit.Before;
import org.junit.Test;
/**
* Test all functionality for PlayerTurnState
* @author TJ Renninger
*
*/
public class TestPlayerTurnState
{
  private PlayerTurnState state;
  private Player p1, p2;
 
  @Before
  /**
   * Create a new state and players for each test
   */
  public void setUp()
  {
    state = new PlayerTurnState();
    p1 = new Player();
    p2 = new Player();
  }
 
  @Test
  /**
   * Test to make sure a card can be asked for
   */
  public void testAskForCard()
  {
    p2.getHand().addCard(new Card(15, 'h'));
    state.askForCard(new GoFish(), p1, p2, 15);
    assertTrue(p1.getHand().contains(new Card(15, 'h')));
    assertFalse(p2.getHand().contains(new Card(15, 'h')));
  }
 
  @Test
  /**
   * Test to make sure the player can fish
   */
  public void testFishing()
  {
    p1.draw();
    int old = p1.getHand().getSize();
    state.goFish(p1, p2);
    assertEquals(old + 1, p1.getHand().getSize());
  }
 
  @Test
  /**
   * Test to make sure matches are found
   */
  public void testCheckingForMatch()
  {
    assertFalse(state.checkForMatch(p1, p2));
    ArrayList<Card> list = new ArrayList<Card>();
    List<Card> l = Arrays.asList(new Card[] {new Card(14, 'c'), new Card(14, 'd'), new Card(14, 'h'), new Card(14, 's')});
    list.addAll(l);
    p1.getHand().addCards(list);
    assertTrue(state.checkForMatch(p1, p2));
  }
}
TOP

Related Classes of games.gofish.state.TestPlayerTurnState

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.