EmployeeService { public Money getTotalAmountOfPaidTaxes(Employee employee) { return monthlyTaxForEmployeeRepository.findByEmployee(employee) .stream() .filter(monthlyTaxForEmployee -> monthlyTaxForEmployee.hasErrorMessage() == false) .map(MonthlyTaxForEmployee::getTax) .reduce((a, b) -> a.plus(b)) .orElse(Money.zero(CurrencyUnit.EUR)); }  List<Employee> getEmployees(int page, int pageSize); Employee getEmployee(Long employeeId); Money getTotalAmountOfPaidTaxes(Employee employee); List<MonthlyTaxForEmployee> getEmployeeTaxes(Long employeeId); Long getEmployeeCount();  }
@Test public void getTotalAmountOfPaidTaxes() throws Exception { Employee employee = new EmployeeTestBuilder().build(); when(monthlyTaxForEmployeeRepository.findByEmployee(employee)).thenReturn( Arrays.asList( new MonthlyTaxForEmployeeTestBuilder().withHasError(false).withTax(10.0).build(), new MonthlyTaxForEmployeeTestBuilder().withHasError(false).withTax(10.0).build(), new MonthlyTaxForEmployeeTestBuilder().withHasError(true).withTax(10.0).build() ) ); Money totalAmountOfPaidTaxes = employeeService.getTotalAmountOfPaidTaxes(employee); assertThat(totalAmountOfPaidTaxes).isEqualTo(Money.of(CurrencyUnit.EUR, 20.0)); }