Example #1
0
  /** Tests the move method in a out of range case */
  @Test(expected = OutOfBoardException.class)
  public void move_out() throws OutOfBoardException {
    Board boardMock = Mockito.mock(Board.class);
    when(boardMock.getXSize()).thenReturn(5);
    when(boardMock.getYSize()).thenReturn(5);

    Pawn pawn = new Pawn('a', 1, 2, boardMock);
    pawn.move(Direction.Left);
  }
Example #2
0
  /** Tests the constructor in a correct context */
  @Test
  public void construct_correct() {
    Board boardMock = Mockito.mock(Board.class);
    Pawn pawn = new Pawn('a', 1, 2, boardMock);

    assertEquals('a', pawn.getLetter());
    assertEquals(1, pawn.getX());
    assertEquals(2, pawn.getY());
    assertEquals(0, pawn.getGold());
  }
Example #3
0
  /** Tests the move method in a correct context */
  @Test
  public void move_correct() throws OutOfBoardException {
    Board boardMock = Mockito.mock(Board.class);
    when(boardMock.getXSize()).thenReturn(5);
    when(boardMock.getYSize()).thenReturn(5);

    Pawn pawn = new Pawn('a', 1, 2, boardMock);
    pawn.move(Direction.Right);

    assertEquals(2, pawn.getX());
  }
Example #4
0
  /**
   * Test de l'ensemble des getters. On initialise un Board avec mockito et un pawn On vérifie que
   * les méthodes getX(), getY(), getLetter() et getGold() retournent les bonnes valeurs.
   */
  @Test
  public void getTest() {
    // Stub d'un board.
    Board mockBoard = mock(Board.class);

    // Initialisation d'un Pawn.
    Pawn myPawn = new Pawn('l', 2, 4, mockBoard);

    // On vérifie le retour des getters.
    assertEquals(2, myPawn.getX());
    assertEquals(4, myPawn.getY());
    assertEquals('l', myPawn.getLetter());
    assertEquals(0, myPawn.getGold());
  }
Example #5
0
  /**
   * Test de la méthode move(). On initialise un Board avec mockito et un Pawn On faut bouger le
   * Pawn et on vérifie au fur et à mesure que la position de celui-ci change.
   */
  @Test
  public void moveTest() throws OutOfBoardException {
    // Stub d'un board.
    Board mockBoard = mock(Board.class);
    when(mockBoard.getXSize()).thenReturn(4);
    when(mockBoard.getYSize()).thenReturn(4);

    // Initialisation du Pawn.
    Pawn myPawn = new Pawn('l', 1, 3, mockBoard);

    // On bouge le Pawn et on vérifie en même temps.
    myPawn.move(Direction.Right);
    assertEquals(2, myPawn.getX());

    myPawn.move(Direction.Down);
    assertEquals(2, myPawn.getY());

    myPawn.move(Direction.Left);
    assertEquals(1, myPawn.getX());

    myPawn.move(Direction.Up);
    assertEquals(3, myPawn.getY());
  }
Example #6
0
  /** Test de la méthode isDead(). */
  @Test
  public void isDeadTest() throws OutOfBoardException {
    // Stub d'un board.
    Board mockBoard = mock(Board.class);
    when(mockBoard.getXSize()).thenReturn(4);
    when(mockBoard.getYSize()).thenReturn(4);
    when(mockBoard.isBonusSquare(2, 2)).thenReturn(true);
    when(mockBoard.numberOfPawns()).thenReturn(0);

    Pawn myPawn1 = new Pawn('l', 2, 2, mockBoard);
    Pawn myPawn2 = new Pawn('m', 1, 2, mockBoard);
    myPawn2.move(Direction.Right);
    myPawn1.move(Direction.Left);
    myPawn2.move(Direction.Left);

    assertFalse(myPawn1.isDead());
  }