WorldpayAPMPaymentInfoPopulator implements Populator<AbstractOrderModel, AbstractOrderData> { @Override public void populate(final AbstractOrderModel source, final AbstractOrderData target) throws ConversionException { final PaymentInfoModel paymentInfoModel = source.getPaymentInfo(); if (isAPM(paymentInfoModel)) { final WorldpayAPMPaymentInfoModel worldpayAPMPaymentInfoModel = (WorldpayAPMPaymentInfoModel) paymentInfoModel; final WorldpayAPMConfigurationModel worldpayAPMConfigurationModel = worldpayAPMPaymentInfoModel.getApmConfiguration(); if (worldpayAPMConfigurationModel != null) { final WorldpayAPMPaymentInfoData worldpayAPMPaymentInfoData = new WorldpayAPMPaymentInfoData(); worldpayAPMPaymentInfoData.setName(worldpayAPMConfigurationModel.getName()); target.setWorldpayAPMPaymentInfo(worldpayAPMPaymentInfoData); } } }  @Override void populate(final AbstractOrderModel source, final AbstractOrderData target);  }
@Test public void populateShouldNotSetApmNameIfNoApm() { when(abstractOrderModelMock.getPaymentInfo()).thenReturn(worldpayAPMPaymentInfoModelMock); when(worldpayAPMPaymentInfoModelMock.getApmConfiguration()).thenReturn(null); testObj.populate(abstractOrderModelMock, abstractOrderDataMock); verify(worldpayAPMPaymentInfoModelMock).getApmConfiguration(); verify(worldpayAPMPaymentInfoDataMock, never()).setName(anyString()); }
@Test public void populateShouldSetApmNameIfApmIsPresent() { when(abstractOrderModelMock.getPaymentInfo()).thenReturn(worldpayAPMPaymentInfoModelMock); when(worldpayAPMPaymentInfoModelMock.getApmConfiguration()).thenReturn(worldpayAPMConfigurationModelMock); when(worldpayAPMConfigurationModelMock.getName()).thenReturn(APM_NAME); testObj.populate(abstractOrderModelMock, abstractOrderDataMock); verify(worldpayAPMPaymentInfoModelMock).getApmConfiguration(); verify(abstractOrderDataMock).setWorldpayAPMPaymentInfo(any(WorldpayAPMPaymentInfoData.class)); }