EmployeeRepository extends AbstractRepository<Employee> { public List<Employee> getEmployees(int page, int pageSize) { TypedQuery<Employee> employees = entityManager.createNamedQuery(Employee.GET_ALL, Employee.class); employees.setFirstResult(page * pageSize); employees.setMaxResults(pageSize); return employees.getResultList(); }  List<Employee> getEmployees(int page, int pageSize);  }
@Test public void given30Employees_whenGetEmployeesForFirstPage_thenFirst10EmployeesAreReturned() throws Exception { haveEmployees(30); List<Employee> first10 = employeeRepository.getEmployees(0, 10); assertThat(first10).hasSize(10); assertThat(first10.get(0).getEmail()).isEqualTo("john.smith0@gmail.com"); }
@Test public void givenEmployeesWithoutCalculatedTaxes_whenGetEmployeesForSecondPage_thenSecondPageEmployeesAreReturnedWithTaxZero() { haveEmployees(30); List<Employee> employeesSecondPage = employeeRepository.getEmployees(1, 10); assertThat(employeesSecondPage).hasSize(10); assertThat(employeesSecondPage.get(0).getEmail()).isEqualTo("john.smith10@gmail.com"); }