mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-14 22:21:20 +00:00
adds Conjured item
This commit is contained in:
parent
e6f4256062
commit
ad087914bc
BIN
Java/src/main/java/com/gildedrose/item/.DS_Store
vendored
Normal file
BIN
Java/src/main/java/com/gildedrose/item/.DS_Store
vendored
Normal file
Binary file not shown.
20
Java/src/main/java/com/gildedrose/item/ConjuredItem.java
Normal file
20
Java/src/main/java/com/gildedrose/item/ConjuredItem.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.gildedrose.item;
|
||||
|
||||
public class ConjuredItem implements CustomisedItem {
|
||||
|
||||
private final Item item;
|
||||
|
||||
public ConjuredItem(Item item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public void updateState() {
|
||||
item.sellIn -= 1;
|
||||
if (item.sellIn > 0) {
|
||||
item.quality -= 2;
|
||||
} else {
|
||||
item.quality -= 4;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -5,6 +5,7 @@ public class CustomisedItemFactory {
|
||||
public final static String SULFURAS = "Sulfuras, Hand of Ragnaros";
|
||||
public final static String BRIE = "Aged Brie";
|
||||
public final static String BACKSTAGE_PASSES_ITEM = "Backstage passes to a TAFKAL80ETC concert";
|
||||
public final static String CONJURED_ITEM = "Conjured";
|
||||
|
||||
public CustomisedItem customiseItem(Item item) {
|
||||
if (item.name.equals(SULFURAS)) {
|
||||
@ -13,6 +14,8 @@ public class CustomisedItemFactory {
|
||||
return new AgedBrie(item);
|
||||
} else if (item.name.equals(BACKSTAGE_PASSES_ITEM)) {
|
||||
return new BackstagePassesItem(item);
|
||||
} else if (item.name.equals(CONJURED_ITEM)) {
|
||||
return new ConjuredItem(item);
|
||||
} else {
|
||||
return new StandardItem(item);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.gildedrose;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import com.gildedrose.item.CustomisedItem;
|
||||
import com.gildedrose.item.Item;
|
||||
import com.gildedrose.item.CustomisedItemFactory;
|
||||
import org.junit.Test;
|
||||
@ -44,6 +45,15 @@ public class GildedRoseTest {
|
||||
assertEquals(-1, itemSellByDayNumber(app));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conjuredItemDecreasesSellByDayNumberEachTime() {
|
||||
GildedRose app = newGildedRose(CustomisedItemFactory.CONJURED_ITEM, 0, 0);
|
||||
|
||||
app.updateQuality();
|
||||
|
||||
assertEquals(-1, itemSellByDayNumber(app));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void brieIncreasesInQualityEachTime() {
|
||||
GildedRose app = newGildedRose(CustomisedItemFactory.BRIE, 1, 1);
|
||||
@ -152,6 +162,33 @@ public class GildedRoseTest {
|
||||
assertEquals(1, itemSellByDayNumber(app));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conjuredItemDecreasesQualityByTwoIfSellByDayIsAboveZero() {
|
||||
GildedRose app = newGildedRose(CustomisedItemFactory.CONJURED_ITEM, 2, 5);
|
||||
|
||||
app.updateQuality();
|
||||
|
||||
assertEquals(3, itemQualityValue(app));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conjuredItemDecreasesQualityByFourOnceSellByDayIsZeroOrLess() {
|
||||
GildedRose app = newGildedRose(CustomisedItemFactory.CONJURED_ITEM,0, 5);
|
||||
|
||||
app.updateQuality();
|
||||
|
||||
assertEquals(1, itemQualityValue(app));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conjuredItemCannotHaveQualityBelowZero() {
|
||||
GildedRose app = newGildedRose(CustomisedItemFactory.CONJURED_ITEM, 0, 0);
|
||||
|
||||
app.updateQuality();
|
||||
|
||||
assertEquals(0, itemQualityValue(app));
|
||||
}
|
||||
|
||||
private GildedRose newGildedRose(String itemName, int itemSellIn, int itemQuality) {
|
||||
Item[] items = new Item[] { new Item(itemName, itemSellIn, itemQuality)};
|
||||
return new GildedRose(items);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user