Skip to content

Commit

Permalink
Multi Currency Money [springframeworkguru#19. Dollar side effects, eq…
Browse files Browse the repository at this point in the history
…uality for All]
  • Loading branch information
gechulim committed May 5, 2023
1 parent dc14003 commit 4ba1ffa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/test/java/guru/springframework/Dollar.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ public Dollar(int amount) {
Dollar times(int multiplier) {
return new Dollar(this.amount * multiplier);
}

@Override
public boolean equals(Object o) {
Dollar dollar = (Dollar) o;
return amount == dollar.amount;
}
}
6 changes: 6 additions & 0 deletions src/test/java/guru/springframework/MoneyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

public class MoneyTest {
@Test
Expand All @@ -14,4 +15,9 @@ void testMultiplication() {
assertEquals(15, product.amount);
}

@Test
void testEquality() {
assertEquals(new Dollar(6), new Dollar(6));
assertNotEquals(new Dollar(6), new Dollar(8));
}
}

0 comments on commit 4ba1ffa

Please sign in to comment.