diff --git a/.classpath b/.classpath
index 72c2ba6..2d74975 100644
--- a/.classpath
+++ b/.classpath
@@ -1,7 +1,7 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index 7341ab1..54e493c 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -1,11 +1,11 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.7
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.7
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/bin/fi/oulu/tol/sqat/GildedRose.class b/bin/fi/oulu/tol/sqat/GildedRose.class
index f244eba..74f547b 100644
Binary files a/bin/fi/oulu/tol/sqat/GildedRose.class and b/bin/fi/oulu/tol/sqat/GildedRose.class differ
diff --git a/bin/fi/oulu/tol/sqat/Item.class b/bin/fi/oulu/tol/sqat/Item.class
index 478a739..6f83438 100644
Binary files a/bin/fi/oulu/tol/sqat/Item.class and b/bin/fi/oulu/tol/sqat/Item.class differ
diff --git a/bin/fi/oulu/tol/sqat/tests/GildedRoseTest.class b/bin/fi/oulu/tol/sqat/tests/GildedRoseTest.class
index e44e81c..a78509e 100644
Binary files a/bin/fi/oulu/tol/sqat/tests/GildedRoseTest.class and b/bin/fi/oulu/tol/sqat/tests/GildedRoseTest.class differ
diff --git a/src/fi/oulu/tol/sqat/GildedRose.java b/src/fi/oulu/tol/sqat/GildedRose.java
index 24741c6..f7915a4 100644
--- a/src/fi/oulu/tol/sqat/GildedRose.java
+++ b/src/fi/oulu/tol/sqat/GildedRose.java
@@ -3,15 +3,19 @@
import java.util.ArrayList;
import java.util.List;
-
public class GildedRose {
+ private static final String SULFURAS_HAND_OF_RAGNAROS = "Sulfuras, Hand of Ragnaros";
+ private static final String AGED_BRIE = "Aged Brie";
+ private static final String BACKSTAGE_PASSES_TO_A_TAFKAL80ETC_CONCERT = "Backstage passes to a TAFKAL80ETC concert";
+ private static final int SELL_IN_VALUE_6 = 6;
+ private static final int SELL_IN_VALUE_11 = 11;
private static List- items = null;
public List
- getItems() {
return items;
}
-
+
public void addItem(Item item) {
items.add(item);
}
@@ -19,80 +23,38 @@ public void addItem(Item item) {
public GildedRose() {
items = new ArrayList
- ();
}
- public static void updateEndOfDay()
- {
- for (int i = 0; i < items.size(); i++)
- {
- if ((!"Aged Brie".equals(items.get(i).getName())) && !"Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))
- {
- if (items.get(i).getQuality() > 0)
- {
- if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName()))
- {
- items.get(i).setQuality(items.get(i).getQuality() - 1);
- }
- }
- }
- else
- {
- if (items.get(i).getQuality() < 50)
- {
- items.get(i).setQuality(items.get(i).getQuality() + 1);
-
- if ("Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))
- {
- if (items.get(i).getSellIn() < 11)
- {
- if (items.get(i).getQuality() < 50)
- {
- items.get(i).setQuality(items.get(i).getQuality() + 1);
- }
- }
-
- if (items.get(i).getSellIn() < 6)
- {
- if (items.get(i).getQuality() < 50)
- {
- items.get(i).setQuality(items.get(i).getQuality() + 1);
- }
- }
- }
- }
- }
- if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName()))
- {
- items.get(i).setSellIn(items.get(i).getSellIn() - 1);
- }
-
- if (items.get(i).getSellIn() < 0)
- {
- if (!"Aged Brie".equals(items.get(i).getName()))
- {
- if (!"Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))
- {
- if (items.get(i).getQuality() > 0)
- {
- if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName()))
- {
- items.get(i).setQuality(items.get(i).getQuality() - 1);
- }
- }
- }
- else
- {
- items.get(i).setQuality(items.get(i).getQuality() - items.get(i).getQuality());
- }
- }
- else
- {
- if (items.get(i).getQuality() < 50)
- {
- items.get(i).setQuality(items.get(i).getQuality() + 1);
- }
- }
- }
- }
- }
+ public static void updateEndOfDay() {
+ for (Item item : items) {
+ if (!SULFURAS_HAND_OF_RAGNAROS.equals(item.getName())) {
+ item = changeQuality(item);
+ item.decreaseSellIn();
+ if (item.isExpired()) {
+ item = changeQuality(item);
+ }
+ }
+ }
+ }
+ private static Item changeQuality(Item item) {
+ if (AGED_BRIE.equals(item.getName())) {
+ item.increaseQuality();
+ } else if (BACKSTAGE_PASSES_TO_A_TAFKAL80ETC_CONCERT.equals(item
+ .getName())) {
+ if (item.isExpired()) {
+ item.setQuality(item.getQuality() - item.getQuality());
+ } else {
+ item.increaseQuality();
+ if (item.getSellIn() < SELL_IN_VALUE_11) {
+ item.increaseQuality();
+ }
+ if (item.getSellIn() < SELL_IN_VALUE_6) {
+ item.increaseQuality();
+ }
+ }
+ } else {
+ item.decreaseQuality();
+ }
+ return item;
+ }
}
diff --git a/src/fi/oulu/tol/sqat/Item.java b/src/fi/oulu/tol/sqat/Item.java
index 447b7fe..1035528 100644
--- a/src/fi/oulu/tol/sqat/Item.java
+++ b/src/fi/oulu/tol/sqat/Item.java
@@ -1,35 +1,78 @@
package fi.oulu.tol.sqat;
-
public class Item {
- String name;
- int sellIn;
- int quality;
-
- public Item(String name, int sellIn, int quality) {
+ private static final int INCREMENT_VALUE = 1;
+ private static final int DECREMENT_VALUE = 1;
+ private static final int MINIMUM_SELL_IN = 0;
+ private static final int MINIMUM_QUALITY = 0;
+ private static final int MAXIMUM_QUALITY = 50;
+ String name;
+ int sellIn;
+ int quality;
+
+ public Item(String name, int sellIn, int quality) {
this.setName(name);
this.setSellIn(sellIn);
this.setQuality(quality);
}
-
+
/* Generated getter and setter code */
- public String getName() {
+ public String getName() {
return name;
}
+
public void setName(String name) {
this.name = name;
}
+
public int getSellIn() {
return sellIn;
}
+
public void setSellIn(int sellIn) {
this.sellIn = sellIn;
}
+
public int getQuality() {
return quality;
}
+
public void setQuality(int quality) {
this.quality = quality;
}
-}
+ public void increaseQuality() {
+ if (!hasReachedMaximumQuality()) {
+ this.quality = this.quality + INCREMENT_VALUE;
+ }
+ }
+
+ public void decreaseQuality() {
+ if (!hasZeroQuality()) {
+ this.quality = this.quality - DECREMENT_VALUE;
+ }
+ }
+
+ public void decreaseSellIn() {
+ this.sellIn = this.sellIn - DECREMENT_VALUE;
+ }
+
+ public boolean hasZeroQuality() {
+ if (this.quality == MINIMUM_QUALITY)
+ return true;
+ return false;
+ }
+
+ public boolean hasReachedMaximumQuality() {
+ if (this.quality == MAXIMUM_QUALITY)
+ return true;
+ return false;
+ }
+
+ public boolean isExpired() {
+ if (this.sellIn < MINIMUM_SELL_IN)
+ return true;
+ return false;
+ }
+
+}
diff --git a/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java b/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java
index 7aceb2e..ebc5956 100644
--- a/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java
+++ b/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java
@@ -2,7 +2,6 @@
import static org.junit.Assert.*;
-import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
@@ -36,7 +35,92 @@ public void testUpdateEndOfDay_AgedBrie_Quality_10_11() {
}
@Test
- public void testUpdateEndOfDay() {
- fail("Test not implemented");
+ public void testGildedRose_SellDatePasedQualityDecreasedTwice() {
+ // Arrange
+ GildedRose store = new GildedRose();
+ store.addItem(new Item("Elixir of the Mongoose", 2, 10) );
+
+ // Act
+ store.updateEndOfDay();
+ store.updateEndOfDay();
+ // Assert
+ List
- items = store.getItems();
+ Item item = items.get(0);
+ assertEquals(8, item.getQuality());
+ }
+
+ @Test
+ public void testGildedRose_QualityLessThanEqualTo50() {
+ // Arrange
+ GildedRose store = new GildedRose();
+ store.addItem(new Item("Aged Brie", 2, 50) );
+
+ // Act
+ store.updateEndOfDay();
+
+ // Assert
+ List
- items = store.getItems();
+ Item item = items.get(0);
+ assertEquals(50, item.getQuality());
+ }
+
+ @Test
+ public void testGildedRose_SulfurasQuality() {
+ // Arrange
+ GildedRose store = new GildedRose();
+ store.addItem(new Item("Sulfuras, Hand of Ragnaros", 0, 80) );
+
+ // Act
+ store.updateEndOfDay();
+
+ // Assert
+ List
- items = store.getItems();
+ Item item = items.get(0);
+ assertEquals(80, item.getQuality());
+ }
+
+ @Test
+ public void testGildedRose_BackstageQuality10days() {
+ // Arrange
+ GildedRose store = new GildedRose();
+ store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", 10, 10) );
+
+ // Act
+ store.updateEndOfDay();
+ // Assert
+ List
- items = store.getItems();
+ Item item = items.get(0);
+ assertEquals(12, item.getQuality());
+ }
+
+ @Test
+ public void testGildedRose_BackstageQuality5days() {
+ // Arrange
+ GildedRose store = new GildedRose();
+ store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", 5, 10) );
+
+ // Act
+ store.updateEndOfDay();
+ // Assert
+ List
- items = store.getItems();
+ Item item = items.get(0);
+ assertEquals(13, item.getQuality());
+ }
+
+
+ @Test
+ public void testGildedRose_BackstageQualityAfterTheConcert() {
+ // Arrange
+ GildedRose store = new GildedRose();
+ store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", 1, 10) );
+
+ // Act
+ store.updateEndOfDay();
+ store.updateEndOfDay();
+
+ // Assert
+ List
- items = store.getItems();
+ Item item = items.get(0);
+ assertEquals(0, item.getQuality());
}
}