@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"); }
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(); }
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(); } }
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(); }  }
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); }
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);  }