@Test public void testInitialPriceWithApplesAndBreadOffer() { double v = 0; for (Item.Type itemType : content.keySet()) v += Item.getInstance(itemType).getUnitPrice() * content.get(itemType); PriceCalculator priceCalculator = new PriceCalculatorImpl(new ApplesOffer(), new BreadOffer()); assertEquals(v, priceCalculator.getInitialPrice(basket), PRICE_TOLERANCE); }
@Test public void testDiscountWithBreadOffer() { Offer breadOffer = new BreadOffer(); PriceCalculator priceCalculator = new PriceCalculatorImpl(new BreadOffer()); double discount = priceCalculator .getDiscounts(basket) .entrySet() .stream() .collect(Collectors.summingDouble(Entry::getValue)); assertEquals(breadOffer.getDiscount(basket), discount, PRICE_TOLERANCE); }
@Test public void testDiscountWithoutOffer() { PriceCalculator priceCalculator = new PriceCalculatorImpl(); assertTrue(priceCalculator.getDiscounts(basket).isEmpty()); }