File tree Expand file tree Collapse file tree 4 files changed +26
-9
lines changed
src/test/java/guru/springframework Expand file tree Collapse file tree 4 files changed +26
-9
lines changed Original file line number Diff line number Diff line change 11package guru .springframework ;
22
3- public class Dollar extends Money {
4- public Dollar (int amount ) {
5- this . amount = amount ;
3+ public class Dollar extends Money {
4+ public Dollar (int amount , String currency ) {
5+ super ( amount , currency ) ;
66 }
77
88 public Money times (int multiplier ) {
9- return new Dollar (this .amount * multiplier );
9+ return Money . dollar (this .amount * multiplier );
1010 }
1111}
Original file line number Diff line number Diff line change 11package guru .springframework ;
22
33public class Franc extends Money {
4- public Franc (int amount ) {
5- this . amount = amount ;
4+ public Franc (int amount , String currency ) {
5+ super ( amount , currency ) ;
66 }
77
88 public Money times (int multiplier ) {
9- return new Franc (this .amount * multiplier );
9+ return Money . franc (this .amount * multiplier );
1010 }
1111
1212}
Original file line number Diff line number Diff line change 22
33public abstract class Money {
44 protected int amount ;
5+ protected String currency ;
6+
7+
8+ public Money (int amount , String currency ) {
9+ this .amount = amount ;
10+ this .currency = currency ;
11+ }
12+
13+ protected String currency () {
14+ return currency ;
15+ }
516
617 public abstract Money times (int multiplier );
718
819 public static Money dollar (int amount ) {
9- return new Dollar (amount );
20+ return new Dollar (amount , "USD" );
1021 }
1122
1223 public static Money franc (int amount ) {
13- return new Franc (amount );
24+ return new Franc (amount , "CHF" );
1425 }
1526
1627 public boolean equals (Object o ) {
Original file line number Diff line number Diff line change @@ -33,4 +33,10 @@ void testEqualityFranc() {
3333 assertNotEquals (Money .franc (5 ), Money .franc (8 ));
3434 assertNotEquals (Money .franc (5 ), Money .dollar (5 ));
3535 }
36+
37+ @ Test
38+ void testCurrency () {
39+ assertEquals ("USD" , Money .dollar (1 ).currency ());
40+ assertEquals ("CHF" , Money .franc (1 ).currency ());
41+ }
3642}
You can’t perform that action at this time.
0 commit comments