Skip to content

Commit cb05433

Browse files
committed
Test for product value object equality and fix contract test
1 parent db9a961 commit cb05433

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/warranty/ContractTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public void TestContractIsSetupCorrectly()
1616
Contract contract = new Contract(100.0, product, new Date(2010, 5, 7), new Date(2010, 5, 8), new Date(2013, 5, 8));
1717

1818
assertNotNull(contract.id);
19-
System.out.println(contract.id);
2019
assertEquals(100.0, contract.purchasePrice);
2120
assertEquals(Contract.Status.PENDING, contract.status);
2221
assertEquals(contract.purchaseDate, new Date(2010, 5, 7));

src/warranty/ProductTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package warranty;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.util.Date;
6+
import java.util.UUID;
7+
8+
import static org.junit.jupiter.api.Assertions.*;
9+
10+
class ProductTest {
11+
12+
// Product is an example of a value object. See https://martinfowler.com/bliki/ValueObject.html for more details
13+
@Test
14+
public void TestProductEquality() {
15+
// A value object must be created whole
16+
Product product = new Product("dishwasher", "OEUOEU23", "Whirlpool", "7DP840CWDB0");
17+
18+
// Demonstrate equality by property - uses custom "equals" method in this example
19+
assertEquals(new Product("dishwasher", "OEUOEU23", "Whirlpool", "7DP840CWDB0"), product);
20+
}
21+
// Product is an example of a value object. See https://martinfowler.com/bliki/ValueObject.html for more details
22+
@Test
23+
public void TestProductInequality() {
24+
Product product = new Product("dishwasher", "OEUOEU23", "Whirlpool", "7DP840CWDB0");
25+
26+
// Demonstrate equality by property - uses custom "equals" method in this example
27+
assertNotEquals(new Product("stove", "OEUOEU23", "Whirlpool", "7DP840CWDB0"), product);
28+
assertNotEquals(new Product("dishwasher", "BEUOEU23", "Whirlpool", "7DP840CWDB0"), product);
29+
assertNotEquals(new Product("dishwasher", "OEUOEU23", "Maytag", "7DP840CWDB0"), product);
30+
assertNotEquals(new Product("dishwasher", "OEUOEU23", "Whirlpool", "9999999"), product);
31+
}
32+
}

0 commit comments

Comments
 (0)