Junit And Mockito

package com.lec.test;
public interface Order {
public double getPrice(FoodItem item);
public double tax(double price);
// 10% tax
}

package com.lec.test;
public class FoodItem {
private String menuId;
private String name;
private int quantity;
public FoodItem(String menuId, String name, int quantity) {
this.menuId = menuId;
this.name = name;
this.quantity = quantity;
}
public String getMenuId() {
return menuId;
}
public void setMenuId(String menuId) {
this.menuId = menuId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
}

package com.lec.test;
import java.util.List;
public class OrderCart {
private Order order;
private List<FoodItem> items;
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
public List<FoodItem> getItems() {
return items;
}
public void setItems(List<FoodItem> items) {
this.items = items;
}
public double getTotalPrice(){
double totalAmount = 0.0;
for(FoodItem item:items){
System.out.println(item.getName()+" "+ item.getQuantity());
totalAmount += order.getPrice(item) * item.getQuantity();
}
totalAmount = totalAmount + order.tax(totalAmount);
return totalAmount;
}
}

  1. The code above implement a “McDonald's Ordering System”. Each branch can create its own menu but unfortunately, the price is determined by the head office. (FoodItem class is designed to create a menu but you should use Order interface to get the price of each menu. Also you can ask amount of tax using the same interface)


  1. Implementing the Order Interface is not your task. Your task is to test the “getTotalPrice” method. (Keep in mind, to test “getTotalPrice”, you should ask a price to head office using the Order interface)

  1. Test the “getTotalPrice” method using Mockito