diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..76b3e7b --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/fi/ diff --git a/bin/fi/oulu/tol/sqat/GildedRose.class b/bin/fi/oulu/tol/sqat/GildedRose.class index f244eba..840fc35 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..bf798c8 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..1d2b0a1 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 8d48732..e3b2b2e 100644 --- a/src/fi/oulu/tol/sqat/GildedRose.java +++ b/src/fi/oulu/tol/sqat/GildedRose.java @@ -1,107 +1,95 @@ -package fi.oulu.tol.sqat; - -import java.util.ArrayList; -import java.util.List; - - -public class GildedRose { - - private static List items = null; - - /** - * @param args - */ - public static void main(String[] args) { - - System.out.println("OMGHAI!"); - - items = new ArrayList(); - items.add(new Item("+5 Dexterity Vest", 10, 20)); - items.add(new Item("Aged Brie", 2, 0)); - items.add(new Item("Elixir of the Mongoose", 5, 7)); - items.add(new Item("Sulfuras, Hand of Ragnaros", 0, 80)); - items.add(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20)); - items.add(new Item("Conjured Mana Cake", 3, 6)); - - updateQuality(); -} - - - - public static void updateQuality() - { - 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); - } - } - } - } - } - -} +package fi.oulu.tol.sqat; + +import java.util.ArrayList; +import java.util.List; + + +public class GildedRose { + + private static List items = null; + + public List getItems() { + return items; + } + + public void addItem(Item item) { + items.add(item); + } + + public GildedRose() { + items = new ArrayList(); + } + public static void updateEndOfDay() + { + for(Item item:items) + { + if ((!"Aged Brie".equals(item.getName())) && !"Backstage passes to a TAFKAL80ETC concert".equals(item.getName())) + { + if (!item.hasZeroQuality()) + { + if (!"Sulfuras, Hand of Ragnaros".equals(item.getName())) + { + item.decreaseQuality(); + } + } + } + else + { + if (!item.hasReachedMaximumQuality()) + { + item.increaseQuality(); + if ("Backstage passes to a TAFKAL80ETC concert".equals(item.getName())) + { + if (item.getSellIn() < 11) + { + if (!item.hasReachedMaximumQuality()) + { + item.increaseQuality(); + } + + if (item.getSellIn() < 6) + { + if (!item.hasReachedMaximumQuality()) + { + item.increaseQuality(); + } + } + } + } + } + + if (!"Sulfuras, Hand of Ragnaros".equals(item.getName())) + { + item.decreaseSellIn(); + } + + if (item.isExpired()) + { + if (!"Aged Brie".equals(item.getName())) + { + if (!"Backstage passes to a TAFKAL80ETC concert".equals(item.getName())) + { + if (!item.hasZeroQuality())// change + { + if (!"Sulfuras, Hand of Ragnaros".equals(item.getName())) + { + item.decreaseQuality(); + } + } + } + else + { + item.setQuality(item.getQuality() - item.getQuality()); + } + } + else + { + if (!item.hasReachedMaximumQuality()) + { + item.increaseQuality(); + } + } + } + } + } + } diff --git a/src/fi/oulu/tol/sqat/Item.java b/src/fi/oulu/tol/sqat/Item.java index 900d2a1..8f6d6b1 100644 --- a/src/fi/oulu/tol/sqat/Item.java +++ b/src/fi/oulu/tol/sqat/Item.java @@ -1,35 +1,57 @@ -package fi.oulu.tol.sqat; - - -public class Item { - public String name; - public int sellIn; - public 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() { - 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; - } -} - +package fi.oulu.tol.sqat; + + +public class Item { + public String name; + public int sellIn; + public int quality; + private static final int MAX_QUALITY =50; + + 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() { + 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 decreaseQuality(){ + setQuality(getQuality() -1 ); + } + public void increaseQuality(){ + setQuality(getQuality() +1 ); + } + public void decreaseSellIn(){ + setSellIn(getSellIn() -1); + } + public void increaseSellIn(){ + setSellIn(getSellIn() +1); + } + public boolean isExpired(){ + return getSellIn() <0; + } + public boolean hasZeroQuality(){ + return getQuality() == 0; + } + public boolean hasReachedMaximumQuality(){ + return getQuality() == MAX_QUALITY; + } +} + diff --git a/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java b/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java index 04a5d2d..0b83417 100644 --- a/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java +++ b/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java @@ -1,12 +1,246 @@ -package fi.oulu.tol.sqat.tests; - -import static org.junit.Assert.*; -import org.junit.Test; - -public class GildedRoseTest { - - @Test - public void testTheTruth() { - assertTrue(true); - } -} +package fi.oulu.tol.sqat.tests; +import static org.junit.Assert.*; +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; +import fi.oulu.tol.sqat.GildedRose; +import fi.oulu.tol.sqat.Item; +public class GildedRoseTest { + + GildedRose store = new GildedRose(); + // Test Aged Brie + @Test + public void testUpdateEndOfDay_AgedBrie_Quality_2_10() { + // Arrange + store.addItem(new Item("Aged Brie", 2, 10) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Aged Brie increases"; + assertEquals(failMessage, 11,quality); + } + @Test + public void testUpdateEndOfDay_AgedBrie_Quality_10_50() { + // Arrange + store.addItem(new Item("Aged Brie", 10, 50) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "The Quality of an item is never more than 50"; + assertEquals(failMessage, 50, quality); + } + @Test + public void testUpdateEndOfDay_AgedBrie_Quality_0_10() { + // Arrange + store.addItem(new Item("Aged Brie", 0, 10) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "The Quality of Aged Brie increases twice after SellIn date has passed"; + assertEquals(failMessage, 12, quality); + } + @Test + public void testUpdateEndOfDay_AgedBrie_Quality_0_50() { + // Arrange + store.addItem(new Item("Aged Brie", 0, 50) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "The Quality of Aged Brie is never more than 50 increases twice after SellIn date has passed"; + assertEquals(failMessage, 50, quality); + } + @Test + public void testUpdateEndOfDay_AgedBrie_Quality_Minus1_20() { + // Arrange + store.addItem(new Item("Aged Brie", -1, 20) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "The Quality of Aged Brie increases twice after SellIn date has passed"; + assertEquals(failMessage, 22, quality); + } + @Test + public void testUpdateEndOfDay_AgedBrie_SellIn_2_10() { + // Arrange + store.addItem(new Item("Aged Brie", 2, 10) ); + // Act + store.updateEndOfDay(); + // Assert + int sellIn = store.getItems().get(0).getSellIn(); + String failMessage = "SellIn date decreases"; + assertEquals(failMessage, 1, sellIn); + } + @Test + public void testUpdateEndOfDay_AgedBrie_SellIn_1_10() { + // Arrange + store.addItem(new Item("Aged Brie", 1, 10) ); + // Act + store.updateEndOfDay(); + // Assert + int sellIn = store.getItems().get(0).getSellIn(); + String failMessage = "SellIn date decreases"; + assertEquals(failMessage, 0, sellIn); + } + @Test + public void testUpdateEndOfDay_AgedBrie_SellIn_0_10() { + // Arrange + store.addItem(new Item("Aged Brie", 0, 10) ); + // Act + store.updateEndOfDay(); + // Assert + int sellIn = store.getItems().get(0).getSellIn(); + String failMessage = "SellIn date decreases"; + assertEquals(failMessage, -1, sellIn); + } + // Test Sulfuras + @Test + public void testUpdateEndOfDay_Sulfuras_Quality_0_80() { + // Arrange + store.addItem(new Item("Sulfuras, Hand of Ragnaros", 0, 80) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Sulfuras is 80 and never alters"; + assertEquals(failMessage, 80, quality); + } + @Test + public void testUpdateEndOfDay_Sulfuras_SellIn_5_80() { + // Arrange + store.addItem(new Item("Sulfuras, Hand of Ragnaros", 5, 80) ); + // Act + store.updateEndOfDay(); + // Assert + int sellIn = store.getItems().get(0).getSellIn(); + String failMessage = "Sulfuras, being a legendary item, never has to be sold"; + assertEquals(failMessage, 5, sellIn); + } + @Test + public void testUpdateEndOfDay_Sulfuras_SellIn_0_80() { + // Arrange + store.addItem(new Item("Sulfuras, Hand of Ragnaros", 0, 80) ); + // Act + store.updateEndOfDay(); + // Assert + int sellIn = store.getItems().get(0).getSellIn(); + String failMessage = "Sulfuras, being a legendary item, never has to be sold"; + assertEquals(failMessage, 0, sellIn); + } + + // Test Backstage pass + @Test + public void testUpdateEndOfDay_Backstage_Quality_15_20() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Backstage pass increases by 1 when there are more than 10 days"; + assertEquals(failMessage, 21, quality); + } + @Test + public void testUpdateEndOfDay_Backstage_Quality_10_20() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", 10, 20) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Backstage pass increases by 2 when there are 10 or less days"; + assertEquals(failMessage, 22, quality); + } + public void testUpdateEndOfDay_Backstage_Quality_8_20() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", 8, 20) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Backstage pass increases by 2 when there are 10 or less days"; + assertEquals(failMessage, 22, quality); + } + @Test + public void testUpdateEndOfDay_Backstage_Quality_5_20() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", 5, 20) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Backstage pass increases by 3 when there are 5 or less days"; + assertEquals(failMessage, 23, quality); + } + @Test + public void testUpdateEndOfDay_Backstage_Quality_3_20() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", 3, 20) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Backstage pass increases by 3 when there are 5 or less days"; + assertEquals(failMessage, 23, quality); + } + @Test + public void testUpdateEndOfDay_Backstage_Quality_0_20() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", 0, 20) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Backstage drops to 0 after the concert"; + assertEquals(failMessage, 0, quality); + } + @Test + public void testUpdateEndOfDay_Backstage_Quality_15_50() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 50) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "The Quality of an item is never more than 50"; + assertEquals(failMessage, 50, quality); + } + @Test + public void testUpdateEndOfDay_Backstage_SellIn_5_10() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", 5, 10) ); + // Act + store.updateEndOfDay(); + // Assert + int sellIn = store.getItems().get(0).getSellIn(); + String failMessage = "The SellIn value should decrease by 1"; + assertEquals(failMessage, 4, sellIn); + } + // Test Elixir + @Test + public void testUpdateEndOfDay_Elixir_Quality_2_7() { + // Arrange + store.addItem(new Item("Elixir of the Mongoose", 2, 7) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality decreases by 1"; + assertEquals(failMessage, 6,quality); + } + @Test + public void testUpdateEndOfDay_SellIn_Quality_2_7() { + // Arrange + store.addItem(new Item("Elixir of the Mongoose", 2, 7) ); + // Act + store.updateEndOfDay(); + // Assert + int sellIn = store.getItems().get(0).getSellIn(); + String failMessage = "SelIn decreases by 1"; + assertEquals(failMessage, 1, sellIn); + } + } \ No newline at end of file