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..cd7bf86 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..a838538 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..b4c5d52 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..2449b0b 100644 --- a/src/fi/oulu/tol/sqat/GildedRose.java +++ b/src/fi/oulu/tol/sqat/GildedRose.java @@ -21,74 +21,74 @@ public GildedRose() { } public static void updateEndOfDay() { - for (int i = 0; i < items.size(); i++) + for (Item item: items) { - if ((!"Aged Brie".equals(items.get(i).getName())) && !"Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName())) + if ((!"Aged Brie".equals(item.getName())) && !"Backstage passes to a TAFKAL80ETC concert".equals(item.getName())) { - if (items.get(i).getQuality() > 0) + if (item.hasPositiveQuality()) { - if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName())) + if (!"Sulfuras, Hand of Ragnaros".equals(item.getName())) { - items.get(i).setQuality(items.get(i).getQuality() - 1); + item.setQuality(item.getQuality() - 1); } } } else { - if (items.get(i).getQuality() < 50) + if (item.canIncreaseQuality()) { - items.get(i).setQuality(items.get(i).getQuality() + 1); + item.setQuality(item.getQuality() + 1); - if ("Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName())) + if ("Backstage passes to a TAFKAL80ETC concert".equals(item.getName())) { - if (items.get(i).getSellIn() < 11) + if (item.getSellIn() < 11) { - if (items.get(i).getQuality() < 50) + if (item.canIncreaseQuality()) { - items.get(i).setQuality(items.get(i).getQuality() + 1); + item.setQuality(item.getQuality() + 1); } } - if (items.get(i).getSellIn() < 6) + if (item.getSellIn() < 6) { - if (items.get(i).getQuality() < 50) + if (item.getQuality() < 50) { - items.get(i).setQuality(items.get(i).getQuality() + 1); + item.setQuality(item.getQuality() + 1); } } } } } - if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName())) + if (!"Sulfuras, Hand of Ragnaros".equals(item.getName())) { - items.get(i).setSellIn(items.get(i).getSellIn() - 1); + item.setSellIn(item.getSellIn() - 1); } - if (items.get(i).getSellIn() < 0) + if (item.hasExpired()) { - if (!"Aged Brie".equals(items.get(i).getName())) + if (!"Aged Brie".equals(item.getName())) { - if (!"Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName())) + if (!"Backstage passes to a TAFKAL80ETC concert".equals(item.getName())) { - if (items.get(i).getQuality() > 0) + if (item.hasPositiveQuality()) { - if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName())) + if (!"Sulfuras, Hand of Ragnaros".equals(item.getName())) { - items.get(i).setQuality(items.get(i).getQuality() - 1); + item.setQuality(item.getQuality() - 1); } } } else { - items.get(i).setQuality(items.get(i).getQuality() - items.get(i).getQuality()); + item.setQuality(item.getQuality() - item.getQuality()); } } else { - if (items.get(i).getQuality() < 50) + if (item.canIncreaseQuality()) { - items.get(i).setQuality(items.get(i).getQuality() + 1); + item.setQuality(item.getQuality() + 1); } } } diff --git a/src/fi/oulu/tol/sqat/Item.java b/src/fi/oulu/tol/sqat/Item.java index 447b7fe..68b92af 100644 --- a/src/fi/oulu/tol/sqat/Item.java +++ b/src/fi/oulu/tol/sqat/Item.java @@ -31,5 +31,29 @@ public int getQuality() { public void setQuality(int quality) { this.quality = quality; } + public void decreaseQuality(int amount) { + this.quality -= amount; + } + public void increaseQuality(int amount) { + this.quality += amount; + } + public void increaseSellIn(int amount) { + this.sellIn += amount; + } + public void decreaseSellIn(int amount) { + this.sellIn -= amount; + } + public boolean hasPositiveQuality() { + if (this.quality > 0) return true; + return false; + } + public boolean canIncreaseQuality() { + if (this.quality < 50) return true; + return false; + } + public boolean hasExpired() { + if (this.sellIn < 0) 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..ea66643 100644 --- a/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java +++ b/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java @@ -1,42 +1,254 @@ 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 { - -// Example scenarios for testing -// Item("+5 Dexterity Vest", 10, 20)); -// Item("Aged Brie", 2, 0)); -// Item("Elixir of the Mongoose", 5, 7)); -// Item("Sulfuras, Hand of Ragnaros", 0, 80)); -// Item("Backstage passes to a TAFKAL80ETC concert", 15, 20)); -// Item("Conjured Mana Cake", 3, 6)); - - @Test - public void testUpdateEndOfDay_AgedBrie_Quality_10_11() { - // Arrange - GildedRose store = new GildedRose(); + + 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 - List items = store.getItems(); - Item itemBrie = items.get(0); - assertEquals(11, itemBrie.getQuality()); + 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); + } + @Test + 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() { - fail("Test not implemented"); + 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