Vincent Sima 8 vuotta sitten
vanhempi
commit
b6be685e20
2 muutettua tiedostoa jossa 48 lisäystä ja 3 poistoa
  1. 11
    2
      Inventory.java
  2. 37
    1
      InventoryTest.java

+ 11
- 2
Inventory.java Näytä tiedosto

@@ -19,12 +19,21 @@ public class Inventory {
19 19
             } else if(items[i].getName().equals("Sulfuras, Hand of Ragnaros")){
20 20
                 items[i].setQuality(items[i].getQuality() + 0);
21 21
 
22
-            } else {
22
+            } else if(items[i].getName().equals("Conjured Sword")){
23
+                if(items[i].getSellIn() > 0 && items[i].getQuality() > 0){
24
+                    items[i].setQuality(items[i].getQuality() - 2);
25
+                }
26
+                if(items[i].getSellIn() <= 0 && items[i].getQuality() > 0){
27
+                items[i].setQuality(items[i].getQuality() - 4);
28
+                }
29
+            
30
+            }else {
23 31
                 if(items[i].getSellIn() > 0 && items[i].getQuality() > 0){
24 32
                     items[i].setQuality(items[i].getQuality() - 1);
25 33
                 }
26 34
                 if(items[i].getSellIn() <= 0 && items[i].getQuality() > 0){
27
-                items[i].setQuality(items[i].getQuality() - 2);}
35
+                items[i].setQuality(items[i].getQuality() - 2);
36
+                }
28 37
             }
29 38
             
30 39
             if(items[i].getQuality() < 80){

+ 37
- 1
InventoryTest.java Näytä tiedosto

@@ -8,7 +8,8 @@ public class InventoryTest {
8 8
     private static final String AGED_BRIE_NAME = "Aged Brie";
9 9
     private static final String BACKSTAGE_PASS_NAME = "Backstage passes to a TAFKAL80ETC concert";
10 10
     private static final String NORMAL_ITEM_NAME = "+5 Dexterity Vest";
11
-
11
+    private static final String CONJURED_SWORD_NAME = "Conjured Sword";
12
+    
12 13
     private Item sulfuras;
13 14
     private Item normalItem;
14 15
 
@@ -119,4 +120,39 @@ public class InventoryTest {
119 120
 
120 121
         assertEquals(expectedQuality, agedBrie.getQuality());
121 122
     }
123
+    
124
+    @Test
125
+    public void testUpdate_ConjuredSword() throws Exception {
126
+        Item conjuredSword = new Item(CONJURED_SWORD_NAME, 10, 25);
127
+        int expectedQuality = conjuredSword.getQuality() - 2;
128
+        Item[] items = {conjuredSword};
129
+        Inventory sut = new Inventory(items);
130
+
131
+        sut.updateQuality();
132
+
133
+        assertEquals(expectedQuality, conjuredSword.getQuality());
134
+    }
135
+
136
+    @Test
137
+    public void testUpdate_ConjuredSwordIsAtMaxQuality() throws Exception {
138
+        Item conjuredSword = new Item(CONJURED_SWORD_NAME, 10, MAX_QUALITY);
139
+        Item[] items = {conjuredSword};
140
+        Inventory sut = new Inventory(items);
141
+
142
+        sut.updateQuality();
143
+
144
+        assertEquals((MAX_QUALITY-2), conjuredSword.getQuality());
145
+    }
146
+
147
+    @Test
148
+    public void testUpdate_WhenConjuredSwordOnceTheSellInDatePassed() throws Exception {
149
+        Item conjuredSword = new Item(CONJURED_SWORD_NAME, -1, 20);
150
+        int expectedQuality = conjuredSword.getQuality() - 4;
151
+        Item[] items = {conjuredSword};
152
+        Inventory sut = new Inventory(items);
153
+
154
+        sut.updateQuality();
155
+
156
+        assertEquals(expectedQuality, conjuredSword.getQuality());
157
+    }
122 158
 }