TaxWebserviceCallResultRepository extends AbstractRepository<TaxWebserviceCallResult> { public TaxWebserviceCallResult findSuccessfulByTaxCalculation(TaxCalculation taxCalculation) { TypedQuery<TaxWebserviceCallResult> byTaxCalculation = entityManager.createNamedQuery(TaxWebserviceCallResult.FIND_SUCCESSFUL_BY_TAXCALCULATION, TaxWebserviceCallResult.class); byTaxCalculation.setParameter("taxCalculationId", taxCalculation.getId()); byTaxCalculation.setMaxResults(1); try { return byTaxCalculation.getSingleResult(); } catch (NoResultException e) { return null; } }  List<TaxWebserviceCallResult> findByTaxCalculation(TaxCalculation taxCalculation); TaxWebserviceCallResult findSuccessfulByTaxCalculation(TaxCalculation taxCalculation);  }
@Test public void testFindSuccessfulByTaxCalculation_returnsSuccessful() { TaxWebserviceCallResult successfulByTaxCalculation = taxWebserviceCallResultRepository.findSuccessfulByTaxCalculation(january); assertThat(successfulByTaxCalculation).isEqualTo(januaryTry2); }
@Test public void testFindSuccessfulByTaxCalculation_returnsNullWhenNoCall() { TaxCalculation march = new TaxCalculationTestBuilder() .withEmployee(employee) .withMonth(3) .withTax(10.0) .build(); ; taxCalculationRepository.save(march); TaxWebserviceCallResult successfulByTaxCalculation = taxWebserviceCallResultRepository.findSuccessfulByTaxCalculation(march); assertThat(successfulByTaxCalculation).isNull(); }