package bookStore;
public interface PricingService {
double getPrice(BookItem item);
double getDiscount(double price);
double calculateTax(double amount);
}
package bookStore;
public class BookItem {
private String isbn;
private String title;
private int quantity;
public BookItem(String isbn, String title, int quantity) {
[Link] = isbn;
[Link] = title;
[Link] = quantity;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
[Link] = isbn;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
[Link] = title;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
[Link] = quantity;
}
}
package bookStore;
import [Link];
public class OrderCart {
private PricingService pricingService;
private List<BookItem> items;
public OrderCart(PricingService pricingService, List<BookItem> items) {
[Link] = pricingService;
[Link] = items;
}
public double getTotalBill() {
double totalAmount = 0.0;
for (BookItem item : items) {
double price = [Link](item);
double discount = [Link](price);
totalAmount += (price - discount) * [Link]();
}
double tax = [Link](totalAmount);
return totalAmount + tax;
}
1. Test the getTotalBill Method:
Your task is to write a unit test for the getTotalBill method in the OrderCart class.
Use Mockito to mock the PricingService interface and simulate different scenarios.
2. Mock the PricingService Interface:
- Mock the getPrice method to return specific prices for each book in the cart.
- Mock the getDiscount method to apply a discount to the price if applicable.
- Mock the calculateTax method to add tax on the total bill amount.
3. Price-Based Discount:
- If the book price is below $10: No discount is applied.
- If the book price is between $10 and $20: A discount of 5% is applied to the book price.
- If the book price is $20 or above: A discount of 10% is applied to the book price.
4. Write a test case using Mockito's verify method to ensure that the getDiscount method is only called
for items that meet the discount rule criteria. According to the rule:
- No discount should be applied for books priced below $10, so getDiscount should not be called
for these items.
- getDiscount should be called for items priced at $10 or above
Submit only [Link] file