DefaultWorldpayPaymentInfoService implements WorldpayPaymentInfoService { @Override public Optional<CreditCardPaymentInfoModel> updateCreditCardPaymentInfo(final CartModel cartModel, final UpdateTokenServiceRequest updateTokenServiceRequest) { final String paymentTokenId = updateTokenServiceRequest.getUpdateTokenRequest().getPaymentTokenId(); final CreditCardPaymentInfoModel matchingTokenisedCard = findMatchingTokenisedCard(cartModel.getUser(), paymentTokenId); if (matchingTokenisedCard != null) { final CardDetails cardDetails = updateTokenServiceRequest.getUpdateTokenRequest().getCardDetails(); matchingTokenisedCard.setCcOwner(cardDetails.getCardHolderName()); matchingTokenisedCard.setValidToMonth(cardDetails.getExpiryDate().getMonth()); matchingTokenisedCard.setValidToYear(cardDetails.getExpiryDate().getYear()); modelService.save(matchingTokenisedCard); return Optional.of(matchingTokenisedCard); } return Optional.empty(); } 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 shouldUpdateCreditCardPaymentInfo() { when(updateTokenServiceRequestMock.getUpdateTokenRequest().getCardDetails()).thenReturn(cardDetailsMock); when(updateTokenServiceRequestMock.getUpdateTokenRequest().getPaymentTokenId()).thenReturn(PAYMENT_TOKEN_ID); testObj.updateCreditCardPaymentInfo(cartModelMock, updateTokenServiceRequestMock); verify(savedPaymentInfoMock).setValidToMonth(CARD_DETAILS_EXPIRY_MONTH); verify(savedPaymentInfoMock).setValidToYear(CARD_DETAILS_EXPIRY_YEAR); verify(savedPaymentInfoMock).setCcOwner(CARD_DETAILS_HOLDER_NAME); verify(modelServiceMock).save(savedPaymentInfoMock); verify(modelServiceMock, never()).save(paymentInfo1Mock); }