Skip to content

Commit

Permalink
Multi Currency Money [springframeworkguru#21. Implement Franc Object …
Browse files Browse the repository at this point in the history
…by test]
  • Loading branch information
gechulim committed May 5, 2023
1 parent 928b2d3 commit 2e38256
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/test/java/guru/springframework/Franc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package guru.springframework;

public class Franc {
private int amount;
public Franc(int amount) {
this.amount = amount;
}

Franc times(int multiplier) {
return new Franc(this.amount * multiplier);
}

@Override
public boolean equals(Object o) {
Franc franc = (Franc) o;
return amount == franc.amount;
}

}
19 changes: 17 additions & 2 deletions src/test/java/guru/springframework/MoneyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class MoneyTest {
@Test
void testMultiplication() {
void testMultiplicationDollar() {
Dollar five = new Dollar(5);
Dollar product = five.times(2);
assertEquals(new Dollar(10), product);
Expand All @@ -16,8 +16,23 @@ void testMultiplication() {
}

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

@Test
void testMultiplicationFranc() {
Franc five = new Franc(5);
Franc product = five.times(2);
assertEquals(new Franc(10), product);
product = five.times(3);
assertEquals(new Franc(15), product);
}

@Test
void testEqualityFranc() {
assertEquals(new Franc(6), new Franc(6));
assertNotEquals(new Franc(6), new Franc(8));
}
}

0 comments on commit 2e38256

Please sign in to comment.