Browse Source

Started working

Yesoda Sanka 6 years ago
parent
commit
98953e8d6e

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

12
 
12
 
13
     public void updateQuality() {
13
     public void updateQuality() {
14
         for (int i = 0; i < items.length; i++) {
14
         for (int i = 0; i < items.length; i++) {
15
-          /** if (!items[i].getName().equals("Aged Brie")
15
+            if (!items[i].getName().equals("Aged Brie")
16
                     && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
16
                     && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
17
                 if (items[i].getQuality() > 0) {
17
                 if (items[i].getQuality() > 0) {
18
                     if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
18
                     if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
19
                         items[i].setQuality(items[i].getQuality() - 1);
19
                         items[i].setQuality(items[i].getQuality() - 1);
20
-
20
+                    }
21
                 }
21
                 }
22
-            } else {/*
22
+            } else {
23
                 if (items[i].getQuality() < 50) {
23
                 if (items[i].getQuality() < 50) {
24
                     items[i].setQuality(items[i].getQuality() + 1);
24
                     items[i].setQuality(items[i].getQuality() + 1);
25
 
25
 
30
                             }
30
                             }
31
                         }
31
                         }
32
 
32
 
33
-                       /* if (items[i].getSellIn() < 6) {
33
+                        if (items[i].getSellIn() < 6) {
34
                             if (items[i].getQuality() < 50) {
34
                             if (items[i].getQuality() < 50) {
35
                                 items[i].setQuality(items[i].getQuality() + 1);
35
                                 items[i].setQuality(items[i].getQuality() + 1);
36
                             }
36
                             }
37
                         }
37
                         }
38
                     }
38
                     }
39
                 }
39
                 }
40
-            }*/
40
+            }
41
 
41
 
42
             if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
42
             if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
43
                 items[i].setSellIn(items[i].getSellIn() - 1);
43
                 items[i].setSellIn(items[i].getSellIn() - 1);

+ 64
- 2
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java View File

5
 
5
 
6
 public class InventoryTest {
6
 public class InventoryTest {
7
     @Test
7
     @Test
8
-    public void updateQuantityTest(){
9
-        Assert.assertEquals(1, 1);
8
+    public void updateQuantity_forAgeBrie(){
9
+        int sellIn = 5;
10
+        int quality = 2;
11
+        Item agedBrie = new Item("Aged Brie", sellIn, quality);
12
+
13
+        Item[] items = {agedBrie};
14
+        Inventory inventory = new Inventory(items);
15
+
16
+        //invoke method under test
17
+        inventory.updateQuality();
18
+
19
+        //verify result
20
+        int expectedQuality = quality + 1;
21
+        Assert.assertEquals(expectedQuality, agedBrie.getQuality());
22
+    }
23
+
24
+    @Test
25
+    public void updateQuantity_forAgeBrieWhenQualityIs50(){
26
+        int sellIn = 5;
27
+        int quality = 50;
28
+        Item agedBrie = new Item("Aged Brie", sellIn, quality);
29
+
30
+        Item[] items = {agedBrie};
31
+        Inventory inventory = new Inventory(items);
32
+
33
+        //invoke method under test
34
+        inventory.updateQuality();
35
+
36
+        //verify result
37
+        int expectedQuality = quality;
38
+        Assert.assertEquals(expectedQuality, agedBrie.getQuality());
39
+    }
40
+    @Test
41
+    public void updateQuantity_forAgeBrieWhenQualityIs49(){
42
+        int sellIn = 5;
43
+        int quality = 30;
44
+        Item agedBrie = new Item("Aged Brie", sellIn, quality);
45
+
46
+        Item[] items = {agedBrie};
47
+        Inventory inventory = new Inventory(items);
48
+
49
+        //invoke method under test
50
+        inventory.updateQuality();
51
+
52
+        //verify result
53
+        int expectedQuality = quality+1;
54
+        Assert.assertEquals(expectedQuality, agedBrie.getQuality());
10
     }
55
     }
56
+    @Test
57
+    public void updateQuantity_forBackstagepasses(){
58
+        int sellIn = 5;
59
+        int quality = 10;
60
+        Item agedBrie = new Item("Backstage passes", sellIn, quality);
61
+
62
+        Item[] items = {agedBrie};
63
+        Inventory inventory = new Inventory(items);
64
+
65
+        //invoke method under test
66
+        inventory.updateQuality();
67
+
68
+        //verify result
69
+        int expectedQuality = quality;
70
+        Assert.assertEquals(expectedQuality, agedBrie.getQuality());
71
+
72
+}
11
 }
73
 }
12
 
74