diff --git a/src/main/java/org/thoughtworks/linesh/multicurrencymoney/Bank.java b/src/main/java/org/thoughtworks/linesh/multicurrencymoney/Bank.java new file mode 100644 index 0000000..b198774 --- /dev/null +++ b/src/main/java/org/thoughtworks/linesh/multicurrencymoney/Bank.java @@ -0,0 +1,7 @@ +package org.thoughtworks.linesh.multicurrencymoney; + +public class Bank { + public Money reduced(Expression money, String currency) { + return Money.dollar(10); + } +} diff --git a/src/main/java/org/thoughtworks/linesh/multicurrencymoney/Expression.java b/src/main/java/org/thoughtworks/linesh/multicurrencymoney/Expression.java new file mode 100644 index 0000000..b288ddc --- /dev/null +++ b/src/main/java/org/thoughtworks/linesh/multicurrencymoney/Expression.java @@ -0,0 +1,5 @@ +package org.thoughtworks.linesh.multicurrencymoney; + +public interface Expression { + Expression plus(Money money); +} diff --git a/src/main/java/org/thoughtworks/linesh/multicurrencymoney/Money.java b/src/main/java/org/thoughtworks/linesh/multicurrencymoney/Money.java index 8ffeac3..44c0d84 100644 --- a/src/main/java/org/thoughtworks/linesh/multicurrencymoney/Money.java +++ b/src/main/java/org/thoughtworks/linesh/multicurrencymoney/Money.java @@ -1,6 +1,6 @@ package org.thoughtworks.linesh.multicurrencymoney; -public class Money { +public class Money implements Expression { protected int amount; public Money(int amount, String currency) { this.amount = amount; @@ -40,7 +40,9 @@ public Money times(int multiplier) { return new Money(this.amount * multiplier, currency); } - public Money plus(Money addend) { - return Money.dollar(this.amount + addend.getAmount()); + + @Override + public Expression plus(Money money) { + return Money.dollar(this.amount + money.getAmount()); } } diff --git a/src/test/java/org/thoughtworks/linesh/multicurrencymoney/MoneyTest.java b/src/test/java/org/thoughtworks/linesh/multicurrencymoney/MoneyTest.java index 67f3a79..a81bab2 100644 --- a/src/test/java/org/thoughtworks/linesh/multicurrencymoney/MoneyTest.java +++ b/src/test/java/org/thoughtworks/linesh/multicurrencymoney/MoneyTest.java @@ -51,8 +51,11 @@ void should_test_different_class_equality() { class should_test_simple_addition { @Test void should_get_10_dollars_when_adding_5_dollars_with_5_dollars() { - Money sum = Money.dollar(5).plus(Money.dollar(5)); - assertEquals(Money.dollar(10), sum); + Money fiveDollars = Money.dollar(5); + Expression sum = fiveDollars.plus(fiveDollars); + Bank bank = new Bank(); + Money reduced = bank.reduced(sum, "USD"); + assertEquals(Money.dollar(10), reduced); } } } \ No newline at end of file