001: package org.springunit.framework.samples.jpetstore.domain;
002:
003: import org.springunit.framework.SpringUnitContext;
004: import org.springunit.framework.SpringUnitTest;
005:
006: public class LineItemTest extends SpringUnitTest {
007:
008: /**
009: * Test of the LineItem domain object in the JPetStore sample application.
010: * @author Ted.Velkoff
011: *
012: */
013: public void testConstructorNoArg() throws Exception {
014: LineItem subject = new LineItem();
015: assertEquals(0, subject.getLineNumber());
016: assertEquals(0.0, subject.getTotalPrice());
017: assertEquals(0.0, subject.getUnitPrice());
018: assertNull(subject.getOrder());
019: assertEquals(0, subject.getQuantity());
020: assertNull(subject.getItem());
021: }
022:
023: public void testConstructorTwoArg() throws Exception {
024: int lineNumber = (Integer) getObject("lineNumber");
025: double totalPrice = (Double) getObject("totalPrice");
026: double unitPrice = (Double) getObject("unitPrice");
027: int quantity = (Integer) getObject("quantity");
028: Item item = getObject("item");
029: CartItem cartItem = getObject("cartItem");
030: LineItem subject = new LineItem(lineNumber, cartItem);
031: assertEquals(lineNumber, subject.getLineNumber());
032: assertEquals(totalPrice, subject.getTotalPrice());
033: assertEquals(unitPrice, subject.getUnitPrice());
034: assertNull(subject.getOrder());
035: assertEquals(quantity, subject.getQuantity());
036: assertEquals(item, subject.getItem());
037: }
038:
039: public void testOrder() throws Exception {
040: LineItem subject = getObject("subject");
041: Order order = getObject("order");
042: Order expected = getObject("expected");
043: subject.setOrder(order);
044: Order actual = subject.getOrder();
045: assertEquals(expected, actual);
046: }
047:
048: public void testItem() throws Exception {
049: LineItem subject = getObject("subject");
050: Item item = getObject("item");
051: Item expected = getObject("expected");
052: subject.setItem(expected);
053: Item actual = subject.getItem();
054: assertEquals(expected, actual);
055: }
056:
057: public void testLineNumber() throws Exception {
058: LineItem subject = getObject("subject");
059: int lineNumber = (Integer) getObject("lineNumber");
060: int expected = (Integer) getObject("expected");
061: subject.setLineNumber(lineNumber);
062: int actual = subject.getLineNumber();
063: assertEquals(expected, actual);
064: }
065:
066: public void testQuantityAndUnitPrice() throws Exception {
067: LineItem subject = getObject("subject");
068: int quantity = (Integer) getObject("quantity");
069: double unitPrice = (Double) getObject("unitPrice");
070: int expectedQuantity = (Integer) getObject("expectedQuantity");
071: double expectedUnitPrice = (Double) getObject("expectedUnitPrice");
072: double expectedTotalPrice = (Double) getObject("expectedTotalPrice");
073: subject.setQuantity(quantity);
074: subject.setUnitPrice(unitPrice);
075: int actualQuantity = subject.getQuantity();
076: double actualUnitPrice = subject.getUnitPrice();
077: double actualTotalPrice = subject.getTotalPrice();
078: assertEquals(expectedQuantity, actualQuantity);
079: assertEquals(expectedUnitPrice, actualUnitPrice);
080: assertEquals(expectedTotalPrice, actualTotalPrice);
081: }
082:
083: public void testEqualsSame() throws Exception {
084: LineItem subject = getObject("subject");
085: LineItem other = getObject("other");
086: assertTrue(subject == other);
087: assertTrue(subject.equals(other));
088: }
089:
090: public void testEqualsNotSame() throws Exception {
091: LineItem subject = getObject("subject");
092: LineItem other = getObject("other");
093: assertFalse(subject == other);
094: assertTrue(subject.equals(other));
095: }
096:
097: public void testEqualsTypeMismatch() throws Exception {
098: LineItem subject = getObject("subject");
099: Integer other = getObject("other");
100: assertTrue(!subject.equals(other));
101: }
102:
103: public void testCompareToLessThan() throws Exception {
104: LineItem subject = getObject("subject");
105: LineItem other = getObject("other");
106: assertTrue(subject.compareTo(other) < 0);
107: }
108:
109: public void testCompareToGreaterThan() throws Exception {
110: LineItem subject = getObject("subject");
111: LineItem other = getObject("other");
112: assertTrue(subject.compareTo(other) > 0);
113: }
114:
115: public void testCompareToEquals() throws Exception {
116: LineItem subject = getObject("subject");
117: LineItem other = getObject("other");
118: assertTrue(subject.compareTo(other) == 0);
119: }
120:
121: public void testHashCodeSame() throws Exception {
122: LineItem subject = getObject("subject");
123: LineItem other = getObject("other");
124: assertTrue(subject.hashCode() == other.hashCode());
125: }
126:
127: public void testHashCodeDifferent() throws Exception {
128: LineItem subject = getObject("subject");
129: LineItem other = getObject("other");
130: assertTrue(subject.hashCode() != other.hashCode());
131: }
132:
133: public void testToString() throws Exception {
134: LineItem subject = getObject("subject");
135: String s = subject.toString();
136: }
137:
138: public SpringUnitContext getLineItemTest() {
139: return this .lineItemTest;
140: }
141:
142: public void setLineItemTest(SpringUnitContext lineItemTest) {
143: this .lineItemTest = lineItemTest;
144: }
145:
146: private SpringUnitContext lineItemTest;
147:
148: }
|