mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Code Refactoring :Separated quality check based on item type to improve readability
This commit is contained in:
parent
816efb008e
commit
e5625734e5
@ -13,7 +13,7 @@ class GildedRose {
|
|||||||
&& !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
&& !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||||
if (item.quality > 0) {
|
if (item.quality > 0) {
|
||||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||||
item.quality = item.quality - 1;
|
updateQualityForNormalItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -21,13 +21,7 @@ class GildedRose {
|
|||||||
item.quality = item.quality + 1;
|
item.quality = item.quality + 1;
|
||||||
|
|
||||||
if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||||
if (item.sellIn < 11) {
|
updateQualityForBackstagePasses(item);
|
||||||
addQualityWhenWithInLimit(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.sellIn < 6) {
|
|
||||||
addQualityWhenWithInLimit(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,6 +34,20 @@ class GildedRose {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateQualityForBackstagePasses(Item item) {
|
||||||
|
if (item.sellIn < 11) {
|
||||||
|
addQualityWhenWithInLimit(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.sellIn < 6) {
|
||||||
|
addQualityWhenWithInLimit(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateQualityForNormalItem(Item item) {
|
||||||
|
item.quality--;
|
||||||
|
}
|
||||||
|
|
||||||
private void addQualityWhenWithInLimit(Item item) {
|
private void addQualityWhenWithInLimit(Item item) {
|
||||||
if (item.quality < 50) {
|
if (item.quality < 50) {
|
||||||
item.quality = item.quality + 1;
|
item.quality = item.quality + 1;
|
||||||
|
|||||||
@ -41,7 +41,11 @@ class GildedRoseTest {
|
|||||||
Arguments.of(new Item[] { new Item("Backstage passes to a TAFKAL80ETC concert", 12, 10) }, 11),
|
Arguments.of(new Item[] { new Item("Backstage passes to a TAFKAL80ETC concert", 12, 10) }, 11),
|
||||||
Arguments.of(new Item[] { new Item("Backstage passes to a TAFKAL80ETC concert", 12, 50) }, 50),
|
Arguments.of(new Item[] { new Item("Backstage passes to a TAFKAL80ETC concert", 12, 50) }, 50),
|
||||||
|
|
||||||
Arguments.of(new Item[] { new Item("Backstage passes to a TAFKAL80ETC concert", -1, 10) }, 0)
|
Arguments.of(new Item[] { new Item("Backstage passes to a TAFKAL80ETC concert", -1, 10) }, 0),
|
||||||
|
|
||||||
|
Arguments.of(new Item[] { new Item("Coffee Day", 1, 1) }, 0),
|
||||||
|
Arguments.of(new Item[] { new Item("Coffee Day", -1, 1) }, 0),
|
||||||
|
Arguments.of(new Item[] { new Item("Coffee Day", -1, 2) }, 0)
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user