PresentationEmployeeRepository { public List<EmployeeTo> getEmployees(int page, int pageSize) { TypedQuery<EmployeeTo> employees = entityManager.createQuery(GET_EMPLOYEES_TOTAL_TAX_QUERY, EmployeeTo.class); employees.setFirstResult(page * pageSize); employees.setMaxResults(pageSize); return employees.getResultList(); }  EmployeeTo getEmployee(long id); List<EmployeeTo> getEmployees(int page, int pageSize); long getEmployeeCount(); void setEntityManager(EntityManager entityManager); static final String GET_EMPLOYEE_COUNT_QUERY; static final String GET_EMPLOYEE_DETAIL_QUERY; static final String GET_EMPLOYEES_TOTAL_TAX_QUERY; }
@Test public void givenEmployeeWithError_whenGetEmployees_employeeWithErrorIsReturned() { Employee first = new EmployeeTestBuilder().build(); MonthlyTaxForEmployee monthlyTax = new MonthlyTaxForEmployeeTestBuilder() .withEmployee(first) .withLastErrorMessage("BOOM!!!") .build(); entityManager.persist(first); entityManager.persist(monthlyTax); entityManager.flush(); EmployeeTo employeeTo = presentationEmployeeRepository.getEmployees(0, 1).get(0); assertThat(employeeTo.getErrorCount()).isEqualTo(1L); }
@Test public void givenEmployeeWithNoError_whenGetEmployees_employeeWithNoErrorIsReturned() { Employee first = new EmployeeTestBuilder().build(); MonthlyTaxForEmployee monthlyTax = new MonthlyTaxForEmployeeTestBuilder() .withEmployee(first) .build(); entityManager.persist(first); entityManager.persist(monthlyTax); entityManager.flush(); EmployeeTo employeeTo = presentationEmployeeRepository.getEmployees(0, 1).get(0); assertThat(employeeTo.getErrorCount()).isEqualTo(0L); }