Exemple #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);
  }
Exemple #2
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());
  }
Exemple #3
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());
  }
Exemple #4
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());
  }