Explorar el Código

Merge branch 'master' of https://git.zipcode.rocks/woat/CleanCode-GildedRoseKata

Ahmad Rusdi hace 6 años
padre
commit
31e2d73742
Se han modificado 5 ficheros con 429 adiciones y 0 borrados
  1. 179
    0
      .gitignore
  2. 39
    0
      Inventory.java
  3. 122
    0
      InventoryTest.java
  4. 36
    0
      Item.java
  5. 53
    0
      package.bluej

+ 179
- 0
.gitignore Ver fichero

@@ -0,0 +1,179 @@
1
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
2
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
3
+
4
+# User-specific stuff:
5
+.idea/**/workspace.xml
6
+.idea/**/tasks.xml
7
+.idea/dictionaries
8
+
9
+# Sensitive or high-churn files:
10
+.idea/**/dataSources/
11
+.idea/**/dataSources.ids
12
+.idea/**/dataSources.xml
13
+.idea/**/dataSources.local.xml
14
+.idea/**/sqlDataSources.xml
15
+.idea/**/dynamic.xml
16
+.idea/**/uiDesigner.xml
17
+
18
+# Gradle:
19
+.idea/**/gradle.xml
20
+.idea/**/libraries
21
+
22
+# CMake
23
+cmake-build-debug/
24
+
25
+# Mongo Explorer plugin:
26
+.idea/**/mongoSettings.xml
27
+
28
+## File-based project format:
29
+*.iws
30
+
31
+## Plugin-specific files:
32
+
33
+# IntelliJ
34
+/out/
35
+
36
+# mpeltonen/sbt-idea plugin
37
+.idea_modules/
38
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
39
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
40
+
41
+# User-specific stuff:
42
+*.iml
43
+.idea/**
44
+.idea/**/workspace.xml
45
+.idea/**/tasks.xml
46
+.idea/dictionaries
47
+
48
+# Sensitive or high-churn files:
49
+.idea/**/dataSources/
50
+.idea/**/dataSources.ids
51
+.idea/**/dataSources.xml
52
+.idea/**/dataSources.local.xml
53
+.idea/**/sqlDataSources.xml
54
+.idea/**/dynamic.xml
55
+.idea/**/uiDesigner.xml
56
+
57
+# Gradle:
58
+.idea/**/gradle.xml
59
+.idea/**/libraries
60
+
61
+# CMake
62
+cmake-build-debug/
63
+
64
+# Mongo Explorer plugin:
65
+.idea/**/mongoSettings.xml
66
+
67
+## File-based project format:
68
+*.iws
69
+
70
+## Plugin-specific files:
71
+
72
+# IntelliJ
73
+/out/
74
+
75
+# mpeltonen/sbt-idea plugin
76
+.idea_modules/
77
+
78
+# JIRA plugin
79
+atlassian-ide-plugin.xml
80
+
81
+# Cursive Clojure plugin
82
+.idea/replstate.xml
83
+
84
+# Crashlytics plugin (for Android Studio and IntelliJ)
85
+com_crashlytics_export_strings.xml
86
+crashlytics.properties
87
+crashlytics-build.properties
88
+fabric.properties# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
89
+                 # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
90
+
91
+                 # User-specific stuff:
92
+                 .idea/**/workspace.xml
93
+                 .idea/**/tasks.xml
94
+                 .idea/dictionaries
95
+
96
+                 # Sensitive or high-churn files:
97
+                 .idea/**/dataSources/
98
+                 .idea/**/dataSources.ids
99
+                 .idea/**/dataSources.xml
100
+                 .idea/**/dataSources.local.xml
101
+                 .idea/**/sqlDataSources.xml
102
+                 .idea/**/dynamic.xml
103
+                 .idea/**/uiDesigner.xml
104
+
105
+                 # Gradle:
106
+                 .idea/**/gradle.xml
107
+                 .idea/**/libraries
108
+
109
+                 # CMake
110
+                 cmake-build-debug/
111
+
112
+                 # Mongo Explorer plugin:
113
+                 .idea/**/mongoSettings.xml
114
+
115
+                 ## File-based project format:
116
+                 *.iws
117
+
118
+                 ## Plugin-specific files:
119
+
120
+                 # IntelliJ
121
+                 /out/
122
+
123
+                 # mpeltonen/sbt-idea plugin
124
+                 .idea_modules/
125
+
126
+                 # JIRA plugin
127
+                 atlassian-ide-plugin.xml
128
+
129
+                 # Cursive Clojure plugin
130
+                 .idea/replstate.xml
131
+
132
+                 # Crashlytics plugin (for Android Studio and IntelliJ)
133
+                 com_crashlytics_export_strings.xml
134
+                 crashlytics.properties
135
+                 crashlytics-build.properties
136
+                 fabric.properties
137
+# JIRA plugin
138
+atlassian-ide-plugin.xml
139
+
140
+# Cursive Clojure plugin
141
+.idea/replstate.xml
142
+
143
+# Crashlytics plugin (for Android Studio and IntelliJ)
144
+com_crashlytics_export_strings.xml
145
+crashlytics.properties
146
+crashlytics-build.properties
147
+fabric.properties
148
+
149
+.project
150
+.classpath
151
+.settings
152
+
153
+
154
+#maven build target
155
+target/
156
+
157
+# ---> Java
158
+# Compiled class file
159
+*.class
160
+
161
+# Log file
162
+*.log
163
+
164
+# BlueJ files
165
+*.ctxt
166
+
167
+# Mobile Tools for Java (J2ME)
168
+.mtj.tmp/
169
+
170
+# Package Files #
171
+*.jar
172
+*.war
173
+*.ear
174
+*.zip
175
+*.tar.gz
176
+*.rar
177
+
178
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
179
+hs_err_pid*

