Skip to content

Commit 4ba1ffa

Browse files
committed
Multi Currency Money [springframeworkguru#19. Dollar side effects, equality for All]
1 parent dc14003 commit 4ba1ffa

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/test/java/guru/springframework/Dollar.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@ public Dollar(int amount) {
99
Dollar times(int multiplier) {
1010
return new Dollar(this.amount * multiplier);
1111
}
12+
13+
@Override
14+
public boolean equals(Object o) {
15+
Dollar dollar = (Dollar) o;
16+
return amount == dollar.amount;
17+
}
1218
}

src/test/java/guru/springframework/MoneyTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.junit.jupiter.api.Test;
44

55
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
67

78
public class MoneyTest {
89
@Test
@@ -14,4 +15,9 @@ void testMultiplication() {
1415
assertEquals(15, product.amount);
1516
}
1617

18+
@Test
19+
void testEquality() {
20+
assertEquals(new Dollar(6), new Dollar(6));
21+
assertNotEquals(new Dollar(6), new Dollar(8));
22+
}
1723
}

0 commit comments

Comments
 (0)