Procházet zdrojové kódy

Curtis Cook's Clean Code Part 3

curtiscook před 6 roky
rodič
revize
e748b3fae2

+ 4
- 0
src/main/java/com/zipcodewilmington/gildedrose/Inventory.java Zobrazit soubor

@@ -37,6 +37,10 @@ public class Inventory {
37 37
                 }
38 38
             }
39 39
 
40
+            if(item.getName().equals("Conjured")) {
41
+                item.setQuality(item.getQuality() - 2);
42
+            }
43
+
40 44
 
41 45
             if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
42 46
                 item.setSellIn(item.getSellIn() - 1);

+ 15
- 1
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java Zobrazit soubor

@@ -10,7 +10,8 @@ public class InventoryTest {
10 10
     Item backstagePasses = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 10);
11 11
     Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 15, 15);
12 12
     Item random = new Item("Random Items", 0, 7);
13
-    Item[] items = {agedBrie, backstagePasses, sulfuras, random};
13
+    Item conjured = new Item("Conjured", 20, 42);
14
+    Item[] items = {agedBrie, backstagePasses, sulfuras, random, conjured};
14 15
     Inventory inventory = new Inventory(items);
15 16
 
16 17
     @Test
@@ -55,5 +56,18 @@ public class InventoryTest {
55 56
         // Then
56 57
         Assert.assertEquals(expected, actual);
57 58
     }
59
+
60
+    @Test
61
+    public void updateQuantityTest4() {
62
+        // Given
63
+        int expected = 42 - 1 - 2 - 39 + 1;
64
+
65
+        // When
66
+        inventory.updateQuality();
67
+        int actual = conjured.getQuality();
68
+
69
+        // Then
70
+        Assert.assertEquals(expected, actual);
71
+    }
58 72
 }
59 73