瀏覽代碼

100 percent test coverage

mpierse 6 年之前
父節點
當前提交
357b05f41b
共有 1 個文件被更改,包括 177 次插入12 次删除
  1. 177
    12
      src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java

+ 177
- 12
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java 查看文件

@@ -9,48 +9,213 @@ public class InventoryTest {
9 9
     private String name;
10 10
     private int sellIn;
11 11
     private int quality;
12
-    private Item item;
12
+    private Item[] items;
13
+    private Inventory store;
14
+    private Item brie;
15
+    private Item ticket;
16
+    private Item legend;
17
+    private Item other;
13 18
 
14 19
     @Before
15 20
     public void setUp(){
16
-        item = new Item("Aged Brie", 5,25);
21
+        ticket = new Item("Backstage passes to a TAFKAL80ETC concert", 0,0);
22
+        brie = new Item ("Aged Brie", 0,50);
23
+        legend = new Item("Sulfuras, Hand of Ragnaros",0,50);
24
+        other = new Item("other", 5,5);
25
+        items =new Item[]{ brie, ticket, legend, other};
26
+        store = new Inventory(items);
17 27
 
18 28
     }
19 29
 
20 30
     @Test
21
-    public void updateQualityTest(){
22
-        Assert.assertEquals(1, 1);
31
+    public void sellInTest(){
32
+        int expected = 5;
33
+        int actual = other.getSellIn();
34
+        Assert.assertEquals(expected, actual);
23 35
     }
24 36
 
25 37
     @Test
26
-    public void getNameTest(){
27
-        item.setName("Aged Brie");
28
-        String actual = name;
38
+    public void nameTest (){
39
+        store.updateQuality();
29 40
         String expected = "Aged Brie";
30
-        Assert.assertEquals(expected, actual);
41
+        String actual = brie.getName();
42
+        Assert.assertEquals(expected,actual);
43
+    }
44
+
45
+    @Test
46
+    public void agedBrieQualityTest (){
47
+        store.updateQuality();
48
+        int expected =50;
49
+        int actual = brie.getQuality();
50
+        Assert.assertEquals(expected,actual);
51
+    }
52
+
53
+    @Test
54
+    public void agedBrieSellInTest (){
55
+        store.updateQuality();
56
+        int expected = -1;
57
+        int actual = brie.getSellIn();
58
+        Assert.assertEquals(expected,actual);
59
+    }
60
+
61
+    //expired test that
62
+
63
+    @Test // when expired quality increases by 2
64
+    public void agedBrieSellInExpiredTest (){
65
+        brie.setQuality(48);
66
+        store.updateQuality();
67
+        int expected = 50;
68
+        int actual = brie.getQuality();
69
+        Assert.assertEquals(expected,actual);
70
+    }
71
+
72
+    @Test
73
+    public void setSellInTest (){
74
+        brie.setSellIn(10);
75
+        int expected = 10;
76
+        int actual = brie.getSellIn();
77
+        Assert.assertEquals(expected,actual);
78
+    }
79
+
80
+    @Test
81
+    public void setQualityTest (){
82
+        brie.setQuality(10);
83
+        int expected = 10;
84
+        int actual = brie.getQuality();
85
+        Assert.assertEquals(expected,actual);
86
+    }
87
+
88
+    @Test
89
+    public void agedBrieSetSellInUpdateTest (){
90
+        brie.setSellIn(10);
91
+        store.updateQuality();
92
+        int expected = 9;
93
+        int actual = brie.getSellIn();
94
+        Assert.assertEquals(expected,actual);
95
+    }
96
+
97
+    @Test
98
+    public void agedBrieSetSellInQualityTest (){
99
+        brie.setSellIn(5);
100
+        brie.setQuality(45);
101
+        store.updateQuality();
102
+        int expected = 46;
103
+        int actual = brie.getQuality();
104
+        Assert.assertEquals(expected,actual);
105
+    }
106
+
107
+    @Test
108
+    public void ticketQualityTest (){
109
+        store.updateQuality();
110
+        int expected =0;
111
+        int actual = ticket.getQuality();
112
+        Assert.assertEquals(expected,actual);
113
+    }
114
+
115
+    @Test
116
+    public void ticketSellInTest (){
117
+        store.updateQuality();
118
+        int expected = -1;
119
+        int actual = ticket.getSellIn();
120
+        Assert.assertEquals(expected,actual);
121
+    }
122
+
123
+    @Test
124
+    public void ticketExpiredQualitySellInTest (){
125
+        ticket.setQuality(5);
126
+        store.updateQuality();
127
+        int expected = 0;
128
+        int actual = ticket.getQuality();
129
+        Assert.assertEquals(expected,actual);
130
+    }
31 131
 
132
+    @Test
133
+    public void ticketSetSellInUpdateTest (){
134
+        ticket.setSellIn(10);
135
+        store.updateQuality();
136
+        int expected = 9;
137
+        int actual = ticket.getSellIn();
138
+        Assert.assertEquals(expected,actual);
32 139
     }
33 140
 
34 141
     @Test
35
-    public void getSellInTest(){
142
+    public void ticketSetFarSellInUpdateTest (){
143
+        ticket.setSellIn(20);
144
+        store.updateQuality();
145
+        int expected = 1;
146
+        int actual = ticket.getQuality();
147
+        Assert.assertEquals(expected,actual);
148
+    }
36 149
 
150
+    @Test
151
+    public void ticketSetSellInQualityTest (){
152
+        ticket.setSellIn(5);
153
+        ticket.setQuality(35);
154
+        store.updateQuality();
155
+        int expected = 38;
156
+        int actual = ticket.getQuality();
157
+        Assert.assertEquals(expected,actual);
37 158
     }
38 159
 
39 160
     @Test
40
-    public void setSellInTest(){
161
+    public void legendQualityTest (){
162
+        store.updateQuality();
163
+        int expected = 50;
164
+        int actual = legend.getQuality();
165
+        Assert.assertEquals(expected,actual);
166
+    }
41 167
 
168
+    @Test
169
+    public void legendSetSellInUpdateTest (){
170
+        ticket.setSellIn(35);
171
+        store.updateQuality();
172
+        int expected = 0;
173
+        int actual = legend.getSellIn();
174
+        Assert.assertEquals(expected,actual);
42 175
     }
43 176
 
44 177
     @Test
45
-    public void getQualityTest(){
178
+    public void otherQualityTest (){
179
+        store.updateQuality();
180
+        int expected =4;
181
+        int actual = other.getQuality();
182
+        Assert.assertEquals(expected,actual);
183
+    }
46 184
 
185
+    @Test
186
+    public void otherNameTest (){
187
+        other.setName("Thing");
188
+        String expected ="Thing";
189
+        String actual = other.getName();
190
+        Assert.assertEquals(expected,actual);
47 191
     }
48 192
 
49 193
     @Test
50
-    public void setQualityTest(){
194
+    public void otherSetSellInUpdateTest (){
195
+        other.setSellIn(1);
196
+        store.updateQuality();
197
+        int expected = 0;
198
+        int actual = other.getSellIn();
199
+        Assert.assertEquals(expected,actual);
200
+    }
51 201
 
202
+    @Test
203
+    public void otherSetSellInExpiredUpdateTest (){
204
+        other.setSellIn(0);
205
+        store.updateQuality();
206
+        int expected = -1;
207
+        int actual = other.getSellIn();
208
+        Assert.assertEquals(expected,actual);
52 209
     }
53 210
 
211
+    @Test
212
+    public void otherQualityExpiredUpdateTest (){
213
+        other.setSellIn(-1);
214
+        store.updateQuality();
215
+        int expected = 3;
216
+        int actual = other.getQuality();
217
+        Assert.assertEquals(expected,actual);
218
+    }
54 219
 
55 220
 
56 221
 }