WorldpayAbstractOrderPopulator implements Populator<AbstractOrderModel, AbstractOrderData> { @Override public void populate(final AbstractOrderModel source, final AbstractOrderData target) throws ConversionException { target.setWorldpayOrderCode(source.getWorldpayOrderCode()); target.setWorldpayDeclineCode(source.getWorldpayDeclineCode()); final PaymentInfoModel paymentInfo = source.getPaymentInfo(); if (paymentInfo != null && isNotCreditCard(paymentInfo) && paymentInfo.getBillingAddress() != null) { final CCPaymentInfoData ccPaymentInfoData = new CCPaymentInfoData(); ccPaymentInfoData.setBillingAddress(addressConverter.convert(paymentInfo.getBillingAddress())); target.setPaymentInfo(ccPaymentInfoData); } }  @Override void populate(final AbstractOrderModel source, final AbstractOrderData target); @Required void setAddressConverter(final Converter<AddressModel, AddressData> addressConverter);  }
@Test public void populate() { when(abstractOrderModelMock.getWorldpayOrderCode()).thenReturn(WORLDPAY_ORDER_CODE); when(abstractOrderModelMock.getWorldpayDeclineCode()).thenReturn(WORLDPAY_DECLINE_CODE); testObj.populate(abstractOrderModelMock, abstractOrderDataMock); verify(abstractOrderDataMock).setWorldpayOrderCode(WORLDPAY_ORDER_CODE); verify(abstractOrderDataMock).setWorldpayDeclineCode(WORLDPAY_DECLINE_CODE); }
@Test public void populateShouldNotSetTargetWorldpayPaymentInfoWhenSourcePaymentInfoIsNull() throws Exception { when(abstractOrderModelMock.getPaymentInfo()).thenReturn(null); testObj.populate(abstractOrderModelMock, abstractOrderDataMock); verify(abstractOrderDataMock, never()).setPaymentInfo(any(CCPaymentInfoData.class)); }
@Test public void populateShouldSetTargetWorldpayPaymentInfoWhenSourcePaymentInfoIsNotCreditCardPaymentInfo() throws Exception { when(abstractOrderModelMock.getPaymentInfo()).thenReturn(paymentInfoMock); when(paymentInfoMock.getBillingAddress()).thenReturn(addressModelMock); testObj.populate(abstractOrderModelMock, abstractOrderDataMock); verify(addressConverterMock).convert(any(AddressModel.class)); verify(abstractOrderDataMock).setPaymentInfo(any(CCPaymentInfoData.class)); }
@Test public void populateShouldSetTargetWorldpayPaymentInfoWhenSourcePaymentInfoIsCreditCardPaymentInfo() throws Exception { when(abstractOrderModelMock.getPaymentInfo()).thenReturn(creditCardPaymentInfoMock); testObj.populate(abstractOrderModelMock, abstractOrderDataMock); verify(abstractOrderDataMock, never()).setPaymentInfo(any(CCPaymentInfoData.class)); }