mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
Add support for quality updater of Conjured items
This commit is contained in:
parent
cbe262583e
commit
c4f2c72a97
@ -18,13 +18,11 @@ class GildedRose {
|
|||||||
private static class NormalItemUpdateStrategy implements UpdateQualityStrategy {
|
private static class NormalItemUpdateStrategy implements UpdateQualityStrategy {
|
||||||
@Override
|
@Override
|
||||||
public void updateQuality(Item item) {
|
public void updateQuality(Item item) {
|
||||||
if (item.quality > MIN_QUALITY) {
|
changeQuality(item, -1);
|
||||||
item.quality = item.quality - 1;
|
|
||||||
}
|
|
||||||
item.sellIn = item.sellIn - 1;
|
item.sellIn = item.sellIn - 1;
|
||||||
|
|
||||||
if (item.sellIn < 0 && item.quality > MIN_QUALITY) {
|
if (item.sellIn < 0) {
|
||||||
item.quality = item.quality - 1;
|
changeQuality(item, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,21 +30,15 @@ class GildedRose {
|
|||||||
private static class BackstagePassesUpdateStrategy implements UpdateQualityStrategy {
|
private static class BackstagePassesUpdateStrategy implements UpdateQualityStrategy {
|
||||||
@Override
|
@Override
|
||||||
public void updateQuality(Item item) {
|
public void updateQuality(Item item) {
|
||||||
if (item.quality < MAX_QUALITY) {
|
changeQuality(item, 1);
|
||||||
item.quality = item.quality + 1;
|
if (item.sellIn < 11) {
|
||||||
|
changeQuality(item, 1);
|
||||||
if (item.sellIn < 11 && item.quality < MAX_QUALITY) {
|
|
||||||
item.quality = item.quality + 1;
|
|
||||||
}
|
}
|
||||||
|
if (item.sellIn < 6) {
|
||||||
if (item.sellIn < 6 && item.quality < MAX_QUALITY) {
|
changeQuality(item, 1);
|
||||||
item.quality = item.quality + 1;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
item.sellIn = item.sellIn - 1;
|
item.sellIn = item.sellIn - 1;
|
||||||
|
if (item.sellIn < 0) {
|
||||||
if (item.sellIn < MIN_QUALITY) {
|
|
||||||
item.quality = MIN_QUALITY;
|
item.quality = MIN_QUALITY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,14 +47,12 @@ class GildedRose {
|
|||||||
private static class AgedBrieUpdateStrategy implements UpdateQualityStrategy {
|
private static class AgedBrieUpdateStrategy implements UpdateQualityStrategy {
|
||||||
@Override
|
@Override
|
||||||
public void updateQuality(Item item) {
|
public void updateQuality(Item item) {
|
||||||
if (item.quality < MAX_QUALITY) {
|
changeQuality(item, 1);
|
||||||
item.quality = item.quality + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
item.sellIn = item.sellIn - 1;
|
item.sellIn = item.sellIn - 1;
|
||||||
|
|
||||||
if (item.sellIn < MIN_QUALITY && item.quality < MAX_QUALITY) {
|
if (item.sellIn < 0) {
|
||||||
item.quality = item.quality + 1;
|
changeQuality(item, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,6 +64,22 @@ class GildedRose {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class ConjuredUpdateStrategy implements UpdateQualityStrategy {
|
||||||
|
@Override
|
||||||
|
public void updateQuality(Item item) {
|
||||||
|
changeQuality(item, -2);
|
||||||
|
item.sellIn = item.sellIn - 1;
|
||||||
|
|
||||||
|
if (item.sellIn < 0) {
|
||||||
|
changeQuality(item, -2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void changeQuality(Item item, int amount) {
|
||||||
|
item.quality = amount < 0 ? Math.max(MIN_QUALITY, item.quality + amount) : Math.min(MAX_QUALITY, item.quality + amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -87,6 +93,7 @@ class GildedRose {
|
|||||||
put("Backstage passes to a TAFKAL80ETC concert", new BackstagePassesUpdateStrategy());
|
put("Backstage passes to a TAFKAL80ETC concert", new BackstagePassesUpdateStrategy());
|
||||||
put("Aged Brie", new AgedBrieUpdateStrategy());
|
put("Aged Brie", new AgedBrieUpdateStrategy());
|
||||||
put("Sulfuras, Hand of Ragnaros", new SulfurasUpdateStrategy());
|
put("Sulfuras, Hand of Ragnaros", new SulfurasUpdateStrategy());
|
||||||
|
put("Conjured Mana Cake", new ConjuredUpdateStrategy());
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -211,11 +211,9 @@ class GildedRoseTest {
|
|||||||
|
|
||||||
// "Conjured" items degrade in Quality twice as fast as normal items
|
// "Conjured" items degrade in Quality twice as fast as normal items
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
|
||||||
// failed
|
|
||||||
public void testConjuredItemQualityDecreasesTwiceAsFast() {
|
public void testConjuredItemQualityDecreasesTwiceAsFast() {
|
||||||
app.updateQuality();
|
app.updateQuality();
|
||||||
assertEquals(1, items[8].quality, "Conjured Quality should decrease twice as fast");
|
assertEquals(4, items[8].quality, "Conjured Quality should decrease twice as fast");
|
||||||
|
|
||||||
app.updateQuality();
|
app.updateQuality();
|
||||||
assertEquals(16, items[9].quality, "Conjured Quality should decrease twice as fast");
|
assertEquals(16, items[9].quality, "Conjured Quality should decrease twice as fast");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user