0% found this document useful (0 votes)
8 views3 pages

Assignment_bookStore

project on bookstore

Uploaded by

rajmudhiraj903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Assignment_bookStore

project on bookstore

Uploaded by

rajmudhiraj903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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) {


this.isbn = isbn;
this.title = title;
this.quantity = quantity;
}

public String getIsbn() {


return isbn;
}

public void setIsbn(String isbn) {


this.isbn = isbn;
}

public String getTitle() {


return title;
}

public void setTitle(String title) {


this.title = title;
}

public int getQuantity() {


return quantity;
}

public void setQuantity(int quantity) {


this.quantity = quantity;
}

}
package bookStore;

import java.util.List;

public class OrderCart {

private PricingService pricingService;


private List<BookItem> items;

public OrderCart(PricingService pricingService, List<BookItem> items) {


this.pricingService = pricingService;
this.items = items;
}

public double getTotalBill() {


double totalAmount = 0.0;

for (BookItem item : items) {


double price = pricingService.getPrice(item);
double discount = pricingService.getDiscount(price);
totalAmount += (price - discount) * item.getQuantity();
}

double tax = pricingService.calculateTax(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 Test.java file

You might also like