WorldpayAuthorizationResultPopulator implements Populator<DirectAuthoriseServiceResponse, AuthorizationResult> { @Override public void populate(final DirectAuthoriseServiceResponse source, final AuthorizationResult target) throws ConversionException { final PaymentReply paymentReply = source.getPaymentReply(); if (paymentReply == null) { LOG.warn("No PaymentReply in response from worldpay"); final ErrorDetail errorDetail = source.getErrorDetail(); if (errorDetail != null) { LOG.error("Error message from Worldpay: " + errorDetail.getMessage()); } worldpayAuthorisationResultService.setAuthoriseResultAsError(target); } else { worldpayAuthorisationResultService.setAuthoriseResultByTransactionStatus(target, paymentReply.getAuthStatus(), source.getOrderCode()); } }  @Override void populate(final DirectAuthoriseServiceResponse source, final AuthorizationResult target); @Required void setWorldpayAuthorisationResultService(final WorldpayAuthorisationResultService worldpayAuthorisationResultService);  }
@Test public void populateShouldSetAcceptedAndSuccessfulWhenDirectAuthoriseServiceResponseAuthorised() { when(paymentReplyMock.getAuthStatus()).thenReturn(AUTHORISED); final AuthorizationResult result = new AuthorizationResult(); testObj.populate(directAuthoriseServiceResponseMock, result); verify(worldpayAuthorisationResultServiceMock).setAuthoriseResultByTransactionStatus(result, AUTHORISED, ORDER_CODE); }
@Test public void populateShouldSetRejectedAndUnknownCodeWhenDirectAuthoriseServiceResponseNotAuthorised() { when(paymentReplyMock.getAuthStatus()).thenReturn(REFUSED); final AuthorizationResult result = new AuthorizationResult(); testObj.populate(directAuthoriseServiceResponseMock, result); verify(worldpayAuthorisationResultServiceMock).setAuthoriseResultByTransactionStatus(result, REFUSED, ORDER_CODE); }
@Test public void populateShouldSetErrorAndUGeneralSystemErrorWhenDirectAuthoriseServiceResponseError() { when(paymentReplyMock.getAuthStatus()).thenReturn(ERROR); final AuthorizationResult result = new AuthorizationResult(); testObj.populate(directAuthoriseServiceResponseMock, result); verify(worldpayAuthorisationResultServiceMock).setAuthoriseResultByTransactionStatus(result, ERROR, ORDER_CODE); }
@Test public void populateShouldSetErrorAndGeneralSystemErrorWhenDirectAuthoriseServiceResponseHasNoPaymentReply() { when(directAuthoriseServiceResponseMock.getPaymentReply()).thenReturn(null); when(directAuthoriseServiceResponseMock.getErrorDetail()).thenReturn(errorDetailMock); when(errorDetailMock.getMessage()).thenReturn(ERROR_MESSAGE); final AuthorizationResult result = new AuthorizationResult(); testObj.populate(directAuthoriseServiceResponseMock, result); verify(directAuthoriseServiceResponseMock).getErrorDetail(); verify(worldpayAuthorisationResultServiceMock).setAuthoriseResultAsError(result); }