/** Test logging when order shipment method is changed. */
  @Test
  public void testLogOrderShipmentMethodChanged() {
    // Given
    final ShippingServiceLevelImpl serviceLevel = createShippingServiceLevel();

    PhysicalOrderShipment physicalShipment = new PhysicalOrderShipmentImpl();
    physicalShipment.setShippingServiceLevelGuid(serviceLevel.getGuid());

    // Expectations
    context.checking(
        new Expectations() {
          {
            allowing(shippingLevelService).findByGuid(serviceLevel.getGuid());
            will(returnValue(serviceLevel));

            oneOf(order).addOrderEvent(orderEvent);
          }
        });

    // When
    orderEventHelper.logOrderShipmentMethodChanged(order, physicalShipment);

    // Then
    assertTrue(
        "Message should contain shippingServLevel's display name",
        orderEvent.getNote().contains(serviceLevel.getDisplayName(Locale.CANADA, false)));
  }
 /** Ensure logging of order payment capture with gift certificate has correct format. */
 @Test
 public void ensureLoggingOfOrderPaymentCaptureWithGiftCertificateHasCorrectFormat() {
   Order order = createBlankOrderWithLocale();
   orderEventHelper.logOrderPaymentCaptured(order, createGiftCertificateCaptureOrderPayment());
   OrderEvent refundOrderEvent = getSingleOrderEventFromOrder(order);
   String captureEventNote = refundOrderEvent.getNote();
   assertThatNoteIsCapture(captureEventNote);
   assertThatNoteIsForGiftCertificate(captureEventNote);
   assertThatNoteHasFormattedAmount(captureEventNote);
 }
 /** Ensure logging of order payment refund with payment token has correct format. */
 @Test
 public void ensureLoggingOfOrderPaymentRefundWithPaymentTokenHasCorrectFormat() {
   Order order = createBlankOrderWithLocale();
   orderEventHelper.logOrderPaymentRefund(order, createPaymentTokenRefundOrderPayment());
   OrderEvent refundOrderEvent = getSingleOrderEventFromOrder(order);
   String refundEventNote = refundOrderEvent.getNote();
   assertNoteIsRefund(refundEventNote);
   assertThatNoteIsForPaymentToken(refundEventNote);
   assertThatNoteHasFormattedAmount(refundEventNote);
 }
  /**
   * Sets up mock bean factory, sets up OrderEventHelper with mock services, and mocks an Order for
   * testing.
   *
   * @throws Exception the exception
   */
  @Before
  public void setUp() throws Exception {
    orderEvent = new OrderEventImpl();

    BeanFactoryExpectationsFactory bfef = new BeanFactoryExpectationsFactory(context, beanFactory);
    bfef.allowingBeanFactoryGetBean(ContextIdNames.ORDER_EVENT, orderEvent);
    bfef.allowingBeanFactoryGetBean(
        ContextIdNames.EVENT_ORIGINATOR_HELPER, new EventOriginatorHelperImpl());
    bfef.allowingBeanFactoryGetBean(ContextIdNames.EVENT_ORIGINATOR, new EventOriginatorImpl());
    bfef.allowingBeanFactoryGetBean(ContextIdNames.CREDIT_CARD_ENCRYPTER, mockCreditCardEncrypter);
    bfef.allowingBeanFactoryGetBean(ContextIdNames.CARD_ENCRYPTER, mockCreditCardEncrypter);

    context.checking(
        new Expectations() {
          {
            allowing(order).getModifiedBy();
            will(returnValue(scapegoat));
            allowing(order).getLocale();
            will(returnValue(Locale.CANADA));

            allowing(timeService).getCurrentTime();
            will(returnValue(new Date()));

            allowing(moneyFormatter)
                .formatCurrency(with(any(Money.class)), with(any(Locale.class)));
            will(returnValue(TEST_FORMATTED_AMOUNT));
          }
        });

    orderEventHelper = new OrderEventHelperImpl();
    orderEventHelper.setBeanFactory(beanFactory);
    orderEventHelper.setMoneyFormatter(moneyFormatter);
    orderEventHelper.setShippingServiceLevelService(shippingLevelService);
    orderEventHelper.setTimeService(timeService);

    Map<PaymentType, OrderEventPaymentDetailFormatter> formatterMap =
        new HashMap<PaymentType, OrderEventPaymentDetailFormatter>();
    formatterMap.put(PaymentType.CREDITCARD, new OrderEventCreditCardDetailsFormatter());
    formatterMap.put(PaymentType.GIFT_CERTIFICATE, new OrderEventGiftCertificateDetailsFormatter());
    formatterMap.put(PaymentType.PAYMENT_TOKEN, new OrderEventPaymentTokenDetailsFormatter());
    orderEventHelper.setFormatterMap(formatterMap);
  }