Browse Source

convert to intellij

Nhu Nguyen 5 years ago
commit
b5427f2acb

+ 25
- 0
.gitignore View File

@@ -0,0 +1,25 @@
1
+/target/
2
+!.mvn/wrapper/maven-wrapper.jar
3
+
4
+### STS ###
5
+.apt_generated
6
+.classpath
7
+.factorypath
8
+.project
9
+.settings
10
+.springBeans
11
+.sts4-cache
12
+
13
+### IntelliJ IDEA ###
14
+.idea
15
+*.iws
16
+*.iml
17
+*.ipr
18
+
19
+### NetBeans ###
20
+/nbproject/private/
21
+/build/
22
+/nbbuild/
23
+/dist/
24
+/nbdist/
25
+/.nb-gradle/

+ 36
- 0
pom.xml View File

@@ -0,0 +1,36 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>com.zipcodewilmington</groupId>
8
+    <artifactId>gildedrose</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+    <properties>
11
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
13
+        <java.version>1.8</java.version>
14
+    </properties>
15
+    <build>
16
+        <plugins>
17
+            <plugin>
18
+                <groupId>org.apache.maven.plugins</groupId>
19
+                <artifactId>maven-compiler-plugin</artifactId>
20
+                <configuration>
21
+                    <source>1.8</source>
22
+                    <target>1.8</target>
23
+                </configuration>
24
+            </plugin>
25
+        </plugins>
26
+    </build>
27
+    <dependencies>
28
+        <dependency>
29
+            <groupId>junit</groupId>
30
+            <artifactId>junit</artifactId>
31
+            <version>4.12</version>
32
+            <scope>test</scope>
33
+        </dependency>
34
+    </dependencies>
35
+
36
+</project>

+ 86
- 0
readme.md View File

