01: package org.springunit.framework.samples.jpetstore.domain;
02:
03: import org.springunit.framework.SpringUnitContext;
04: import org.springunit.framework.SpringUnitTest;
05:
06: /**
07: * Test of the CartItem domain object in the JPetStore sample application.
08: * @author Ted.Velkoff
09: *
10: */
11: public class CartItemTest extends SpringUnitTest {
12:
13: public void testConstructor() throws Exception {
14: CartItem subject = getObject("subject");
15: Item item = getObject("item");
16: assertEquals(item, subject.getItem());
17: Double totalPrice = getObject("totalPrice");
18: assertEquals(totalPrice, subject.getTotalPrice());
19: int quantity = (Integer) getObject("quantity");
20: assertEquals(quantity, subject.getQuantity());
21: subject.incrementQuantity();
22: assertEquals(quantity + 1, subject.getQuantity());
23: }
24:
25: public void testInStock() throws Exception {
26: CartItem subject = getObject("subject");
27: boolean inStock = (Boolean) getObject("inStock");
28: boolean expected = (Boolean) getObject("expected");
29: subject.setInStock(inStock);
30: boolean actual = subject.isInStock();
31: assertEquals(expected, actual);
32: }
33:
34: public void testItem() throws Exception {
35: CartItem subject = getObject("subject");
36: subject.incrementQuantity();
37: subject.incrementQuantity();
38: subject.incrementQuantity();
39: double listPrice = (Double) getObject("listPrice");
40: Item item = getObject("item");
41: item.setListPrice(listPrice);
42: subject.setItem(item);
43: double expectedTotalPrice = (Double) getObject("expectedTotalPrice");
44: Item expectedItem = getObject("expectedItem");
45: expectedItem.setListPrice(listPrice);
46: Item actualItem = subject.getItem();
47: assertEquals(expectedItem.getListPrice(), actualItem
48: .getListPrice());
49: assertEquals(expectedTotalPrice, subject.getTotalPrice());
50: }
51:
52: public SpringUnitContext getCartItemTest() {
53: return this .cartItemTest;
54: }
55:
56: public void setCartItemTest(SpringUnitContext cartItemTest) {
57: this .cartItemTest = cartItemTest;
58: }
59:
60: private SpringUnitContext cartItemTest;
61:
62: }
|