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.
Wrote validation to determine whether the input was a coin or a produ…
…ct and then sent it down the previously built bath (either insertCoin or dispenseProduct)
- Loading branch information
1 parent
bd91f6e
commit 8ba9793
Showing
8 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,21 @@ | ||
package com.vendingmachine.validator; | ||
|
||
import com.vendingmachine.converter.CoinConverter; | ||
import com.vendingmachine.converter.ProductConverter; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import static com.vendingmachine.constants.Coins.NONE; | ||
import static com.vendingmachine.constants.Products.INVALID; | ||
|
||
public class Validator { | ||
public boolean isACoin(String value) { | ||
BigDecimal coin = new CoinConverter().toCoin(value); | ||
return !coin.equals(NONE); | ||
} | ||
|
||
public boolean isAProduct(String value) { | ||
BigDecimal product = new ProductConverter().toProduct(value); | ||
return !product.equals(INVALID); | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
src/test/java/com/vendingmachine/validator/ValidatorTest.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,42 @@ | ||
package com.vendingmachine.validator; | ||
|
||
import com.tngtech.java.junit.dataprovider.DataProvider; | ||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | ||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(DataProviderRunner.class) | ||
public class ValidatorTest { | ||
@DataProvider | ||
public static Object[][] coinDataProvider() { | ||
return new Object[][] { | ||
{ "nickel", true }, | ||
{ "dime", true }, | ||
{ "chips", false } | ||
}; | ||
} | ||
|
||
@Test | ||
@UseDataProvider("coinDataProvider") | ||
public void shouldPassIfIsValidCoin(String value, boolean expected) { | ||
assertEquals(expected, new Validator().isACoin(value)); | ||
} | ||
|
||
@DataProvider | ||
public static Object[][] productDataProvider() { | ||
return new Object[][] { | ||
{ "chips", true }, | ||
{ "candy", true }, | ||
{ "dime", false } | ||
}; | ||
} | ||
|
||
@Test | ||
@UseDataProvider("productDataProvider") | ||
public void shouldPassIfIsValidProduct(String value, boolean expected) { | ||
assertEquals(expected, new Validator().isAProduct(value)); | ||
} | ||
} |