diff --git a/src/main/java/com/vendingmachine/constants/Coins.java b/src/main/java/com/vendingmachine/constants/Coins.java index 093b05d7..26a84302 100644 --- a/src/main/java/com/vendingmachine/constants/Coins.java +++ b/src/main/java/com/vendingmachine/constants/Coins.java @@ -3,7 +3,7 @@ import java.math.BigDecimal; public final class Coins { - public static final BigDecimal NULL = BigDecimal.ZERO; + public static final BigDecimal NONE = BigDecimal.ZERO; public static final BigDecimal PENNY = new BigDecimal(0.01); public static final BigDecimal NICKEL = new BigDecimal(0.05); public static final BigDecimal DIME = new BigDecimal(0.10); diff --git a/src/main/java/com/vendingmachine/converter/CoinConverter.java b/src/main/java/com/vendingmachine/converter/CoinConverter.java index 540b6c1d..69192881 100644 --- a/src/main/java/com/vendingmachine/converter/CoinConverter.java +++ b/src/main/java/com/vendingmachine/converter/CoinConverter.java @@ -18,7 +18,7 @@ public BigDecimal toCoin(String entry) { } else if (isHalfDollar(entryWithoutSpaces)) { return HALF_DOLLAR; } else { - return NULL; + return NONE; } } @@ -31,7 +31,7 @@ private boolean isNickel(String entry) { } private boolean isDime(String entry) { - return "dime".equalsIgnoreCase(entry) || ".10".equals(entry) || "0.10".equals(entry); + return "dime".equalsIgnoreCase(entry) || ".10".equals(entry) || "0.10".equals(entry) || ".1".equals(entry) || "0.1".equals(entry); } private boolean isQuarter(String entry) { @@ -39,7 +39,7 @@ private boolean isQuarter(String entry) { } private boolean isHalfDollar(String entry) { - return "halfdollar".equalsIgnoreCase(entry) || ".50".equals(entry) || "0.50".equals(entry); + return "halfdollar".equalsIgnoreCase(entry) || ".50".equals(entry) || "0.50".equals(entry) || ".5".equals(entry) || "0.5".equals(entry); } private String removeSpaces(String entry) { diff --git a/src/main/java/com/vendingmachine/service/CoinService.java b/src/main/java/com/vendingmachine/service/CoinService.java index e0def900..a4783ae5 100644 --- a/src/main/java/com/vendingmachine/service/CoinService.java +++ b/src/main/java/com/vendingmachine/service/CoinService.java @@ -29,7 +29,7 @@ private String determineConsoleOutput(Coin coin) { } private void askForNextCoin() { - System.out.print("Insert coin: "); + System.out.print("Insert coin or select a product: "); } private String formatCurrency(BigDecimal runningTotal) { diff --git a/src/test/java/com/vendingmachine/converter/CoinConverterTest.java b/src/test/java/com/vendingmachine/converter/CoinConverterTest.java index f5b00849..154df906 100644 --- a/src/test/java/com/vendingmachine/converter/CoinConverterTest.java +++ b/src/test/java/com/vendingmachine/converter/CoinConverterTest.java @@ -26,15 +26,19 @@ public static Object[][] toCoinDataProvier() { { ".01", PENNY }, { ".05", NICKEL }, { ".10", DIME }, + { ".1", DIME }, { ".25", QUARTER }, { ".50", HALF_DOLLAR }, + { ".5", HALF_DOLLAR }, { "0.01", PENNY }, { "0.05", NICKEL }, { "0.10", DIME }, + { "0.1", DIME }, { "0.25", QUARTER }, { "0.50", HALF_DOLLAR }, - { "", NULL }, - { "asdf", NULL } + { "0.5", HALF_DOLLAR }, + { "", NONE}, + { "asdf", NONE} }; } diff --git a/src/test/java/com/vendingmachine/service/CoinServiceTest.java b/src/test/java/com/vendingmachine/service/CoinServiceTest.java index f39463ec..33d1ce8e 100644 --- a/src/test/java/com/vendingmachine/service/CoinServiceTest.java +++ b/src/test/java/com/vendingmachine/service/CoinServiceTest.java @@ -24,13 +24,20 @@ public void cleanUpStreams() { System.setOut(null); } + @Test + public void shouldPrintInsertCoinIfNoCoinIsInserted() { + new CoinService(); + + assertEquals("Insert coin or select a product: ", byteArrayOutputStream.toString()); + } + @Test public void shouldPrintCurrentAmountFiveToConsole() { Coin nickel = new Coin().setValue(NICKEL); new CoinService().insertCoin(nickel); - assertEquals("Insert coin: Current amount: $0.05\nInsert coin: ", byteArrayOutputStream.toString()); + assertEquals("Insert coin or select a product: Current amount: $0.05\nInsert coin or select a product: ", byteArrayOutputStream.toString()); } @Test @@ -43,7 +50,7 @@ public void shouldPrintCurrentAmountFiveCurrentAmountTenCurrentAmountThirtyFive( coinService.insertCoin(nickel); coinService.insertCoin(quarter); - assertEquals("Insert coin: Current amount: $0.05\nInsert coin: Current amount: $0.10\nInsert coin: Current amount: $0.35\nInsert coin: ", byteArrayOutputStream.toString()); + assertEquals("Insert coin or select a product: Current amount: $0.05\nInsert coin or select a product: Current amount: $0.10\nInsert coin or select a product: Current amount: $0.35\nInsert coin or select a product: ", byteArrayOutputStream.toString()); } @Test @@ -55,7 +62,7 @@ public void shouldPrintCurrentAmountFiveCoinReturnOne() { coinService.insertCoin(nickel); coinService.insertCoin(penny); - assertEquals("Insert coin: Current amount: $0.05\nInsert coin: Coin return: $0.01\nInsert coin: ", byteArrayOutputStream.toString()); + assertEquals("Insert coin or select a product: Current amount: $0.05\nInsert coin or select a product: Coin return: $0.01\nInsert coin or select a product: ", byteArrayOutputStream.toString()); } @Test @@ -64,7 +71,7 @@ public void shouldPrintCurrentAmountTwentyFive() { new CoinService().insertCoin(quarter); - assertEquals("Insert coin: Current amount: $0.25\nInsert coin: ", byteArrayOutputStream.toString()); + assertEquals("Insert coin or select a product: Current amount: $0.25\nInsert coin or select a product: ", byteArrayOutputStream.toString()); } @Test @@ -73,7 +80,7 @@ public void shouldPrintCoinReturnOne() { new CoinService().insertCoin(penny); - assertEquals("Insert coin: Coin return: $0.01\nInsert coin: ", byteArrayOutputStream.toString()); + assertEquals("Insert coin or select a product: Coin return: $0.01\nInsert coin or select a product: ", byteArrayOutputStream.toString()); } @Test @@ -82,13 +89,6 @@ public void shouldPrintCoinReturnFifty() { new CoinService().insertCoin(halfDollar); - assertEquals("Insert coin: Coin return: $0.50\nInsert coin: ", byteArrayOutputStream.toString()); - } - - @Test - public void shouldPrintInsertCoinIfNoCoinIsInserted() { - new CoinService(); - - assertEquals("Insert coin: ", byteArrayOutputStream.toString()); + assertEquals("Insert coin or select a product: Coin return: $0.50\nInsert coin or select a product: ", byteArrayOutputStream.toString()); } }