瀏覽代碼

part 1 complete

Christian Sheridan 6 年之前
父節點
當前提交
9d419d1d27
共有 1 個檔案被更改,包括 124 行新增0 行删除
  1. 124
    0
      src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java

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

@@ -1,6 +1,7 @@
1 1
 package com.zipcodewilmington.gildedrose;
2 2
 
3 3
 import org.junit.Assert;
4
+import org.junit.Before;
4 5
 import org.junit.Test;
5 6
 
6 7
 public class InventoryTest {
@@ -8,5 +9,128 @@ public class InventoryTest {
8 9
     public void updateQuantityTest(){
9 10
         Assert.assertEquals(1, 1);
10 11
     }
12
+
13
+    Item item;
14
+    Item item1;
15
+    Item agedBrie;
16
+    Item backStage;
17
+    Item backStage2;
18
+    Item sulfuras;
19
+    Inventory inventory;
20
+    Item[] testItem;
21
+
22
+    @Before
23
+    public void initialize(){
24
+        //given
25
+        item = new Item("Ticket", 2,2);
26
+        item1 = new Item("Not Brie", -1, 2);
27
+        agedBrie = new Item("Aged Brie", -1, 4);
28
+        backStage = new Item ("Backstage passes to a TAFKAL80ETC concert", 4, 3);
29
+        backStage2 = new Item ("Backstage passes to a TAFKAL80ETC concert", -1, 3);
30
+        sulfuras = new Item ("Sulfuras, Hand of Ragnaros", 4, 3);
31
+        testItem = new Item[]{agedBrie, backStage, sulfuras, item, item1, backStage2};
32
+        inventory = new Inventory(testItem);
33
+    }
34
+
35
+    @Test
36
+    public void getQualityTest(){
37
+        //when
38
+        int expected = 2;
39
+        int actual = item.getQuality();
40
+
41
+        //Then
42
+        Assert.assertEquals(expected, actual);
43
+    }
44
+
45
+    @Test
46
+    public void getNameTest(){
47
+        //when
48
+        String expected = "Ticket";
49
+        String actual = item.getName();
50
+
51
+        //then
52
+          Assert.assertEquals(expected, actual);
53
+    }
54
+
55
+    @Test
56
+    public void getSellIn(){
57
+        //when
58
+        int expected = 2;
59
+        int actual = item.getSellIn();
60
+
61
+        //then
62
+        Assert.assertEquals(expected, actual);
63
+    }
64
+
65
+    @Test
66
+    public void setQualityTest(){
67
+        item.setQuality(1);
68
+        int actual = item.getQuality();
69
+        int expected = 1;
70
+
71
+        Assert.assertEquals(expected, actual);
72
+    }
73
+
74
+    @Test
75
+    public void setNameTest(){
76
+        item.setName("Ticket");
77
+        String actual = item.getName();
78
+        String expected = "Ticket";
79
+
80
+        Assert.assertEquals(expected, actual);
81
+    }
82
+
83
+    @Test
84
+    public void setSellIn(){
85
+        item.setSellIn(3);
86
+        int actual = item.getSellIn();
87
+        int expected = 3;
88
+
89
+        Assert.assertEquals(expected, actual);
90
+    }
91
+
92
+    @Test
93
+    public void agedBrieTest(){
94
+        int actual = agedBrie.getQuality() - 1;
95
+        int expected = 3;
96
+
97
+        Assert.assertEquals(expected, actual);
98
+    }
99
+
100
+    @Test
101
+    public void sulfurasTest(){
102
+        int actual = sulfuras.getQuality() -1;
103
+        int expected = 2;
104
+
105
+        Assert.assertEquals(expected, actual);
106
+    }
107
+
108
+    @Test
109
+    public void backStageTest(){
110
+        int actual = backStage.getQuality()-1;
111
+        int expected = 2;
112
+
113
+        Assert.assertEquals(expected, actual);
114
+    }
115
+
116
+
117
+    @Test
118
+    public void notNames(){
119
+        int before = item1.getQuality();
120
+        int expected = 0;
121
+        inventory.updateQuality();
122
+        int actual = item1.getQuality();
123
+
124
+        Assert.assertEquals(expected, actual);
125
+    }
126
+
127
+    @Test
128
+    public void lastTest(){
129
+        int actual = 6;
130
+        inventory.updateQuality();
131
+        int expected = agedBrie.getQuality();
132
+
133
+        Assert.assertEquals(actual, expected);
134
+    }
11 135
 }
12 136