@Test public void whenPreviousCallResultIsFailed_andCallReturnsValid_callResultIsReturned() throws Exception { when(taxWebserviceCallResultRepository.findSuccessfulByTaxCalculation(taxCalculation)).thenReturn(null); when(taxServiceCallResultCallable.call()).thenReturn(null); TaxWebserviceCallResult actualTaxWebserviceCallResult = taxPaymentWebServiceFacade.callTaxService(taxCalculation, taxServiceCallResultCallable); assertThat(actualTaxWebserviceCallResult.isSuccessfulResponse()).isTrue(); }
public TaxWebserviceCallResult callTaxService(TaxCalculation taxCalculation, Callable<Void> callable) throws Exception { TaxWebserviceCallResult previousResult = taxWebserviceCallResultRepository.findSuccessfulByTaxCalculation(taxCalculation); if (previousResult != null) { return previousResult; } try { callable.call(); TaxWebserviceCallResult successTaxWebserviceCallResult = TaxWebserviceCallResult.callSucceeded(taxCalculation); saveTaxServiceCallResult(successTaxWebserviceCallResult); return successTaxWebserviceCallResult; } catch (TaxWebServiceNonFatalException e) { TaxWebserviceCallResult failedTaxWebserviceCallResult = TaxWebserviceCallResult.callFailed(taxCalculation, e); saveTaxServiceCallResult(failedTaxWebserviceCallResult); throw e; } }
TaxPaymentWebServiceFacade { public TaxWebserviceCallResult callTaxService(TaxCalculation taxCalculation, Callable<Void> callable) throws Exception { TaxWebserviceCallResult previousResult = taxWebserviceCallResultRepository.findSuccessfulByTaxCalculation(taxCalculation); if (previousResult != null) { return previousResult; } try { callable.call(); TaxWebserviceCallResult successTaxWebserviceCallResult = TaxWebserviceCallResult.callSucceeded(taxCalculation); saveTaxServiceCallResult(successTaxWebserviceCallResult); return successTaxWebserviceCallResult; } catch (TaxWebServiceNonFatalException e) { TaxWebserviceCallResult failedTaxWebserviceCallResult = TaxWebserviceCallResult.callFailed(taxCalculation, e); saveTaxServiceCallResult(failedTaxWebserviceCallResult); throw e; } } }
TaxPaymentWebServiceFacade { public TaxWebserviceCallResult callTaxService(TaxCalculation taxCalculation, Callable<Void> callable) throws Exception { TaxWebserviceCallResult previousResult = taxWebserviceCallResultRepository.findSuccessfulByTaxCalculation(taxCalculation); if (previousResult != null) { return previousResult; } try { callable.call(); TaxWebserviceCallResult successTaxWebserviceCallResult = TaxWebserviceCallResult.callSucceeded(taxCalculation); saveTaxServiceCallResult(successTaxWebserviceCallResult); return successTaxWebserviceCallResult; } catch (TaxWebServiceNonFatalException e) { TaxWebserviceCallResult failedTaxWebserviceCallResult = TaxWebserviceCallResult.callFailed(taxCalculation, e); saveTaxServiceCallResult(failedTaxWebserviceCallResult); throw e; } }  }
TaxPaymentWebServiceFacade { public TaxWebserviceCallResult callTaxService(TaxCalculation taxCalculation, Callable<Void> callable) throws Exception { TaxWebserviceCallResult previousResult = taxWebserviceCallResultRepository.findSuccessfulByTaxCalculation(taxCalculation); if (previousResult != null) { return previousResult; } try { callable.call(); TaxWebserviceCallResult successTaxWebserviceCallResult = TaxWebserviceCallResult.callSucceeded(taxCalculation); saveTaxServiceCallResult(successTaxWebserviceCallResult); return successTaxWebserviceCallResult; } catch (TaxWebServiceNonFatalException e) { TaxWebserviceCallResult failedTaxWebserviceCallResult = TaxWebserviceCallResult.callFailed(taxCalculation, e); saveTaxServiceCallResult(failedTaxWebserviceCallResult); throw e; } }  TaxWebserviceCallResult callTaxService(TaxCalculation taxCalculation, Callable<Void> callable); }
TaxPaymentWebServiceFacade { public TaxWebserviceCallResult callTaxService(TaxCalculation taxCalculation, Callable<Void> callable) throws Exception { TaxWebserviceCallResult previousResult = taxWebserviceCallResultRepository.findSuccessfulByTaxCalculation(taxCalculation); if (previousResult != null) { return previousResult; } try { callable.call(); TaxWebserviceCallResult successTaxWebserviceCallResult = TaxWebserviceCallResult.callSucceeded(taxCalculation); saveTaxServiceCallResult(successTaxWebserviceCallResult); return successTaxWebserviceCallResult; } catch (TaxWebServiceNonFatalException e) { TaxWebserviceCallResult failedTaxWebserviceCallResult = TaxWebserviceCallResult.callFailed(taxCalculation, e); saveTaxServiceCallResult(failedTaxWebserviceCallResult); throw e; } }  TaxWebserviceCallResult callTaxService(TaxCalculation taxCalculation, Callable<Void> callable);  }