🔨 refactor LegendaryItem validation

This commit is contained in:
Velizar Todorov 2021-11-30 19:12:11 +01:00
parent 46a7bc437c
commit fef68513a5
3 changed files with 5 additions and 5 deletions

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;