|
@@ -0,0 +1,179 @@
|
|
1
|
+import static org.junit.Assert.*;
|
|
2
|
+import java.util.Arrays;
|
|
3
|
+import org.junit.Test;
|
|
4
|
+
|
|
5
|
+public class InventoryTest {
|
|
6
|
+
|
|
7
|
+ @Test
|
|
8
|
+ public void should_never_changes_quailty_of_Sulfuras() throws Exception {
|
|
9
|
+ Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 0, 80);
|
|
10
|
+
|
|
11
|
+ Inventory sut = new Inventory((Item[]) Arrays.asList(new Item("Sulfuras, Hand of Ragnaros", 0, 80)).toArray());
|
|
12
|
+
|
|
13
|
+ sut.updateQuality();
|
|
14
|
+
|
|
15
|
+ assertEquals(80, sulfuras.getQuality());
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+ }
|
|
19
|
+ @Test
|
|
20
|
+ public void should_never_changes_sellIn_of_Sulfuras() throws Exception {
|
|
21
|
+ Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 0, 80);
|
|
22
|
+
|
|
23
|
+ Inventory sut = new Inventory((Item[]) Arrays.asList(sulfuras).toArray());
|
|
24
|
+
|
|
25
|
+ sut.updateQuality();
|
|
26
|
+
|
|
27
|
+ assertEquals(0, sulfuras.getSellIn());
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+ @Test
|
|
35
|
+ public void should_lower_the_sellIn_by_one_for_normal_items() throws Exception {
|
|
36
|
+ Item normalItem = new Item("+5 Dexterity Vest", 10, 20);
|
|
37
|
+
|
|
38
|
+ Inventory sut = new Inventory((Item[]) Arrays.asList(normalItem).toArray());
|
|
39
|
+
|
|
40
|
+ sut.updateQuality();
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+ assertEquals(9, normalItem.getSellIn());
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ @Test
|
|
47
|
+ public void should_lower_the_quality_by_one_for_normal_items() throws Exception {
|
|
48
|
+ Item normalItem = new Item("+5 Dexterity Vest", 10, 20);
|
|
49
|
+
|
|
50
|
+ Inventory sut = new Inventory((Item[]) Arrays.asList(normalItem).toArray());
|
|
51
|
+
|
|
52
|
+ sut.updateQuality();
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+ assertEquals(19, normalItem.getQuality());
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ @Test
|
|
59
|
+ public void should_not_lower_the_quality_below_zero() throws Exception {
|
|
60
|
+ Item normalItem = new Item("+5 Dexterity Vest", 10, 0);
|
|
61
|
+
|
|
62
|
+ Inventory sut = new Inventory((Item[]) Arrays.asList(normalItem).toArray());
|
|
63
|
+
|
|
64
|
+ sut.updateQuality();
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+ assertEquals(0, normalItem.getQuality());
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ @Test
|
|
71
|
+ public void should_lower_the_quality_twice_as_fast_once_the_sell_in_date_has_passed() throws Exception {
|
|
72
|
+ Item normalItem = new Item("+5 Dexterity Vest", -1, 25);
|
|
73
|
+
|
|
74
|
+ Inventory sut = new Inventory((Item[]) Arrays.asList(normalItem).toArray());
|
|
75
|
+
|
|
76
|
+ sut.updateQuality();
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+ assertEquals(23, normalItem.getQuality());
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+ @Test
|
|
84
|
+ public void should_increase_the_quality_of_aged_brie_as_it_gets_older() throws Exception {
|
|
85
|
+ Item agedBrie = new Item("Aged Brie", 10, 25);
|
|
86
|
+
|
|
87
|
+ Inventory sut = new Inventory((Item[]) Arrays.asList(agedBrie).toArray());
|
|
88
|
+
|
|
89
|
+ sut.updateQuality();
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+ assertEquals(26, agedBrie.getQuality());
|
|
93
|
+ }
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+ @Test
|
|
97
|
+ public void should_not_increase_the_quality_of_aged_brie_over_50() throws Exception {
|
|
98
|
+ Item agedBrie = new Item("Aged Brie", 10, 50);
|
|
99
|
+
|
|
100
|
+ Inventory sut = new Inventory((Item[]) Arrays.asList(agedBrie).toArray());
|
|
101
|
+
|
|
102
|
+ sut.updateQuality();
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+ assertEquals(50, agedBrie.getQuality());
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ @Test
|
|
109
|
+ public void should_lower_backstage_passes_to_zero_quality_once_concert_has_happened() throws Exception {
|
|
110
|
+ Item backStagePass = new Item("Backstage passes to a TAFKAL80ETC concert", -1, 20);
|
|
111
|
+
|
|
112
|
+ Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePass).toArray());
|
|
113
|
+
|
|
114
|
+ sut.updateQuality();
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+ assertEquals(0, backStagePass.getQuality());
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ @Test
|
|
121
|
+ public void should_increase_backstage_passes_quality_by_1_when_the_concert_is_more_than_10_days_away() throws Exception {
|
|
122
|
+ Item backStagePass = new Item("Backstage passes to a TAFKAL80ETC concert", 11, 20);
|
|
123
|
+
|
|
124
|
+ Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePass).toArray());
|
|
125
|
+
|
|
126
|
+ sut.updateQuality();
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+ assertEquals(21, backStagePass.getQuality());
|
|
130
|
+ }
|
|
131
|
+
|
|
132
|
+ @Test
|
|
133
|
+ public void should_increase_backstage_passes_quality_by_2_when_the_concert_is_10_days_or_less_away() throws Exception {
|
|
134
|
+ Item backStagePass = new Item("Backstage passes to a TAFKAL80ETC concert", 10, 27);
|
|
135
|
+
|
|
136
|
+ Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePass).toArray());
|
|
137
|
+
|
|
138
|
+ sut.updateQuality();
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+ assertEquals(29, backStagePass.getQuality());
|
|
142
|
+ }
|
|
143
|
+
|
|
144
|
+ @Test
|
|
145
|
+ public void should_increase_backstage_passes_quality_by_3_when_the_concert_is_5_days_or_less_away() throws Exception {
|
|
146
|
+ Item backStagePass = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 44);
|
|
147
|
+
|
|
148
|
+ Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePass).toArray());
|
|
149
|
+
|
|
150
|
+ sut.updateQuality();
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+ assertEquals(47, backStagePass.getQuality());
|
|
154
|
+ }
|
|
155
|
+
|
|
156
|
+ @Test
|
|
157
|
+ public void should_not_increase_backstage_passes_above_a_quality_of_50() throws Exception {
|
|
158
|
+ Item backStagePassMoreThan10DaysAway = new Item("Backstage passes to a TAFKAL80ETC concert", 15, 50);
|
|
159
|
+
|
|
160
|
+ Item backStagePass10DaysAway = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49);
|
|
161
|
+ Item backStagePass5DaysAway = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 48);
|
|
162
|
+
|
|
163
|
+ Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePassMoreThan10DaysAway, backStagePass10DaysAway, backStagePass5DaysAway).toArray());
|
|
164
|
+
|
|
165
|
+ sut.updateQuality();
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+ assertEquals(50, backStagePassMoreThan10DaysAway.getQuality());
|
|
169
|
+ assertEquals(50, backStagePass10DaysAway.getQuality());
|
|
170
|
+ assertEquals(50, backStagePass5DaysAway.getQuality());
|
|
171
|
+ }
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+}
|