Browse Source

Curtis Cook's Clean Code Part 1

curtiscook 6 years ago
parent
commit
b9949c67a0
1 changed files with 64 additions and 2 deletions
  1. 64
    2
      src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java

+ 64
- 2
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java View File

@@ -4,9 +4,71 @@ import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6 6
 public class InventoryTest {
7
+
8
+    // Given
9
+    Item agedBrie = new Item("Aged Brie", 10, 5);
10
+    Item backstagePasses = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 10);
11
+    Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 15, 15);
12
+    Item random = new Item("Random Items", 0, 7);
13
+    Item[] items = {agedBrie, backstagePasses, sulfuras, random};
14
+    Inventory inventory = new Inventory(items);
15
+
16
+    @Test
17
+    public void updateQuantityTest() {
18
+        // Given
19
+        agedBrie.setSellIn(10);
20
+        int expected = 10 - 1;
21
+
22
+        //  When
23
+        inventory.updateQuality();
24
+        int actual = agedBrie.getSellIn();
25
+
26
+        // Then
27
+        Assert.assertEquals(expected, actual);
28
+    }
29
+
7 30
     @Test
8
-    public void updateQuantityTest(){
9
-        Assert.assertEquals(1, 1);
31
+    public void updateQuantityTest2() {
32
+        // Given
33
+        random.setName("Plan Old Java Objects");
34
+        int expected = 0 - 1;
35
+
36
+        // When
37
+        inventory.updateQuality();
38
+        int actual = random.getSellIn();
39
+
40
+        // Then
41
+        Assert.assertEquals(expected, actual);
42
+    }
43
+
44
+    @Test
45
+    public void updateQuantityTest3() {
46
+        // Given
47
+        backstagePasses.setSellIn(-5);
48
+        backstagePasses.setQuality(75);
49
+        int expected = 75 - 75;
50
+
51
+        // When
52
+        inventory.updateQuality();
53
+        int actual = backstagePasses.getQuality();
54
+
55
+        // Then
56
+        Assert.assertEquals(expected, actual);
57
+    }
58
+
59
+    @Test
60
+    public void updateQuantityTest4() {
61
+        // Given
62
+        agedBrie.setSellIn(-7);
63
+        agedBrie.setQuality(41);
64
+        int expected = 41 + 1 + 1;
65
+
66
+        // When
67
+        inventory.updateQuality();
68
+        int actual = agedBrie.getQuality();
69
+
70
+        // Then
71
+        Assert.assertEquals(expected, actual);
10 72
     }
11 73
 }
12 74