ThuyKhong 6 лет назад
Родитель
Сommit
768b0440f6
1 измененных файлов: 128 добавлений и 2 удалений
  1. 128
    2
      src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java

+ 128
- 2
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java Просмотреть файл

@@ -1,12 +1,138 @@
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
+
9
+    Item agedBrie = new Item("Aged Brie", 10, 45);
10
+    Item backstagePasses = new Item("Backstage passes to a TAFKAL80ETC concert", 15, 40);
11
+    Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 20, 35);
12
+    Item apples = new Item("Apples", 30,25);
13
+
14
+    Inventory inventory;
15
+
16
+    @Before
17
+    public void setUp(){
18
+        Item[] items = {agedBrie, backstagePasses, sulfuras};
19
+        inventory = new Inventory(items);
20
+    }
21
+
22
+    @Test
23
+    public void updateQualityTest_forAgedBrieWhenQualIsUnder50(){
24
+        int expected = agedBrie.getQuality() + 1;
25
+
26
+        inventory.updateQuality();
27
+
28
+        int actual = agedBrie.getQuality();
29
+        Assert.assertEquals(expected, actual);
30
+    }
31
+
32
+    @Test
33
+    public void updateQualityTest_forAgeBrieWhenQualityIs50(){
34
+        int expected = 50;
35
+        agedBrie.setQuality(expected);
36
+
37
+        inventory.updateQuality();
38
+
39
+        int actual = agedBrie.getQuality();
40
+        Assert.assertEquals(expected, actual);
41
+    }
42
+
43
+    @Test
44
+    public void updateQualityTest_forBackstagePassUnder50(){
45
+        int expected = backstagePasses.getQuality() + 1;
46
+
47
+        inventory.updateQuality();
48
+
49
+        int actual = backstagePasses.getQuality();
50
+        Assert.assertEquals(expected,actual);
51
+    }
52
+
53
+    @Test
54
+    public void updateQualityTest_forBackStagePassAt50(){
55
+        int expected = 51;
56
+        backstagePasses.setQuality(expected);
57
+
58
+        int actual = backstagePasses.getQuality();
59
+        Assert.assertEquals(expected,actual);
60
+    }
61
+
62
+    @Test
63
+    public void updateQualityTest_forSulfurasUnder50(){
64
+        int expected = sulfuras.getQuality();
65
+
66
+        inventory.updateQuality();
67
+
68
+        int actual = sulfuras.getQuality();
69
+        Assert.assertEquals(expected,actual);
70
+    }
71
+
72
+    @Test
73
+    public void updateQualityTest_forSulfurasAt50(){
74
+        int expected = 51;
75
+        sulfuras.setQuality(expected);
76
+
77
+        int actual = sulfuras.getQuality();
78
+        Assert.assertEquals(expected,actual);
79
+    }
80
+
81
+    @Test
82
+    public void updateQualityTest_forApplesUnder50(){
83
+        int expected = apples.getQuality();
84
+
85
+        inventory.updateQuality();
86
+
87
+        int actual = apples.getQuality();
88
+        Assert.assertEquals(expected,actual);
89
+    }
90
+
7 91
     @Test
8
-    public void updateQuantityTest(){
9
-        Assert.assertEquals(1, 1);
92
+    public void updateQualityTest_forApplesAt0(){
93
+        int expected = 0;
94
+        apples.setQuality(expected);
95
+
96
+        int actual = apples.getQuality();
97
+        Assert.assertEquals(expected,actual);
10 98
     }
99
+
100
+
101
+    @Test
102
+    public void testSetAndGetName(){
103
+        String name = "Aged Brie"  ;
104
+        agedBrie.setName(name);
105
+        String actual = agedBrie.getName();
106
+        Assert.assertEquals(name,actual);
107
+    }
108
+
109
+    @Test
110
+    public void testUpdateQuality_appleSellInPassed (){
111
+        Item[] items = {apples};
112
+        inventory = new Inventory(items);
113
+
114
+        apples.setSellIn(0);
115
+        int expected = apples.getQuality() - 2;
116
+
117
+        inventory.updateQuality();
118
+
119
+        int actual = apples.getQuality();
120
+        Assert.assertEquals(expected, actual);
121
+    }
122
+
123
+    public void testUpdateQuality_AgedBrieSellInAt10(){
124
+        agedBrie.setSellIn(10);
125
+        int expected = 47;
126
+        int actual = apples.getQuality();
127
+        Assert.assertEquals(actual,expected);
128
+    }
129
+
130
+    public void testUpdateQuality_AgedBrieSellInAt5(){
131
+        agedBrie.setSellIn(5);
132
+        int expected = 48;
133
+        int actual = agedBrie.getQuality();
134
+        Assert.assertEquals(actual,expected);
135
+    }
136
+
11 137
 }
12 138