浏览代码

Updated backstage passes to default to 0 quality when sellin is 0

Lauren Green 6 年前
父节点
当前提交
983bbc4049

+ 5
- 1
src/main/java/com/zipcodewilmington/gildedrose/Inventory.java 查看文件

@@ -56,7 +56,11 @@ public class Inventory {
56 56
                 increaseQualityByTwo(i);
57 57
                 if ((items[i].getSellIn() <= 5)) {
58 58
                 increaseQualityByOne(i);
59
-            } } else if ((items[i].getName().equals("Conjured")) || (items[i].getSellIn() == 0)) {
59
+                }
60
+                if (items[i].getSellIn() == 0) {
61
+                    items[i].setQuality(0);
62
+                }
63
+            } else if ((items[i].getName().equals("Conjured")) || (items[i].getSellIn() == 0)) {
60 64
                 decreaseQualityByTwo(i);
61 65
             } else {
62 66
                 decreaseQualityByOne(i);

+ 21
- 0
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java 查看文件

@@ -188,6 +188,27 @@ public class InventoryTest {
188 188
     }
189 189
 
190 190
     @Test
191
+    public void backstagePasses0DaysUpdateQualityTest(){
192
+        //Given
193
+        Item backstagePass = new Item("Backstage Passes", 1, 10);
194
+        Item[] itemArr = new Item[1];
195
+        itemArr[0] = backstagePass;
196
+        Inventory newInv = new Inventory(itemArr);
197
+        int expected = 0;
198
+
199
+        //When
200
+        newInv.updateSellIn();
201
+        newInv.updateQuality();
202
+        newInv.updateSellIn();
203
+        newInv.updateQuality();
204
+
205
+        //Then
206
+        int actual = backstagePass.getQuality();
207
+
208
+        Assert.assertEquals(expected, actual);
209
+    }
210
+
211
+    @Test
191 212
     public void agedBrieUpdateQualityTest(){
192 213
         //Given
193 214
         Item agedBrie = new Item("Aged Brie", 20, 5);