@@ -0,0 +1,86 @@
1
+# Clean Code
2
+
3
+### **Objective:**
4
+* To learn to read code and write test for the `Inventory` class
5
+* To refactor (aka clean up) the code in the `Inventory` class to make it more maintainable and readable
6
+
7
+### **Purpose:**
8
+* To understand why writing readable code matter
9
+
10
+### **Instructions:**
11
+
12
+1. Fork this Repository
13
+    * [fork](https://help.github.com/articles/fork-a-repo/) this repository to your personal github account
14
+    * [clone](https://help.github.com/articles/cloning-a-repository/) **your** `forked` repository to your local machine.
15
+    * clean up the code in the `Inventory` class
16
+    * commit your changes
17
+    * submit a `pull request` which compares Zipcoder `master` to your `master`.
18
+3. DO NOT CHANGE THE ITEM CLASS
19
+
20
+### See test coverage
21
+1. Right click on the `java` folder in the `test` directory
22
+2. Select `Run all with test coverage`
23
+3. Note a window pop up which display which line is covered
24
+
25
+# Part 1 - Original Description of the Gilded Rose
26
+
27
+Hi and welcome to team Gilded Rose. As you know, we are a small inn
28
+with a prime location in a prominent city run by a friendly innkeeper
29
+named Allison. We also buy and sell only the finest
30
+goods. Unfortunately, our goods are constantly degrading in quality as
31
+they approach their sell by date. We have a system in place that
32
+updates our inventory for us. It was developed by a no-nonsense type
33
+named Leeroy, who has moved on to new adventures. Your task is to add
34
+the new feature to our system so that we can begin selling a new
35
+category of items. But before you can add a new feature, you need to add a test
36
+that provides 100% line coverage for the `Inventory` class.
37
+
38
+
39
+First an introduction to our system:
40
+
41
+- All items have a SellIn value which denotes the number of days we
42
+  have to sell the item
43
+- All items have a Quality value which denotes how valuable the item
44
+  is
45
+- At the end of each day our system lowers both values for every item
46
+
47
+Pretty simple, right? Well this is where it gets interesting:
48
+
49
+  - Once the sell by date has passed, Quality degrades twice as fast
50
+  - The Quality of an item is never negative
51
+  - "Aged Brie" actually increases in Quality the older it gets
52
+  - The Quality of an item is never more than 50
53
+  - "Sulfuras", being a legendary item, never has to be sold or
54
+    decreases in Quality
55
+  - "Backstage passes", like aged brie, increases in Quality as it's
56
+    SellIn value approaches; Quality increases by 2 when there are 10
57
+    days or less and by 3 when there are 5 days or less but Quality
58
+    drops to 0 after the concert
59
+
60
+Just for clarification, an item can never have its Quality increase
61
+above 50, however "Sulfuras" is a legendary item and as such its
62
+Quality is 80 and it never alters.
63
+
64
+DO NOT alter the Item class or Items property as those belong to the goblin
65
+in the corner who will insta-rage and one-shot you as he doesn't
66
+believe in shared code ownership (you can make the UpdateQuality
67
+method and Items property static if you like, we'll cover for
68
+you).
69
+
70
+## Part 2 - Refactor the code
71
+
72
+Note how hard it is to read this code. Your task is to refactor the code to make it more readable. First create a new branch called `refactor`.
73
+
74
+
75
+
76
+## Part 3 - Add a new item
77
+
78
+We have recently signed a supplier of conjured items. This requires an update to our system. First create a new branch called `new-item`. Add a `conjured` item.
79
+
80
+- "Conjured" items degrade in Quality twice as fast as normal items
81
+
82
+Feel free to make any changes to the UpdateQuality method and add any
83
+new code as long as everything still works correctly.
84
+
85
+
86
+This originated from [Bobby Johnson's Blog](https://iamnotmyself.com/2011/02/13/refactor-this-the-gilded-rose-kata/).

+ 66
- 0
src/main/java/com/zipcodewilmington/gildedrose/Inventory.java View File

@@ -0,0 +1,66 @@
1
+package com.zipcodewilmington.gildedrose;
2
+
3
+
4
+public class Inventory {
5
+    private Item[] items;
6
+
7
+    public Inventory(Item[] items) {
8
+        super();
9
+        this.items = items;
10
+    }
11
+
12
+
13
+    public void updateQuality() {
14
+        for (int i = 0; i < items.length; i++) {
15
+            if (!items[i].getName().equals("Aged Brie")
16
+                    && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
17
+                if (items[i].getQuality() > 0) {
18
+                    if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
19
+                        items[i].setQuality(items[i].getQuality() - 1);
20
+                    }
21
+                }
22
+            } else {
23
+                if (items[i].getQuality() < 50) {
24
+                    items[i].setQuality(items[i].getQuality() + 1);
25
+
26
+                    if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert") {
27
+                        if (items[i].getSellIn() < 11) {
28
+                            if (items[i].getQuality() < 50) {
29
+                                items[i].setQuality(items[i].getQuality() + 1);
30
+                            }
31
+                        }
32
+
33
+                        if (items[i].getSellIn() < 6) {
34
+                            if (items[i].getQuality() < 50) {
35
+                                items[i].setQuality(items[i].getQuality() + 1);
36
+                            }
37
+                        }
38
+                    }
39
+                }
40
+            }
41
+
42
+            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
43
+                items[i].setSellIn(items[i].getSellIn() - 1);
44
+            }
45
+
46
+            if (items[i].getSellIn() < 0) {
47
+                if (!items[i].getName().equals("Aged Brie")) {
48
+                    if (!items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
49
+                        if (items[i].getQuality() > 0) {
50
+                            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
51
+                                items[i].setQuality(items[i].getQuality() - 1);
52
+                            }
53
+                        }
54
+                    } else {
55
+                        items[i].setQuality(items[i].getQuality()
56
+                                - items[i].getQuality());
57
+                    }
58
+                } else {
59
+                    if (items[i].getQuality() < 50) {
60
+                        items[i].setQuality(items[i].getQuality() + 1);
61
+                    }
62
+                }
63
+            }
64
+        }
65
+    }
66
+}

+ 38
- 0
src/main/java/com/zipcodewilmington/gildedrose/Item.java View File

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

+ 12
- 0
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java View File

@@ -0,0 +1,12 @@
1
+package com.zipcodewilmington.gildedrose;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class InventoryTest {
7
+    @Test
8
+    public void updateQuantityTest(){
9
+        Assert.assertEquals(1, 1);
10
+    }
11
+}
12
+