DefaultWorldpayPaymentInfoService implements WorldpayPaymentInfoService { @Override public PaymentInfoModel createPaymentInfoApplePay(final CartModel cartModel, final ApplePayAdditionalAuthInfo applePayAdditionalAuthInfo) { validateParameterNotNull(cartModel, CART_MODEL_CANNOT_BE_NULL); validateParameterNotNull(applePayAdditionalAuthInfo, "ApplePayAdditionalAuthInfo cannot be null"); final ApplePayPaymentInfoModel paymentInfoModel = modelService.create(ApplePayPaymentInfoModel.class); paymentInfoModel.setUser(cartModel.getUser()); paymentInfoModel.setSaved(false); paymentInfoModel.setCode(generateCcPaymentInfoCode(cartModel)); paymentInfoModel.setVersion(applePayAdditionalAuthInfo.getVersion()); paymentInfoModel.setTransactionId(applePayAdditionalAuthInfo.getHeader().getTransactionId()); cartModel.setPaymentInfo(paymentInfoModel); modelService.save(cartModel); return updatePaymentInfo(cartModel, paymentInfoModel); } DefaultWorldpayPaymentInfoService(final ModelService modelService, final EnumerationService enumerationService, final APMConfigurationLookupService apmConfigurationLookupService, final ConfigurationService configurationService, final WorldpayMerchantInfoService worldpayMerchantInfoService); @Override void savePaymentType(final PaymentTransactionModel transactionModel, final String methodCode); @Override void setPaymentInfoModel(final PaymentTransactionModel paymentTransactionModel, final AbstractOrderModel orderModel, final OrderNotificationMessage orderNotificationMessage); @Override void updateAndAttachPaymentInfoModel(final PaymentTransactionModel paymentTransactionModel, final AbstractOrderModel orderModel, final PaymentInfoModel paymentInfoModel); @Override WorldpayAPMPaymentInfoModel createWorldpayApmPaymentInfo(final PaymentTransactionModel paymentTransactionModel); @Override PaymentInfoModel createPaymentInfo(final CartModel cartModel); @Override PaymentInfoModel createPaymentInfoGooglePay(final CartModel cartModel, final GooglePayAdditionalAuthInfo googleAuthInfo); @Override PaymentInfoModel createPaymentInfoApplePay(final CartModel cartModel, final ApplePayAdditionalAuthInfo applePayAdditionalAuthInfo); @Override CreditCardPaymentInfoModel createCreditCardPaymentInfo(final AbstractOrderModel abstractOrderModel, final TokenReply tokenReply, final boolean saveCard, final String merchantId); @Override void setCreditCardType(final CreditCardPaymentInfoModel creditCardPaymentInfoModel, final PaymentReply paymentReply); @Override Optional<CreditCardPaymentInfoModel> updateCreditCardPaymentInfo(final CartModel cartModel, final UpdateTokenServiceRequest updateTokenServiceRequest); @Override void setTransactionIdentifierOnPaymentInfo(final PaymentInfoModel paymentInfoModel, final String transactionIdentifier);  }
@Test public void shouldCreateApplePayPaymentInfoAndSetItAsPaymentInfoOnTheCart() { when(modelServiceMock.create(ApplePayPaymentInfoModel.class)).thenReturn(applePayPaymentInfoModelMock); final ApplePayPaymentInfoModel result = (ApplePayPaymentInfoModel) testObj.createPaymentInfoApplePay(cartModelMock, applePayAdditionalAuthInfoMock); assertThat(result).isEqualTo(applePayPaymentInfoModelMock); verify(applePayPaymentInfoModelMock).setUser(cartModelMock.getUser()); verify(applePayPaymentInfoModelMock).setSaved(false); verify(applePayPaymentInfoModelMock).setCode(startsWith(ORDER_CODE)); verify(applePayPaymentInfoModelMock).setTransactionId(TRANSACTION_ID); verify(applePayPaymentInfoModelMock).setVersion(VERSION); verify(cartModelMock).setPaymentInfo(applePayPaymentInfoModelMock); verify(modelServiceMock).save(cartModelMock); verify(modelServiceMock).save(applePayPaymentInfoModelMock); }