DefaultAmountCalculationStrategy implements AmountCalculationStrategy { BigDecimal calculateDelivery(final CustomerOrderDelivery orderDelivery) { if (orderDelivery != null && orderDelivery.getPrice() != null) { return orderDelivery.getPrice().setScale(Constants.MONEY_SCALE, BigDecimal.ROUND_HALF_UP); } return Total.ZERO; } DefaultAmountCalculationStrategy(final TaxProvider taxProvider,
                                            final DeliveryCostCalculationStrategy deliveryCostCalculationStrategy,
                                            final PromotionContextFactory promotionContextFactory,
                                            final CustomerService customerService,
                                            final ShopService shopService); @Override Total calculate(final MutableShoppingCart cart); @Override Total calculate(final CustomerOrder order, final CustomerOrderDelivery orderDelivery); @Override Total calculate(final CustomerOrder order);  }
@Test public void testCalculateDeliveryNull() throws Exception { final TaxProvider taxProvider = context.mock(TaxProvider.class, "taxProvider"); final DeliveryCostCalculationStrategy deliveryCostCalculationStrategy = context.mock(DeliveryCostCalculationStrategy.class, "deliveryCost"); final PromotionContextFactory promotionContextFactory = context.mock(PromotionContextFactory.class, "promotion"); final CustomerService customerService = context.mock(CustomerService.class, "customerService"); final ShopService shopService = context.mock(ShopService.class, "shopService"); final BigDecimal delivery = new DefaultAmountCalculationStrategy(taxProvider, deliveryCostCalculationStrategy, promotionContextFactory, customerService, shopService).calculateDelivery(null); assertEquals("0.00", delivery.toPlainString()); }
@Test public void testCalculateDeliveryPriceNull() throws Exception { final TaxProvider taxProvider = context.mock(TaxProvider.class, "taxProvider"); final DeliveryCostCalculationStrategy deliveryCostCalculationStrategy = context.mock(DeliveryCostCalculationStrategy.class, "deliveryCost"); final CustomerOrderDelivery orderDelivery = context.mock(CustomerOrderDelivery.class, "orderDelivery"); final PromotionContextFactory promotionContextFactory = context.mock(PromotionContextFactory.class, "promotion"); final CustomerService customerService = context.mock(CustomerService.class, "customerService"); final ShopService shopService = context.mock(ShopService.class, "shopService"); context.checking(new Expectations() {{ oneOf(orderDelivery).getPrice(); will(returnValue(null)); }}); final BigDecimal delivery = new DefaultAmountCalculationStrategy(taxProvider, deliveryCostCalculationStrategy, promotionContextFactory, customerService, shopService).calculateDelivery(orderDelivery); assertEquals("0.00", delivery.toPlainString()); }
@Test public void testCalculateDeliveryPrice() throws Exception { final TaxProvider taxProvider = context.mock(TaxProvider.class, "taxProvider"); final DeliveryCostCalculationStrategy deliveryCostCalculationStrategy = context.mock(DeliveryCostCalculationStrategy.class, "deliveryCost"); final CustomerOrderDelivery orderDelivery = context.mock(CustomerOrderDelivery.class, "orderDelivery"); final PromotionContextFactory promotionContextFactory = context.mock(PromotionContextFactory.class, "promotion"); final CustomerService customerService = context.mock(CustomerService.class, "customerService"); final ShopService shopService = context.mock(ShopService.class, "shopService"); context.checking(new Expectations() {{ allowing(orderDelivery).getPrice(); will(returnValue(new BigDecimal("9.99"))); }}); final BigDecimal delivery = new DefaultAmountCalculationStrategy(taxProvider, deliveryCostCalculationStrategy, promotionContextFactory, customerService, shopService).calculateDelivery(orderDelivery); assertEquals("9.99", delivery.toPlainString()); }