forked from guyroyse/vending-machine-kata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring and more separation of responsibilities
- Loading branch information
1 parent
4580f50
commit 809e0e2
Showing
5 changed files
with
44 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.vendingmachine.formatter; | ||
|
||
import java.math.BigDecimal; | ||
import java.text.NumberFormat; | ||
|
||
public class Formatter { | ||
public String toCurrency(BigDecimal bigDecimal) { | ||
return NumberFormat.getCurrencyInstance().format(bigDecimal); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/test/java/com/vendingmachine/formatter/FormatterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.vendingmachine.formatter; | ||
|
||
import org.junit.Test; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class FormatterTest { | ||
@Test | ||
public void shouldFormatMoney() { | ||
BigDecimal bigDecimal = new BigDecimal(13.37); | ||
|
||
String currency = new Formatter().toCurrency(bigDecimal); | ||
|
||
assertEquals("$13.37", currency); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters