File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
src/test/java/guru/springframework Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 33import org .junit .jupiter .api .Test ;
44
55import static org .junit .jupiter .api .Assertions .assertEquals ;
6+ import static org .junit .jupiter .api .Assertions .assertNotEquals ;
67
78public 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}
You can’t perform that action at this time.
0 commit comments