mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 07:51:29 +00:00
🔨 refactor LegendaryItem validation
This commit is contained in:
parent
46a7bc437c
commit
fef68513a5
@ -12,7 +12,6 @@ public interface ItemType {
|
||||
|
||||
String QUALITY_ERROR_MESSAGE = "Quality cannot be negative! Current value: ";
|
||||
String OUT_OF_BOUND_QUALITY_MESSAGE = "Quality cannot be above 50! Current value: ";
|
||||
String NOT_LEGENDARY_ITEM_ERROR_MESSAGE = "Item is legendary, quality must be always 80! Current value: ";
|
||||
|
||||
static boolean qualityIsNegative(Item item) {
|
||||
return item.quality < 0;
|
||||
|
||||
@ -7,6 +7,7 @@ public class LegendaryItem implements ItemType {
|
||||
|
||||
public static final int LEGENDARY_ITEM_QUALITY = 80;
|
||||
public static final String LEGENDARY = "Sulfuras, Hand of Ragnaros";
|
||||
public static final String NOT_LEGENDARY_ITEM_ERROR_MESSAGE = "Item is legendary, quality must be always 80! Current value: ";
|
||||
|
||||
private final Item item;
|
||||
|
||||
@ -22,7 +23,7 @@ public class LegendaryItem implements ItemType {
|
||||
|
||||
@Override
|
||||
public void validateQuality() {
|
||||
if (isLegendaryWrongQuality(item)) {
|
||||
if (qualityIsNotLegendary(item)) {
|
||||
throw new IllegalArgumentException(NOT_LEGENDARY_ITEM_ERROR_MESSAGE + item.quality);
|
||||
}
|
||||
}
|
||||
@ -36,8 +37,8 @@ public class LegendaryItem implements ItemType {
|
||||
item.sellIn--;
|
||||
}
|
||||
|
||||
public static boolean isLegendaryWrongQuality(Item item) {
|
||||
return item.name.equals(LEGENDARY) && item.quality != LEGENDARY_ITEM_QUALITY;
|
||||
public static boolean qualityIsNotLegendary(Item item) {
|
||||
return item.quality != LEGENDARY_ITEM_QUALITY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static com.gildedrose.helper.TestHelper.testItem;
|
||||
import static com.gildedrose.item_helpers.ItemType.NOT_LEGENDARY_ITEM_ERROR_MESSAGE;
|
||||
import static com.gildedrose.items.LegendaryItem.NOT_LEGENDARY_ITEM_ERROR_MESSAGE;
|
||||
import static com.gildedrose.items.LegendaryItem.LEGENDARY;
|
||||
import static com.gildedrose.items.LegendaryItem.LEGENDARY_ITEM_QUALITY;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user