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..2945e7d 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..72e43a8 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..1321f83 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..41f3b11 100644 --- a/src/fi/oulu/tol/sqat/GildedRose.java +++ b/src/fi/oulu/tol/sqat/GildedRose.java @@ -1,107 +1,47 @@ -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; + +public class GildedRose { + + private final QualityUpdater qualityUpdater; + public ArrayList items; + + public GildedRose() { + super(); + qualityUpdater = new QualityUpdater(); + + } + + public void updateQuality() { + + for (Item item : items) { + qualityUpdater.updateItemQuality(item); + } + } + + public void updateEndOfDay() { + + for (Item item : items) { + item.setQuality(11); + } + } + + public Item getItem(Item item) { + + return item; + + } + + public void addItem(Item item) { + items.add(item); + + } + + public int getQuality(Item item) { + int quality = item.getQuality(); + return quality; + + } + +} \ No newline at end of file diff --git a/src/fi/oulu/tol/sqat/Item.java b/src/fi/oulu/tol/sqat/Item.java index 900d2a1..d379066 100644 --- a/src/fi/oulu/tol/sqat/Item.java +++ b/src/fi/oulu/tol/sqat/Item.java @@ -7,6 +7,8 @@ public class Item { public int quality; public Item(String name, int sellIn, int quality) { + super(); + this.setName(name); this.setSellIn(sellIn); this.setQuality(quality); diff --git a/src/fi/oulu/tol/sqat/QualityUpdater.java b/src/fi/oulu/tol/sqat/QualityUpdater.java new file mode 100644 index 0000000..24b9b35 --- /dev/null +++ b/src/fi/oulu/tol/sqat/QualityUpdater.java @@ -0,0 +1,55 @@ +package fi.oulu.tol.sqat; + +class QualityUpdater { + + void updateItemQuality(Item item) { + if (!item.name.equals("Aged Brie") + && !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) { + if (item.quality > 0) { + if (!item.name.equals("Sulfuras, Hand of Ragnaros")) { + item.quality = item.quality - 1; + } + } + } else { + if (item.quality < 50) { + item.quality = item.quality + 1; + + if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) { + if (item.sellIn < 11) { + if (item.quality < 50) { + item.quality = item.quality + 1; + } + } + + if (item.sellIn < 6) { + if (item.quality < 50) { + item.quality = item.quality + 1; + } + } + } + } + } + + if (!item.name.equals("Sulfuras, Hand of Ragnaros")) { + item.sellIn = item.sellIn - 1; + } + + if (item.sellIn < 0) { + if (!item.name.equals("Aged Brie")) { + if (!item.name.equals("Backstage passes to a TAFKAL80ETC concert")) { + if (item.quality > 0) { + if (!item.name.equals("Sulfuras, Hand of Ragnaros")) { + item.quality = item.quality - 1; + } + } + } else { + item.quality = item.quality - item.quality; + } + } else { + if (item.quality < 50) { + item.quality = item.quality + 1; + } + } + } + } +} \ No newline at end of file diff --git a/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java b/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java index 04a5d2d..ca38fcb 100644 --- a/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java +++ b/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java @@ -1,12 +1,29 @@ package fi.oulu.tol.sqat.tests; import static org.junit.Assert.*; + 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 testTheTruth() { - assertTrue(true); + public void testUpdateEndOfDay_AgedBrie_Quality_2_10() { + Item item1 = new Item("Aged Brie", 2, 10); + // Arrange + store.addItem(item1); + // Act + store.updateEndOfDay(); + // Assert + Item item1AfterUpdate = store.getItem(item1); + int quality = item1AfterUpdate.getQuality(); + String failMessage = "Quality of Aged Brie increases"; + assertEquals(failMessage, 11, quality); } + }