+ 39
- 0
Inventory.java Ver fichero

@@ -0,0 +1,39 @@
1
+
2
+public class Inventory {
3
+    private Item[] items;
4
+
5
+    public Inventory(Item[] items) {
6
+        super();
7
+        this.items = items;
8
+    }
9
+
10
+    public void updateQuality() {
11
+        for (int i = 0; i < items.length; i++) {
12
+            if (!items[i].getName().equals("Aged Brie")) {
13
+                if (items[i].getQuality() > 0) {
14
+                    if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
15
+                        items[i].setQuality(items[i].getQuality() - 1);
16
+                    }
17
+                }
18
+            } else {
19
+                if (items[i].getQuality() < 50) {
20
+                    items[i].setQuality(items[i].getQuality() + 1);
21
+                }
22
+            }
23
+
24
+            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
25
+                items[i].setSellIn(items[i].getSellIn() - 1);
26
+            }
27
+
28
+            if (items[i].getSellIn() < 0) {
29
+                if (!items[i].getName().equals("Aged Brie")) {
30
+                  items[i].setQuality(items[i].getQuality() - 1);
31
+                } else {
32
+                    if (items[i].getQuality() < 50) {
33
+                        items[i].setQuality(items[i].getQuality() + 1);
34
+                    }
35
+                }
36
+            }
37
+        }
38
+}
39
+}

+ 122
- 0
InventoryTest.java Ver fichero

@@ -0,0 +1,122 @@
1
+import static org.junit.Assert.*;
2
+import java.util.Arrays;
3
+import org.junit.Test;
4
+import org.junit.Before;
5
+
6
+public class InventoryTest {
7
+    private static final int MAX_QUALITY = 50;
8
+    private static final String AGED_BRIE_NAME = "Aged Brie";
9
+    private static final String BACKSTAGE_PASS_NAME = "Backstage passes to a TAFKAL80ETC concert";
10
+    private static final String NORMAL_ITEM_NAME = "+5 Dexterity Vest";
11
+
12
+    private Item sulfuras;
13
+    private Item normalItem;
14
+
15
+    @Before
16
+    public void setup(){
17
+        sulfuras = new Item("Sulfuras, Hand of Ragnaros", 0, 80);
18
+        normalItem = new Item(NORMAL_ITEM_NAME, 10, 20);
19
+    }
20
+
21
+    @Test
22
+    public void testUpdate_ForSulfurasQuality() throws Exception {
23
+        int expectedQuality = sulfuras.getQuality();
24
+        Item[] items = {sulfuras};
25
+        Inventory sut = new Inventory(items);
26
+
27
+        sut.updateQuality();
28
+
29
+        assertEquals(expectedQuality, sulfuras.getQuality());
30
+    }
31
+    @Test
32
+    public void testUpdate_ForSulfurasSellIn() throws Exception {
33
+        int expectedSellIn = sulfuras.getSellIn();
34
+        Item[] items = {sulfuras};
35
+        Inventory sut = new Inventory(items);
36
+
37
+        sut.updateQuality();
38
+
39
+        assertEquals(expectedSellIn, sulfuras.getSellIn());
40
+    }
41
+
42
+    @Test
43
+    public void testUpdate_ForNormalItemSellIn() throws Exception {
44
+        int expectedSellIn = normalItem.getSellIn() - 1;
45
+        Item[] items = {normalItem};
46
+        Inventory sut = new Inventory(items);
47
+
48
+        sut.updateQuality();
49
+
50
+        assertEquals(expectedSellIn, normalItem.getSellIn());
51
+    }
52
+
53
+    @Test
54
+    public void testUpdate_ForNormalItemQuantity() throws Exception {
55
+        int expectedQuality = normalItem.getQuality() - 1;
56
+        Item[] items = {normalItem};
57
+        Inventory sut = new Inventory(items);
58
+
59
+        sut.updateQuality();
60
+
61
+        assertEquals(expectedQuality, normalItem.getQuality());
62
+    }
63
+
64
+    @Test
65
+    public void testUpdate_ForSoldOutItem() throws Exception {
66
+        int minimumQuality = 0;
67
+        Item normalItemWithMinimumQuality = new Item(NORMAL_ITEM_NAME, 10, minimumQuality);
68
+        Item[] items = {normalItemWithMinimumQuality};
69
+        Inventory sut = new Inventory(items);
70
+
71
+        sut.updateQuality();
72
+
73
+        assertEquals(minimumQuality, normalItemWithMinimumQuality.getQuality());
74
+    }
75
+
76
+    @Test
77
+    public void testUpdate_ForNormalItemOnceTheSellInDatePassed() throws Exception {
78
+        Item normalItemWithPassedSellDate = new Item(NORMAL_ITEM_NAME, -1, 25);
79
+        int expectedQuality = normalItemWithPassedSellDate.getQuality() - 2;
80
+        Item[] items = {normalItemWithPassedSellDate};
81
+        Inventory sut = new Inventory(items);
82
+
83
+        sut.updateQuality();
84
+
85
+        assertEquals(expectedQuality, normalItemWithPassedSellDate.getQuality());
86
+    }
87
+
88
+    @Test
89
+    public void testUpdate_AgedBrie() throws Exception {
90
+        Item agedBrie = new Item(AGED_BRIE_NAME, 10, 25);
91
+        int expectedQuality = agedBrie.getQuality() + 1;
92
+        Item[] items = {agedBrie};
93
+        Inventory sut = new Inventory(items);
94
+
95
+        sut.updateQuality();
96
+
97
+        assertEquals(expectedQuality, agedBrie.getQuality());
98
+    }
99
+
100
+    @Test
101
+    public void testUpdate_WhenAgedBrieIsAtMaxQuality() throws Exception {
102
+        Item agedBrie = new Item(AGED_BRIE_NAME, 10, MAX_QUALITY);
103
+        Item[] items = {agedBrie};
104
+        Inventory sut = new Inventory(items);
105
+
106
+        sut.updateQuality();
107
+
108
+        assertEquals(MAX_QUALITY, agedBrie.getQuality());
109
+    }
110
+
111
+    @Test
112
+    public void testUpdate_WhenAgedBrieOnceTheSellInDatePassed() throws Exception {
113
+        Item agedBrie = new Item(AGED_BRIE_NAME, -1, 20);
114
+        int expectedQuality = agedBrie.getQuality() + 2;
115
+        Item[] items = {agedBrie};
116
+        Inventory sut = new Inventory(items);
117
+
118
+        sut.updateQuality();
119
+
120
+        assertEquals(expectedQuality, agedBrie.getQuality());
121
+    }
122
+}

