Browse Source

Curtis Cook's Clean Code Part 3

curtiscook 6 years ago
parent
commit
e748b3fae2

+ 4
- 0
src/main/java/com/zipcodewilmington/gildedrose/Inventory.java View File

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

+ 15
- 1
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java View File

10
     Item backstagePasses = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 10);
10
     Item backstagePasses = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 10);
11
     Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 15, 15);
11
     Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 15, 15);
12
     Item random = new Item("Random Items", 0, 7);
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
     Inventory inventory = new Inventory(items);
15
     Inventory inventory = new Inventory(items);
15
 
16
 
16
     @Test
17
     @Test
55
         // Then
56
         // Then
56
         Assert.assertEquals(expected, actual);
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