DefaultWorldpayCartFacade implements WorldpayCartFacade { @Override public void setBillingAddressFromPaymentInfo() { final CartModel sessionCart = cartService.getSessionCart(); if (sessionCart.getPaymentAddress() == null) { sessionCart.setPaymentAddress(sessionCart.getPaymentInfo().getBillingAddress()); cartService.saveOrder(sessionCart); } }  @Override void resetDeclineCodeAndShopperBankOnCart(final String shopperBankCode); @Override void setBillingAddressFromPaymentInfo(); @Required void setWorldpayCartService(final WorldpayCartService worldpayCartService); @Required void setCartService(final CartService cartService);  }
@Test public void shouldSetBillingAddressFromPaymentInfoWhenPaymentAddressIsNull() { when(cartServiceMock.getSessionCart()).thenReturn(cartModelMock); when(cartModelMock.getPaymentAddress()).thenReturn(null); when(cartModelMock.getPaymentInfo()).thenReturn(paymentInfoModelMock); when(paymentInfoModelMock.getBillingAddress()).thenReturn(addressModelMock); testObj.setBillingAddressFromPaymentInfo(); verify(cartModelMock).setPaymentAddress(addressModelMock); verify(cartServiceMock).saveOrder(cartModelMock); }
@Test public void shouldNotSetPaymentAddressWhenIsNotNull() { when(cartServiceMock.getSessionCart()).thenReturn(cartModelMock); when(cartModelMock.getPaymentAddress()).thenReturn(addressModelMock); testObj.setBillingAddressFromPaymentInfo(); verify(cartModelMock, never()).setPaymentAddress(addressModelMock); verify(cartServiceMock, never()).saveOrder(cartModelMock); }