Commit ccfcb936 authored by Karel Frajták's avatar Karel Frajták

restart 2

parent e62cf698
import cz.cvut.eshop.shop.Customer;
import cz.cvut.eshop.shop.DiscountedItem;
import cz.cvut.eshop.shop.Order;
import cz.cvut.eshop.shop.ShoppingCart;
import cz.cvut.eshop.shop.StandardItem;
import java.util.Date;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
public class LoyaltyPointsTest {
@Test
public void willGetLoyaltyPoints() {
// setup
// zakaznik
Customer customer = new Customer(0);
ShoppingCart cart = new ShoppingCart();
cart.addItem(new StandardItem(0, "", 0, "", 7));
cart.addItem(new StandardItem(0, "", 0, "", 3));
cart.addItem(new DiscountedItem(0, "", 0, "", 0, new Date(), new Date()));
// objednavka
Order order = new Order(cart);
// act
order.setCustomer(customer);
order.create();
// assert
//assertEquals(10, customer.getLoyaltyPoints());
assertThat(customer.getLoyaltyPoints()).isEqualTo(10);
}
// For certain number of loyalty points the customer gets a discount for one
// purchase (particular amount, which will be decreased from total price)
@Test
public void willGetDiscountForLoyaltyPoints()
{
// setup
int loyaltyPoints = 12;
// zakaznik
Customer customer = new Customer(loyaltyPoints);
// act
ShoppingCart cart = new ShoppingCart();
cart.addItem(new StandardItem(0, "", 10, "", 0));
cart.addItem(new StandardItem(0, "", 20, "", 0));
// objednavka
Order order = new Order(cart);
// act
order.setCustomer(customer);
order.create();
// mezi-assert
assertEquals(30.0, order.getTotalAmount(), 0.0);
order.applyDiscount();
// assert
// 1 bod = 0.2 sleva
assertEquals(30 - loyaltyPoints * .2, order.getTotalAmount(), 0.00001);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment