@Test public void computePrice_ShouldThrowEx_whenOrderHasNoItems() { Order order = new Order(); try { orderPriceEngine.computePrice(order); fail("Should have thrown ex"); } catch (IllegalStateException e) { } }
@Override public void computePrice(Order order) { if (CollectionUtils.isEmpty(order.getItems())){ throw new IllegalStateException("Order items list is empty "+order); } Double price = 0.0; for (OrderItem orderItem : order.getItems()){ SKU sku = entityManager.find(SKU.class,(orderItem).getSkuId()); price += (sku.getPrice()*(orderItem).getQuantity()); orderItem.setPrice(sku.getPrice()); } final Double fixedDeliveryFee = orderConfiguration.getFixedDeliveryFee(); price = applyEligibleDiscounts(order, price); if (fixedDeliveryFee != null){ price += fixedDeliveryFee; order.setDeliveryFee(fixedDeliveryFee); } order.setPrice(price); }
PriceEngineImpl implements PriceEngine { @Override public void computePrice(Order order) { if (CollectionUtils.isEmpty(order.getItems())){ throw new IllegalStateException("Order items list is empty "+order); } Double price = 0.0; for (OrderItem orderItem : order.getItems()){ SKU sku = entityManager.find(SKU.class,(orderItem).getSkuId()); price += (sku.getPrice()*(orderItem).getQuantity()); orderItem.setPrice(sku.getPrice()); } final Double fixedDeliveryFee = orderConfiguration.getFixedDeliveryFee(); price = applyEligibleDiscounts(order, price); if (fixedDeliveryFee != null){ price += fixedDeliveryFee; order.setDeliveryFee(fixedDeliveryFee); } order.setPrice(price); } }
PriceEngineImpl implements PriceEngine { @Override public void computePrice(Order order) { if (CollectionUtils.isEmpty(order.getItems())){ throw new IllegalStateException("Order items list is empty "+order); } Double price = 0.0; for (OrderItem orderItem : order.getItems()){ SKU sku = entityManager.find(SKU.class,(orderItem).getSkuId()); price += (sku.getPrice()*(orderItem).getQuantity()); orderItem.setPrice(sku.getPrice()); } final Double fixedDeliveryFee = orderConfiguration.getFixedDeliveryFee(); price = applyEligibleDiscounts(order, price); if (fixedDeliveryFee != null){ price += fixedDeliveryFee; order.setDeliveryFee(fixedDeliveryFee); } order.setPrice(price); } PriceEngineImpl();  PriceEngineImpl(EntityManager entityManager, OrderConfiguration orderConfiguration,
                           OrderFinder orderFinder, DiscountFinder discountFinder); }
PriceEngineImpl implements PriceEngine { @Override public void computePrice(Order order) { if (CollectionUtils.isEmpty(order.getItems())){ throw new IllegalStateException("Order items list is empty "+order); } Double price = 0.0; for (OrderItem orderItem : order.getItems()){ SKU sku = entityManager.find(SKU.class,(orderItem).getSkuId()); price += (sku.getPrice()*(orderItem).getQuantity()); orderItem.setPrice(sku.getPrice()); } final Double fixedDeliveryFee = orderConfiguration.getFixedDeliveryFee(); price = applyEligibleDiscounts(order, price); if (fixedDeliveryFee != null){ price += fixedDeliveryFee; order.setDeliveryFee(fixedDeliveryFee); } order.setPrice(price); } PriceEngineImpl();  PriceEngineImpl(EntityManager entityManager, OrderConfiguration orderConfiguration,
                           OrderFinder orderFinder, DiscountFinder discountFinder); @Override void computePrice(Order order); }
PriceEngineImpl implements PriceEngine { @Override public void computePrice(Order order) { if (CollectionUtils.isEmpty(order.getItems())){ throw new IllegalStateException("Order items list is empty "+order); } Double price = 0.0; for (OrderItem orderItem : order.getItems()){ SKU sku = entityManager.find(SKU.class,(orderItem).getSkuId()); price += (sku.getPrice()*(orderItem).getQuantity()); orderItem.setPrice(sku.getPrice()); } final Double fixedDeliveryFee = orderConfiguration.getFixedDeliveryFee(); price = applyEligibleDiscounts(order, price); if (fixedDeliveryFee != null){ price += fixedDeliveryFee; order.setDeliveryFee(fixedDeliveryFee); } order.setPrice(price); } PriceEngineImpl();  PriceEngineImpl(EntityManager entityManager, OrderConfiguration orderConfiguration,
                           OrderFinder orderFinder, DiscountFinder discountFinder); @Override void computePrice(Order order);  }