@Before public void setUp() throws Exception { context.setImposteriser(ClassImposteriser.INSTANCE); beanFactory = context.mock(BeanFactory.class); BeanFactoryExpectationsFactory bfef = new BeanFactoryExpectationsFactory(context, beanFactory); bfef.allowingBeanFactoryGetBean(ContextIdNames.SEO_URL_BUILDER, SeoUrlBuilderImpl.class); geography = context.mock(Geography.class); moneyFormatter = context.mock(MoneyFormatter.class); storeThemeMessageSource = context.mock(StoreThemeMessageSource.class); contextFactory = new EmailContextFactoryImpl(); contextFactory.setGeography(geography); contextFactory.setMoneyFormatter(moneyFormatter); contextFactory.setStoreThemeMessageSource(storeThemeMessageSource); store = new StoreImpl(); store.setCode("store"); emailProperties = new EmailPropertiesImpl(); }
/** * 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); }