예제 #1
0
  @Test
  public void shouldThrownExceptionIfTeamIdIsNotValid() {
    int unexistingTeamId = 999;
    final Player player = new Player();
    player.setAge(22);
    player.setCountry("Italia");
    player.setGoals(3);
    player.setName("Nuevo jugador");
    player.setTeamId(unexistingTeamId);

    try {
      playerDao.persist(player);
      fail("El test debió fallar ya que no existe el equipo");
    } catch (IllegalArgumentException iae) {
      assertEquals("No existe un equipo con id " + unexistingTeamId, iae.getMessage());
    }
  }
예제 #2
0
  @Test
  public void shouldPersistAPlayer() {
    final Player player = new Player();
    player.setAge(22);
    player.setCountry("Italia");
    player.setGoals(3);
    player.setName("Nuevo jugador");
    player.setTeamId(5000);

    int newPlayerId = playerDao.persist(player);

    final Player playerFromDB = playerDao.getById(newPlayerId, player.getTeamId());
    assertNotNull(playerFromDB);
    assertEquals(player.getAge(), playerFromDB.getAge());
    assertEquals(player.getCountry(), playerFromDB.getCountry());
    assertEquals(player.getGoals(), playerFromDB.getGoals());
    assertEquals(player.getName(), playerFromDB.getName());
    assertEquals(player.getTeamId(), playerFromDB.getTeamId());

    deletePlayerAndValidateDeletion(playerFromDB);
  }