mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Add Conjured item to business logic
This commit is contained in:
parent
79851ff2e9
commit
c3b2ebe7af
19
Java/src/main/java/com/gildedrose/Conjured.java
Normal file
19
Java/src/main/java/com/gildedrose/Conjured.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.gildedrose;
|
||||
|
||||
public class Conjured extends InventoryItem {
|
||||
public Conjured(Item item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
void age() {
|
||||
decreaseQuality();
|
||||
decreaseSellIn();
|
||||
if (item.sellIn < Constants.SELLIN_DAY) decreaseQuality();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decreaseQuality() {
|
||||
if (item.quality > Constants.MIN_QUALITY) item.quality -= 2;
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@ public final class Constants {
|
||||
public static final String BACKSTAGE = "Backstage passes to a TAFKAL80ETC concert";
|
||||
public static final String AGED_BRIE = "Aged Brie";
|
||||
public static final String SULFURAS = "Sulfuras, Hand of Ragnaros";
|
||||
public static final String CONJURED = "Conjured Mana Cake";
|
||||
public static final int MAX_QUALITY = 50;
|
||||
public static final int MIN_QUALITY = 0;
|
||||
public static final int SELLIN_DAY = 0;
|
||||
|
||||
@ -13,13 +13,14 @@ public class InventoryItem {
|
||||
if (item.name.equals(SULFURAS)) return new Sulfuras(item);
|
||||
if (item.name.equals(AGED_BRIE)) return new AgedBrie(item);
|
||||
if (item.name.equals(BACKSTAGE)) return new Backstage(item);
|
||||
if (item.name.equals(CONJURED)) return new Conjured(item);
|
||||
return new InventoryItem(item);
|
||||
}
|
||||
|
||||
void age() {
|
||||
decreaseQuality();
|
||||
decreaseSellIn();
|
||||
if (item.sellIn < 0) decreaseQuality();
|
||||
if (item.sellIn < Constants.SELLIN_DAY) decreaseQuality();
|
||||
}
|
||||
|
||||
protected void decreaseSellIn() {
|
||||
@ -27,6 +28,6 @@ public class InventoryItem {
|
||||
}
|
||||
|
||||
protected void decreaseQuality() {
|
||||
if (item.quality > 0) item.quality--;
|
||||
if (item.quality > Constants.MIN_QUALITY) item.quality--;
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,14 +30,14 @@ class GildedRoseTest {
|
||||
|
||||
@Test
|
||||
void increaseAgedBrieQualityWhenItGetsOlder() {
|
||||
Item[] items = new Item[]{new Item("Aged Brie", 0, 2)};
|
||||
Item[] items = new Item[]{new Item(Constants.AGED_BRIE, 0, 2)};
|
||||
GildedRose.updateQuality(new GildedRose(items));
|
||||
assertEquals(4, items[0].quality);
|
||||
}
|
||||
|
||||
@Test
|
||||
void neverMustHaveAnItemWithMoreThan50OfQuality() {
|
||||
Item[] items = new Item[]{new Item("Aged Brie", 0, 50)};
|
||||
Item[] items = new Item[]{new Item(Constants.AGED_BRIE, 0, 50)};
|
||||
GildedRose.updateQuality(new GildedRose(items));
|
||||
assertEquals(50, items[0].quality);
|
||||
}
|
||||
@ -45,26 +45,33 @@ class GildedRoseTest {
|
||||
|
||||
@Test
|
||||
void neverModifySulfurasQuality() {
|
||||
Item[] items = new Item[]{new Item("Sulfuras, Hand of Ragnaros", 0, 50)};
|
||||
Item[] items = new Item[]{new Item(Constants.SULFURAS, 0, 50)};
|
||||
GildedRose.updateQuality(new GildedRose(items));
|
||||
assertEquals(50, items[0].quality);
|
||||
}
|
||||
|
||||
@Test
|
||||
void neverModifySulfurasQualityEvenISGreaterThan50() {
|
||||
Item[] items = new Item[]{new Item("Sulfuras, Hand of Ragnaros", 0, 80)};
|
||||
Item[] items = new Item[]{new Item(Constants.SULFURAS, 0, 80)};
|
||||
GildedRose.updateQuality(new GildedRose(items));
|
||||
assertEquals(80, items[0].quality);
|
||||
}
|
||||
|
||||
@Test
|
||||
void mustIncreaseBackstagePassesQualityWhenItsSellInApproaches() {
|
||||
Item[] items = new Item[]{new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 20),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 20)};
|
||||
Item[] items = new Item[]{new Item(Constants.BACKSTAGE, 15, 20),
|
||||
new Item(Constants.BACKSTAGE, 10, 20),
|
||||
new Item(Constants.BACKSTAGE, 5, 20)};
|
||||
GildedRose.updateQuality(new GildedRose(items));
|
||||
assertEquals(21, items[0].quality);
|
||||
assertEquals(22, items[1].quality);
|
||||
assertEquals(23, items[2].quality);
|
||||
}
|
||||
|
||||
@Test
|
||||
void mustDecreaseQualityTwiceAsFastIfItemIsConjured() {
|
||||
Item[] items = new Item[]{new Item(Constants.CONJURED, 0, 20)};
|
||||
GildedRose.updateQuality(new GildedRose(items));
|
||||
assertEquals(16, items[0].quality);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,7 @@ class GoldenMasterApprovalTest {
|
||||
}
|
||||
|
||||
private String[] itemTypes() {
|
||||
return new String[]{"common item", "Aged Brie", "Backstage passes to a TAFKAL80ETC concert", "Sulfuras, Hand of Ragnaros"};
|
||||
return new String[]{Constants.AGED_BRIE, Constants.BACKSTAGE, "Common item", Constants.CONJURED, Constants.SULFURAS};
|
||||
}
|
||||
|
||||
private Integer[] sellInRangeValues() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user