@Test
  public void executesMethodWithNamedParametersCorrectly() throws Exception {

    firstUser = userDao.save(firstUser);
    secondUser = userDao.save(secondUser);

    assertTrue(
        userDao
            .findByLastnameOrFirstname("Oliver", "Arrasz")
            .containsAll(Arrays.asList(firstUser, secondUser)));
  }
  @Test
  public void savingEmptyCollectionIsNoOp() throws Exception {

    List<User> result = userDao.save(new ArrayList<User>());
    assertNotNull(result);
    assertTrue(result.isEmpty());
  }
  @Test
  public void savingNullCollectionIsNoOp() throws Exception {

    List<User> result = userDao.save((Collection<User>) null);
    assertNotNull(result);
    assertTrue(result.isEmpty());
  }
  @Test
  public void savesCollectionCorrectly() throws Exception {

    List<User> result = userDao.save(Arrays.asList(firstUser, secondUser, thirdUser));
    assertNotNull(result);
    assertThat(result.size(), is(3));
    assertThat(result, hasItems(firstUser, secondUser, thirdUser));
  }
  /** Flushes test users to the database. */
  private void flushTestUsers() {

    firstUser = userDao.save(firstUser);
    secondUser = userDao.save(secondUser);
    thirdUser = userDao.save(thirdUser);

    userDao.flush();

    id = firstUser.getId();

    assertThat(id, is(notNullValue()));
    assertThat(secondUser.getId(), is(notNullValue()));
    assertThat(thirdUser.getId(), is(notNullValue()));

    assertThat(userDao.exists(id), is(true));
    assertThat(userDao.exists(secondUser.getId()), is(true));
    assertThat(userDao.exists(thirdUser.getId()), is(true));
  }
  /** Tests, that the generic dao implements count correctly. */
  @Test
  public void testCountsCorrectly() {

    Long count = userDao.count();

    User user = new User();
    user.setEmailAddress("*****@*****.**");
    userDao.save(user);

    assertTrue(userDao.count().equals(count + 1));
  }
  /** Tests cascading on {@literal merge} operation. */
  @Test
  public void testMergingCascadesCollegueas() {

    firstUser.addColleague(secondUser);
    flushTestUsers();

    firstUser.addColleague(new User("Florian", "Hopf", "*****@*****.**"));
    firstUser = userDao.save(firstUser);

    User reference = userDao.readByPrimaryKey(firstUser.getId());
    Set<User> colleagues = reference.getColleagues();

    assertNotNull(colleagues);
    assertEquals(2, colleagues.size());
  }