瀏覽代碼

Test cover 35% of lines in code

Akeem Cherry 6 年之前
父節點
當前提交
da31c70406

+ 1
- 13
src/main/java/com/zipcodewilmington/gildedrose/Inventory.java 查看文件

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
-
26
                     if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert") {
25
                     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
-
33
                         if (items[i].getSellIn() < 6) {
26
                         if (items[i].getSellIn() < 6) {
34
                             if (items[i].getQuality() < 50) {
27
                             if (items[i].getQuality() < 50) {
35
                                 items[i].setQuality(items[i].getQuality() + 1);
28
                                 items[i].setQuality(items[i].getQuality() + 1);
52
                             }
45
                             }
53
                         }
46
                         }
54
                     } else {
47
                     } 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);
48
+                        items[i].setQuality(0);
61
                     }
49
                     }
62
                 }
50
                 }
63
             }
51
             }

+ 6
- 0
src/main/java/com/zipcodewilmington/gildedrose/Item.java 查看文件

13
     }
13
     }
14
 
14
 
15
     public String getName() {
15
     public String getName() {
16
+
16
         return name;
17
         return name;
17
     }
18
     }
18
 
19
 
19
     public void setName(String name) {
20
     public void setName(String name) {
21
+
20
         this.name = name;
22
         this.name = name;
21
     }
23
     }
22
 
24
 
23
     public int getSellIn() {
25
     public int getSellIn() {
26
+
24
         return sellIn;
27
         return sellIn;
25
     }
28
     }
26
 
29
 
27
     public void setSellIn(int sellIn) {
30
     public void setSellIn(int sellIn) {
31
+
28
         this.sellIn = sellIn;
32
         this.sellIn = sellIn;
29
     }
33
     }
30
 
34
 
31
     public int getQuality() {
35
     public int getQuality() {
36
+
32
         return quality;
37
         return quality;
33
     }
38
     }
34
 
39
 
35
     public void setQuality(int quality) {
40
     public void setQuality(int quality) {
41
+
36
         this.quality = quality;
42
         this.quality = quality;
37
     }
43
     }
38
 }
44
 }

+ 53
- 0
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java 查看文件

6
 public class InventoryTest {
6
 public class InventoryTest {
7
     @Test
7
     @Test
8
     public void updateQuantityTest(){
8
     public void updateQuantityTest(){
9
+        Item item = new Item("Sulfuras", 1, 1);
9
         Assert.assertEquals(1, 1);
10
         Assert.assertEquals(1, 1);
10
     }
11
     }
12
+
13
+    @Test
14
+    public void getNameTest(){
15
+        Item tape = new Item("Some new tape",47,55);
16
+        String expectedTapeName = "Some new tape";
17
+        String actualTapeName = tape.getName();
18
+        Assert.assertEquals(expectedTapeName, actualTapeName);
19
+    }
20
+
21
+    @Test
22
+    public void setNameTest(){
23
+        Item tape = new Item("Some new tape", 47,55);
24
+        String expectedTapeName = "New Tape";
25
+        tape.setName("New Tape");
26
+        String actualTapeName = tape.getName();
27
+        Assert.assertEquals(expectedTapeName, actualTapeName);
28
+    }
29
+
30
+    @Test
31
+    public void getSellInTest(){
32
+        Item tape = new Item("Some new tape", 47,55);
33
+        int expectedSellIn = 47;
34
+        int actualSellIn = tape.getSellIn();
35
+        Assert.assertEquals(expectedSellIn, actualSellIn);
36
+    }
37
+
38
+    @Test
39
+    public void setSellInTest(){
40
+        Item tape = new Item("Some new tape", 47,55);
41
+        int expectedSellIn = 47;
42
+        tape.setSellIn(47);
43
+        int actualSellIn = tape.getSellIn();
44
+        Assert.assertEquals(expectedSellIn, actualSellIn);
45
+    }
46
+
47
+    @Test
48
+    public void getQualityTest(){
49
+        Item tape = new Item("Some new tape", 47,55);
50
+        int expectedQuality = 55;
51
+        int actualQuality = tape.getQuality();
52
+        Assert.assertEquals(expectedQuality, actualQuality);
53
+    }
54
+
55
+    @Test
56
+    public void setQualityTest(){
57
+        Item tape = new Item("Some new tape", 47,55);
58
+        int expectedQuality = 55;
59
+        tape.setQuality(55);
60
+        int actualQuality = tape.getQuality();
61
+        Assert.assertEquals(expectedQuality, actualQuality);
62
+    }
63
+
11
 }
64
 }
12
 
65