/** Check non-null name constraints */
 @Test(expectedExceptions = ConstraintViolationException.class)
 public void nullAbilityNameNotAllowed() {
   Ability ability = new Ability();
   ability.setName(null);
   ability.setDescription("Description");
   abilityDao.create(ability);
 }
  /** Make sure that object is successfully inserted to db and can be removed. */
  @Test()
  public void remove() {
    Ability ability1 = new Ability();
    ability1.setName("Ability1");
    ability1.setDescription("Ability1desc");

    abilityDao.create(ability1);

    Assert.assertNotNull(abilityDao.findById(ability1.getId()));
    abilityDao.remove(ability1);
    Assert.assertNull(abilityDao.findById(ability1.getId()));
  }
  /** Make sure that object is successfully inserted to db and can be updated. */
  @Test()
  public void update() {
    Ability ability1 = new Ability();
    ability1.setName("Ability1");
    ability1.setDescription("Ability1desc");

    abilityDao.create(ability1);

    Ability updatedAbility =
        new Ability(ability1.getId(), "Updated ability", "Updated description");
    abilityDao.edit(updatedAbility);

    Ability updatedDbAbility = abilityDao.findById(updatedAbility.getId());
    Assert.assertEquals(updatedDbAbility.getName(), "Updated ability");
    Assert.assertEquals(updatedDbAbility.getDescription(), "Updated description");
  }
 /** Check name unique constraints */
 @Test(expectedExceptions = PersistenceException.class)
 public void nameIsUnique() {
   Ability ability = new Ability();
   ability.setName("Name");
   ability.setDescription("Description");
   abilityDao.create(ability);
   Ability ability2 = new Ability();
   ability2.setName("Name");
   ability2.setDescription("Description2");
   abilityDao.create(ability2);
 }
  /** Make sure that find object by id work. */
  @Test
  public void findById() {
    Ability ability1 = new Ability();
    ability1.setName("Ability11");
    ability1.setDescription("Ability11desc");

    Ability ability2 = new Ability();
    ability2.setName("Ability22");
    ability2.setDescription("Ability22desc");

    abilityDao.create(ability1);
    abilityDao.create(ability2);

    Ability fromDatabase11 = abilityDao.findById(ability1.getId());
    Assert.assertEquals(fromDatabase11, ability1);
  }
  /** Make sure that the creation of database objects work and can return all ability entries. */
  @Test
  public void findAll() {
    Ability ability1 = new Ability();
    ability1.setName("Ability1");
    ability1.setDescription("Ability1desc");

    Ability ability2 = new Ability();
    ability2.setName("Ability2");
    ability2.setDescription(null);

    abilityDao.create(ability1);
    abilityDao.create(ability2);

    List<Ability> abilities = abilityDao.findAll();

    Assert.assertEquals(2, abilities.size());
    Assert.assertTrue(abilities.contains(ability1));
    Assert.assertTrue(abilities.contains(ability2));
  }