+ 36
- 0
Item.java Ver fichero

@@ -0,0 +1,36 @@
1
+public class Item {
2
+    private String name;
3
+    private int sellIn;
4
+    private int quality;
5
+
6
+    public Item(String name, int sellIn, int quality) {
7
+        super();
8
+        this.name = name;
9
+        this.sellIn = sellIn;
10
+        this.quality = quality;
11
+    }
12
+
13
+    public String getName() {
14
+        return name;
15
+    }
16
+
17
+    public void setName(String name) {
18
+        this.name = name;
19
+    }
20
+
21
+    public int getSellIn() {
22
+        return sellIn;
23
+    }
24
+
25
+    public void setSellIn(int sellIn) {
26
+        this.sellIn = sellIn;
27
+    }
28
+
29
+    public int getQuality() {
30
+        return quality;
31
+    }
32
+
33
+    public void setQuality(int quality) {
34
+        this.quality = quality;
35
+    }
36
+}

+ 53
- 0
package.bluej Ver fichero

@@ -0,0 +1,53 @@
1
+#BlueJ package file
2
+dependency1.from=InventoryTest
3
+dependency1.to=Item
4
+dependency1.type=UsesDependency
5
+dependency2.from=InventoryTest
6
+dependency2.to=Inventory
7
+dependency2.type=UsesDependency
8
+editor.fx.0.height=722
9
+editor.fx.0.width=800
10
+editor.fx.0.x=320
11
+editor.fx.0.y=50
12
+objectbench.height=164
13
+objectbench.width=776
14
+package.divider.horizontal=0.6
15
+package.divider.vertical=0.6845018450184502
16
+package.editor.height=364
17
+package.editor.width=674
18
+package.editor.x=577
19
+package.editor.y=61
20
+package.frame.height=600
21
+package.frame.width=800
22
+package.numDependencies=2
23
+package.numTargets=3
24
+package.showExtends=true
25
+package.showUses=true
26
+project.charset=UTF-8
27
+readme.height=58
28
+readme.name=@README
29
+readme.width=47
30
+readme.x=10
31
+readme.y=10
32
+target1.height=50
33
+target1.name=Item
34
+target1.showInterface=false
35
+target1.type=ClassTarget
36
+target1.width=80
37
+target1.x=10
38
+target1.y=100
39
+target2.height=50
40
+target2.name=InventoryTest
41
+target2.showInterface=false
42
+target2.type=UnitTestTargetJunit4
43
+target2.width=80
44
+target2.x=40
45
+target2.y=160
46
+target3.association=InventoryTest
47
+target3.height=50
48
+target3.name=Inventory
49
+target3.showInterface=false
50
+target3.type=ClassTarget
51
+target3.width=80
52
+target3.x=10
53
+target3.y=190