Sfoglia il codice sorgente

Curtis Cook's Clean Code Part 2

curtiscook 6 anni fa
parent
commit
9aac27260e

+ 45
- 42
src/main/java/com/zipcodewilmington/gildedrose/Inventory.java Vedi File

@@ -11,56 +11,59 @@ public class Inventory {
11 11
 
12 12
 
13 13
     public void updateQuality() {
14
-        for (int i = 0; i < items.length; i++) {
15
-            if (!items[i].getName().equals("Aged Brie")
16
-                    && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
17
-                if (items[i].getQuality() > 0) {
18
-                    if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
19
-                        items[i].setQuality(items[i].getQuality() - 1);
20
-                    }
14
+        for (Item item : items) {
15
+            if (!item.getName().equals("Aged Brie")
16
+                    && !item.getName().equals("Backstage passes to a TAFKAL80ETC concert")
17
+                    && item.getQuality() > 0
18
+                    && !item.getName().equals("Sulfuras, Hand of Ragnaros")) {
19
+                item.setQuality(item.getQuality() - 1);
20
+            }
21
+
22
+            if (!item.getName().equals("Aged Brie")
23
+                    && !item.getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
24
+            } else if (item.getQuality() < 50) {
25
+                item.setQuality(item.getQuality() + 1);
26
+                if (item.getName().equals("Backstage passes to a TAFKAL80ETC concert")
27
+                        && item.getSellIn() < 11) {
21 28
                 }
22
-            } else {
23
-                if (items[i].getQuality() < 50) {
24
-                    items[i].setQuality(items[i].getQuality() + 1);
29
+                if (item.getSellIn() < 6
30
+                        && item.getQuality() < 50) {
31
+                    item.setQuality(item.getQuality() + 1);
32
+                }
33
+                if (item.getName().equals("Backstage passes to a TAFKAL80ETC concert")
34
+                        && item.getSellIn() < 11
35
+                        && item.getQuality() < 50) {
36
+                    item.setQuality(item.getQuality() + 1);
37
+                }
38
+            }
25 39
 
26
-                    if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert") {
27
-                        if (items[i].getSellIn() < 11) {
28
-                            if (items[i].getQuality() < 50) {
29
-                                items[i].setQuality(items[i].getQuality() + 1);
30
-                            }
31
-                        }
32 40
 
33
-                        if (items[i].getSellIn() < 6) {
34
-                            if (items[i].getQuality() < 50) {
35
-                                items[i].setQuality(items[i].getQuality() + 1);
36
-                            }
37
-                        }
38
-                    }
39
-                }
41
+            if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
42
+                item.setSellIn(item.getSellIn() - 1);
40 43
             }
41 44
 
42
-            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
43
-                items[i].setSellIn(items[i].getSellIn() - 1);
45
+            if (item.getSellIn() < 0
46
+                    && !item.getName().equals("Aged Brie")
47
+                    && !item.getName().equals("Backstage passes to a TAFKAL80ETC concert")
48
+                    && item.getQuality() > 0
49
+                    && !item.getName().equals("Sulfuras, Hand of Ragnaros")) {
50
+                item.setQuality(item.getQuality() - 1);
44 51
             }
45 52
 
46
-            if (items[i].getSellIn() < 0) {
47
-                if (!items[i].getName().equals("Aged Brie")) {
48
-                    if (!items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
49
-                        if (items[i].getQuality() > 0) {
50
-                            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
51
-                                items[i].setQuality(items[i].getQuality() - 1);
52
-                            }
53
-                        }
54
-                    } else {
55
-                        items[i].setQuality(items[i].getQuality()
56
-                                - items[i].getQuality());
57
-                    }
58
-                } else {
59
-                    if (items[i].getQuality() < 50) {
60
-                        items[i].setQuality(items[i].getQuality() + 1);
61
-                    }
62
-                }
53
+            if (item.getSellIn() < 0
54
+                    && !item.getName().equals("Aged Brie")
55
+                    && !item.getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
56
+            } else {
57
+                item.setQuality(0);
58
+            }
59
+
60
+            if (item.getSellIn() < 0
61
+                    && !item.getName().equals("Aged Brie")) {
62
+            } else if (item.getQuality() < 50) {
63
+                item.setQuality(item.getQuality() + 1);
63 64
             }
65
+
64 66
         }
65 67
     }
68
+
66 69
 }

+ 0
- 15
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java Vedi File

@@ -55,20 +55,5 @@ public class InventoryTest {
55 55
         // Then
56 56
         Assert.assertEquals(expected, actual);
57 57
     }
58
-
59
-    @Test
60
-    public void updateQuantityTest4() {
61
-        // Given
62
-        agedBrie.setSellIn(-7);
63
-        agedBrie.setQuality(41);
64
-        int expected = 41 + 1 + 1;
65
-
66
-        // When
67
-        inventory.updateQuality();
68
-        int actual = agedBrie.getQuality();
69
-
70
-        // Then
71
-        Assert.assertEquals(expected, actual);
72
-    }
73 58
 }
74 59