package com.guillermo.services;

import junit.framework.TestCase;

public class ShoppingCartTest extends TestCase {

	ShoppingCartSpec sc;
	Item[] items = {new Item("item1", 2.0), new Item("item2",3.5), new Item("item3", 1.7)};
	
	protected void setUp() throws Exception {
		super.setUp();
		sc = new ShoppingCart();
	}

	public void testAddItem() {
		assertEquals(0, sc.getQty());
		
		sc.addItem(items[0]);
		
		assertEquals(1, sc.getItems().size());
		assertTrue(sc.getItems().contains(items[0]));
	};

	public void testUpdateItemWithPositive() {
		sc.addItem(items[0]);
		sc.updateItem(items[0], 5);
		
		assertEquals(5, sc.getQty());
	};

	public void testUdpateItemWithZero() {
		sc.addItem(items[0]);
		sc.updateItem(items[0], 0);
		
		assertEquals(0, sc.getQty());
	};
	
	public void testGetItems() {
		sc.addItem(items[0]);
		sc.addItem(items[1]);
		sc.addItem(items[2]);
		
		assertEquals(3, sc.getItems().size());
	};

	public void testGetQty() {
		sc.addItem(items[1]);
		sc.updateItem(items[1], 23);
		
		assertEquals(23, sc.getQty());
	};

	public void testClear() {
		sc.addItem(items[0]);
		sc.addItem(items[1]);
		sc.addItem(items[2]);
		
		sc.clear();
		
		assertTrue(sc.getItems().isEmpty());
	};

	public void testGetTotal() {
		sc.addItem(items[0]);
		sc.addItem(items[1]);
		sc.updateItem(items[0], 2);
		sc.updateItem(items[1], 2);
		
		assertEquals(11.0, sc.getTotal());
	};

	public void testPay() {
		fail("not implemented");
	};
}
