@Test
  public void returnsSamePageIfNoSpecGiven() throws Exception {

    Pageable pageable = new PageRequest(0, 1);

    flushTestUsers();
    assertEquals(userDao.readAll(pageable), userDao.readAll(null, pageable));
  }
  @Test
  public void executesCombinedSpecificationsCorrectly() {

    flushTestUsers();
    Specification<User> spec = where(userHasFirstname("Oliver")).or(userHasLastname("Arrasz"));
    assertThat(userDao.readAll(spec).size(), is(2));
  }
  /** Tests reading all users. */
  @Test
  public void testReadAll() {

    flushTestUsers();

    List<User> reference = Arrays.asList(firstUser, secondUser);
    assertTrue(userDao.readAll().containsAll(reference));
  }
  private Page<User> executeSpecWithSort(Sort sort) {

    flushTestUsers();

    Specification<User> spec = where(userHasFirstname("Oliver")).or(userHasLastname("Matthews"));

    Page<User> result = userDao.readAll(spec, new PageRequest(0, 1, sort));
    assertThat(result.getTotalElements(), is(2L));
    return result;
  }
  @Test
  public void executesCombinedSpecificationsWithPageableCorrectly() {

    flushTestUsers();
    Specification<User> spec = where(userHasFirstname("Oliver")).or(userHasLastname("Arrasz"));

    Page<User> users = userDao.readAll(spec, new PageRequest(0, 1));
    assertThat(users.getSize(), is(1));
    assertThat(users.hasPreviousPage(), is(false));
    assertThat(users.getTotalElements(), is(2L));
  }
  @Test
  public void returnsAllSortedCorrectly() throws Exception {

    flushTestUsers();
    List<User> result = userDao.readAll(new Sort(Order.ASCENDING, "lastname"));
    assertNotNull(result);
    assertThat(result.size(), is(3));
    assertThat(result.get(0), is(secondUser));
    assertThat(result.get(1), is(firstUser));
    assertThat(result.get(2), is(thirdUser));
  }
  @Test
  public void returnsAllAsPageIfNoPageableIsGiven() throws Exception {

    flushTestUsers();
    assertEquals(new PageImpl<User>(userDao.readAll()), userDao.readAll((Pageable) null));
  }
  @Test
  public void returnsSameListIfNoSortIsGiven() throws Exception {

    flushTestUsers();
    assertSameElements(userDao.readAll((Sort) null), userDao.readAll());
  }
  @Test
  public void returnsSameListIfNoSpecGiven() throws Exception {

    flushTestUsers();
    assertSameElements(userDao.readAll(), userDao.readAll((Specification<User>) null));
  }
  @Test
  public void executesSpecificationCorrectly() {

    flushTestUsers();
    assertThat(userDao.readAll(where(userHasFirstname("Oliver"))).size(), is(1));
  }