diff --git a/Java/README.md b/Java/README.md
index da5135ae..b9166802 100644
--- a/Java/README.md
+++ b/Java/README.md
@@ -17,18 +17,22 @@
All items have a Quality value which denotes how valuable the item is.
At the end of each day our system lowers both values for every item.
-
-
-New Requisites
-
- Once the sell by date has passed, Quality degrades twice as fast
- The Quality of an item is never negative
- "Aged Brie" actually increases in Quality the older it gets
- The Quality of an item is never more than 50
- "Sulfuras", being a legendary item, never has to be sold or decreases in Quality
- - "Backstage passes", like aged brie, increases in Quality as its SellIn value approaches;
- - Quality increases by 2 when there are 10 days or less and by 3 when there are 5 days or less but
- - Quality drops to 0 after the concert
+ -
+ "Backstage passes", like aged brie, increases in Quality as its SellIn value approaches;
+
+ - Quality increases by 2 when there are 10 days or less and by 3 when there are 5 days or less but
+ - Quality drops to 0 after the concert
+
+
+
+
+New Requirement
+
- Conjured" items degrade in Quality twice as fast as normal items
@@ -42,7 +46,6 @@
Original Output
-
OMGHAI!
-------- day 0 --------
diff --git a/Java/src/test/java/com/gildedrose/GildedRoseTest.java b/Java/src/test/java/com/gildedrose/GildedRoseTest.java
index 9e61b788..d2ca9a49 100644
--- a/Java/src/test/java/com/gildedrose/GildedRoseTest.java
+++ b/Java/src/test/java/com/gildedrose/GildedRoseTest.java
@@ -7,21 +7,80 @@ import java.util.stream.IntStream;
import static org.junit.jupiter.api.Assertions.assertEquals;
class GildedRoseTest {
+ private final int days = 2;
@Test
- void dexterityVestShouldDecreaseSellInAndQualityEachUpdate() {
- String name = "+5 Dexterity Vest";
- int sellIn = 10;
- int quality = 20;
- int days = 2;
+ void shouldDecreaseQualityEachUpdate() {
+ assertCalculatedValues(getDecreaseQualityItems(),
+ new GildedRose(getDecreaseQualityItems()), CalcQuality.DECREASE);
+ }
- Item[] items = new Item[]{new Item(name, sellIn, quality)};
- GildedRose app = new GildedRose(items);
- IntStream.rangeClosed(1, days).forEach(index -> {
+ @Test
+ void shouldIncreaseQualityEachUpdate() {
+ assertCalculatedValues(getIncreaseQualityItems(),
+ new GildedRose(getIncreaseQualityItems()), CalcQuality.INCREASE);
+ }
+
+ @Test
+ void shouldRetainPropsEachUpdate() {
+ assertCalculatedValues(getRetainPropsItems(),
+ new GildedRose(getRetainPropsItems()), CalcQuality.NOTHING);
+ }
+
+ private Item[] getRetainPropsItems() {
+ return new Item[] {
+ new Item("Sulfuras, Hand of Ragnaros", 0, 80),
+ new Item("Sulfuras, Hand of Ragnaros", -1, 80)
+ };
+ }
+
+ private Item[] getIncreaseQualityItems() {
+ return new Item[] {
+ new Item("Aged Brie", 2, 0),
+ new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
+ new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
+ new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49)
+ };
+ }
+
+ private Item[] getDecreaseQualityItems() {
+ return new Item[] {
+ new Item("+5 Dexterity Vest", 10, 20),
+ new Item("Elixir of the Mongoose", 5, 7)
+ };
+ }
+
+ private void assertCalculatedValues(Item[] originItems, GildedRose app, CalcQuality calcQuality) {
+ IntStream.range(1, this.days).forEach(day -> {
app.updateQuality();
- assertEquals(name, app.items[0].name);
- assertEquals(sellIn - index, app.items[0].sellIn);
- assertEquals(quality - index, app.items[0].quality);
+ IntStream.range(0, originItems.length).forEach(index -> {
+ assertEquals(originItems[index].name, app.items[index].name);
+ int sellInCalculated = getSellInCalculated(originItems[index].sellIn, calcQuality, day);
+ assertEquals(sellInCalculated, app.items[index].sellIn);
+ int quantityCalculated = getQualityCalculated(originItems[index].quality, calcQuality, day);
+ assertEquals(quantityCalculated, app.items[index].quality);
+ });
});
}
+
+ private int getSellInCalculated(int sellIn, CalcQuality calcQuality, int day) {
+ if(!calcQuality.equals(CalcQuality.NOTHING)) {
+ return sellIn - day;
+ }
+ return sellIn;
+ }
+
+ private int getQualityCalculated(int quality, CalcQuality calcQuality, int day) {
+ if(calcQuality.equals(CalcQuality.DECREASE)) {
+ return quality - day;
+ }
+ if(calcQuality.equals(CalcQuality.INCREASE)) {
+ return quality + day;
+ }
+ return quality;
+ }
+}
+
+enum CalcQuality {
+ INCREASE, DECREASE, NOTHING
}