ソースを参照

Curtis Cook's Clean Code Part 3

curtiscook 6 年 前
コミット
e748b3fae2
共有2 個のファイルを変更した19 個の追加1 個の削除を含む
  1. 4
    0
      src/main/java/com/zipcodewilmington/gildedrose/Inventory.java
  2. 15
    1
      src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java

+ 4
- 0
src/main/java/com/zipcodewilmington/gildedrose/Inventory.java ファイルの表示

@@ -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 ファイルの表示

@@ -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