### Question:
Discount extends CatalogItem { public Double processDiscount(Double currentPrice, Double originItemsPrice) { if (!isEligible(originItemsPrice)){ return currentPrice; } switch (type) { case DISCOUNT_RATE: currentPrice = currentPrice - originItemsPrice * discountValue / 100; break; case ORDER_DISCOUNT_AMOUNT: currentPrice -= discountValue; break; case SHIPPING_FEE_DISCOUNT_AMOUNT: currentPrice -= discountValue; } return currentPrice; } Discount();  Discount(Long id);  Discount(String name, String description, ApplicableTo applicableTo, Type type, Trigger triggerRule, String voucherCode, Double discountValue, Double triggerValue, Integer usesPerCustomer, Boolean uniqueUse, Date startDate, Date endDate, Boolean disabled); boolean isEligible(Double itemsPrice); Double processDiscount(Double currentPrice, Double originItemsPrice); Type getType(); void setType(Type type); Trigger getTrigger(); void setTrigger(Trigger triggerRule); String getVoucherCode(); void setVoucherCode(String voucherCode); List<SKU> getSkus(); void setSkus(List<SKU> skus); List<Product> getProducts(); void setProducts(List<Product> products); Integer getUsesPerCustomer(); void setUsesPerCustomer(Integer usesPerCustomer); Boolean getUniqueUse(); void setUniqueUse(Boolean uniqueUse); Trigger getTriggerRule(); void setTriggerRule(Trigger triggerRule); ApplicableTo getApplicableTo(); void setApplicableTo(ApplicableTo applicableTo); Double getDiscountValue(); void setDiscountValue(Double discountValue); Boolean getRateType(); @Override boolean equals(Object o); @Override int hashCode();  }### Answer:
@Test public void processAmountDiscountWithRate() throws Exception { Discount discount = new Discount("discount1", "a discount", ORDER, DISCOUNT_RATE, AMOUNT, null,10.0, 2.0, 1, true,null,null, false); assertThat(discount.processDiscount(10.0,10.0)).isEqualTo(9); }
@Test public void processAmountDiscountWithRate_andCurrentPriceDifferentFromOriginalPrice() throws Exception { Discount discount = new Discount("discount1", "a discount", ORDER, DISCOUNT_RATE, AMOUNT, null,10.0, 2.0, 1, true,null,null, false); assertThat(discount.processDiscount(10.0,20.0)).isEqualTo(8); }
@Test public void processAmountDiscountWithDiscountValue() throws Exception { Discount discount = new Discount("discount1", "a discount", ORDER, ORDER_DISCOUNT_AMOUNT, AMOUNT, null,5.0, 2.0, 1, true,null,null, false); assertThat(discount.processDiscount(10.0,10.0)).isEqualTo(5); }
@Test public void processShippingDiscount() throws Exception { Discount discount = new Discount("discount1", "a discount", ORDER, SHIPPING_FEE_DISCOUNT_AMOUNT, AMOUNT, null,5.0, 2.0, 1, true,null,null, false); assertThat(discount.processDiscount(10.0,10.0)).isEqualTo(5); }